딥 링크는 애플리케이션 내에서 콘텐츠에 직접 연결되는 링크입니다. Unity는 Application.absoluteURL
프로퍼티와 Application.deepLinkActivated
이벤트를 사용하여 다음 플랫폼에서 딥 링크를 지원합니다.
애플리케이션이 딥 링크 URL에서 활성화되면 Unity는 Application.deepLinkActivated
이벤트를 호출합니다. 이 시나리오에서 딥 링크를 처리하기 위해 다음을 수행할 수 있습니다.
Application.absoluteURL
을 확인합니다.Application.deepLinkActivated
이벤트를 구독합니다.예를 들어 아래의 코드를 시작 씬의 게임 오브젝트에 연결할 수 있습니다.
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);
}
}
애플리케이션이 특정 URL에 반응하도록 설정하는 프로세스는 플랫폼마다 다릅니다.
앱이 딥 링크에 반응하도록 만드는 방법에는 두 가지, 즉 URL 체계와 유니버설 링크가 있습니다.
URL 체계를 추가하려면 다음 단계를 따르십시오.
unitydl
).이렇게 하면 앱이 unitydl://
로 시작하는 링크를 열고, Application.deepLinkActivated
이벤트에서 URL을 처리할 수 있습니다.
앱이 Unity 에디터의 유니버설 링크를 사용하도록 설정할 수 없는데, 이는 외부 웹사이트가 필요하기 때문입니다. 자세한 내용은 유니버설 링크 활성화에 대한 Apple 문서를 참조하십시오.
딥 링크를 활성화하려면 표준 앱 매니페스트를 오버라이드하는 목적 필터를 설정하여 활동에 대한 특정 intent-filter
섹션을 포함하도록 만들어야 합니다. 이를 위한 가장 간단한 방법은 다음의 AndroidManifest.xml
파일을 프로젝트의 Assets/Plugins/Android
폴더에 넣는 것입니다. 앱을 빌드할 때 Unity는 이 파일을 자동으로 처리합니다.
<?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>
이렇게 하면 앱이 unitydl://
로 시작하는 링크를 열고, Application.deepLinkActivated
이벤트에서 URL을 처리할 수 있습니다.
앱에 커스텀 URI 체계를 추가하려면 다음 단계를 따르십시오.
unitydl
을 입력합니다.이렇게 하면 앱이 unitydl://
로 시작하는 모든 링크를 엽니다.
딥 링크를 테스트하기 위해 HTML 파일을 생성하여, 로컬 웹 서버에서 호스팅하고, 사용 중인 기기의 웹 브라우저에서 해당 파일에 액세스할 수 있습니다.
<html>
<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
</head>
<body >
<h1>My Deep Link Test page</h1>
<p><a href="unitydl://mylink">Launch</a></p>
<p><a href="unitydl://mylink?parameter">Launch with Parameter</a></p>
</body>
</html>
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.