백지부터 시작하는 이세계 코딩 생활

Deep Link for Unity ( Setting Up ) 본문

백지부터 시작하는 이세계 유니티 생활 since 2020

Deep Link for Unity ( Setting Up )

조아덕 2021. 2. 22. 17:34

Unity 제공 소스파일 : github.com/Unity-Technologies/NotchSafeAreaSample

docs.unity3d.com/2020.1/Documentation/Manual/enabling-deep-linking.html

 

Unity - Manual: Enabling deep linking

Using Unity as a Library in other applications Enabling deep linking Deep links are links that point directly to content within your application. Unity uses the Application.absoluteURL property and Application.deepLinkActivated event to support deep links

docs.unity3d.com

단일링크를 위한 기본 코드 셋업 : Android

public class ProcessDeepLinkMngr : MonoBehaviour
{
	public static ProcessDeepLinkMngr Instance { get; private set; }
	public string deeplinkURL;
	private void Awake()
	{
    	if (Instance == null)
    	{
        	Instance = this;             	
        	Application.deepLinkActivated += onDeepLinkActivated;
        	if (!String.IsNullOrEmpty(Application.absoluteURL))
        	{
            	// Cold start and Application.absoluteURL not null so process Deep Link.
                onDeepLinkActivated(Application.absoluteURL);
        	}
        	// Initialize DeepLink Manager global variable.
        	else deeplinkURL = "[none]";
        	DontDestroyOnLoad(gameObject);
    	}
    	else
    	{
        	Destroy(gameObject);
    	}
	}
 
	private void onDeepLinkActivated(string url)
	{
    	// Update DeepLink Manager global variable, so URL can be accessed from anywhere.
    	deeplinkURL = url;
    	
// Decode the URL to determine action. 
// In this example, the app expects a link formatted like this:
// unitydl://mylink?scene1 
    	string sceneName = url.Split("?"[0])[1];
    	bool validScene;
    	switch (sceneName)
    	{
        	case "scene1":
            	validScene = true;
            	break;
        	case "scene2":
            	validScene = true;
            	break;
        	default:
            	validScene = false;
            	break;
    	}
    	if (validScene) SceneManager.LoadScene(sceneName);
	}
}

 

테스트 : 

xml 파일과 HTML 파일을 만들어 간단하게 테스트 할 수 있음.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
  <application>
    <activity android:name="com.unity3d.player.UnityPlayerActivity" android:theme="@style/UnityThemeSelector" >
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
      <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="unitydl" android:host="mylink" />
      </intent-filter>
    </activity>
  </application>
</manifest>
<html>
<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
</head>
<body >
<h1>My Deep Link Test page</h1>
<h2 >
<a href="unitydl://mylink">Launch</a>
</h2>
<h2 >
<a href="unitydl://mylink?parameter">Launch with Parameter</a>
</h2>

</body>
</html>

 

 

cf.

Application.absoluteURL

public static string absoluteURL;

Description

  • 문서의 URL, 안드로이드경우 Intent Filter 를 통해, IOS경우 Scheme or Universal Link 를 통해 사용할 수 있음.

The URL of the document. For WebGL, this a web URL. For Android, iOS, or Universal Windows Platform (UWP) this is a deep link URL. (Read Only)

WebGL: The URL of the document as shown in a browser's address bar.

Android: If the application has been launched or activated using an Intent Filter, a deep link (App Link) URL.

iOS: If the application has been launched or activated using a URL Scheme or a Universal Link, a deep link (Universal Link) URL.

UWP: If the application has been launched or activated using a custom URI scheme, a deep link URL.

Note: If the deep link is activated while the application is running Application.deepLinkActivated delegate is called.

 

 

Application.deepLinkActivated

value The deep link URL that activated the application.

Description :

  • 딥링크 URL 이 활성화 되었을 때 호출됨.

This event is raised when an application running on Android, iOS, or the Universal Windows Platform (UWP) is activated using a deep link URL.

Note: When this delegate is called Application.absoluteURL property is also updated.


 

단일링크를 위한 기본 코드 셋업 : IOS

딥링크 사용예제 : IOS

kumgo1d.tistory.com/20

 

[Unity] launch a unity app from url scheme or deep link in ios(스키마를 이용하여 웹에서 유니티 앱 열기(SSO))

안녕하세요 골드입니다. 오늘은 스키마라는 것을 이용하여 외부에서 우리가 만든 앱에 접근하는 방법에 대해서 글을 쓰겠습니다. 1. 스키마에 대한 간단 설명 여기 웹브라우저가 있습니다. 저는

kumgo1d.tistory.com

 

 


Ref.

1 blogs.unity3d.com/kr/2020/07/16/add-deep-links-to-your-unity-mobile-apps-for-better-user-experience/

 

Add deep links to your Unity mobile apps for better user experienceUnity 製モバイルアプリにディープリンクを追

Adding deep links within your Unity project is a simple way to drive users directly to specific content in a mobile app – no navigation required. That content becomes easily shareable and more interactive, bringing new users, guiding existing users to ne

blogs.unity3d.com

2 charlie0301.blogspot.com/2014/03/android-unity_7.html

 

Android 상에서의 Unity 개발을 위한 필요 사항(plugin 개발 방법, debugging) 링크 정리

Android 타겟으로 Unity 개발을 위한 개발 방법 링크를 정리함. - Android plugin for Unity - Rest API using in C# script - tutorial links [Plugin for Android]...

charlie0301.blogspot.com

Unity 공식 문서에서는 Android plugin에서 사용 가능한 두가지 방법을 설명하고 있음.

1. Using Java Plugins
 > Script상에서 JNI interface를 사용하여 java code를 직접 호출하여 사용 하는 방법

using UnityEngine; 
public class NewBehaviourScript : MonoBehaviour { 

 void Start () { 
  AndroidJNIHelper.debug = true; 
  using (AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) { 
   jc.CallStatic("UnitySendMessage", "Main Camera", "JavaMessage", "whoowhoo"); 
  } 
 } 

 void JavaMessage(string message) { 
  Debug.Log("message from java: " + message); 
 }
} 

 

2. Extending the UnityPlayerActivity Java Code
 > UnityPlayerActivity를 상속 받아 Activity 코드에서 Android 관련 처리를 할 수 있도록 하는 방법

public class OverrideExample extends UnityPlayerActivity {

  protected void onCreate(Bundle savedInstanceState) {

    // call UnityPlayerActivity.onCreate()
    super.onCreate(savedInstanceState);

    // print debug message to logcat
    Log.d("OverrideActivity", "onCreate called!");
  }

  public void onBackPressed()
  {
    // instead of calling UnityPlayerActivity.onBackPressed() we just ignore the back button event
    // super.onBackPressed();
  }
} 

 

 

 

 

'백지부터 시작하는 이세계 유니티 생활 since 2020' 카테고리의 다른 글

Deep Link for XCode (IOS)  (0) 2021.02.22
Deep Link 처리 순서  (0) 2021.02.22
DOTween  (0) 2021.02.17
변수 형변환  (0) 2021.02.10
Resources  (0) 2021.02.10
Comments