백지부터 시작하는 이세계 코딩 생활
Deep Link for Unity ( Setting Up ) 본문
Unity 제공 소스파일 : github.com/Unity-Technologies/NotchSafeAreaSample
docs.unity3d.com/2020.1/Documentation/Manual/enabling-deep-linking.html
단일링크를 위한 기본 코드 셋업 : 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
Ref.
1 blogs.unity3d.com/kr/2020/07/16/add-deep-links-to-your-unity-mobile-apps-for-better-user-experience/
2 charlie0301.blogspot.com/2014/03/android-unity_7.html
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 |