Version: 2020.3
다른 애플리케이션에서 Unity as a Library 사용
스탠드얼론

딥 링크 활성화

딥 링크는 애플리케이션 내에서 콘텐츠에 직접 연결되는 링크입니다. Unity는 Application.absoluteURL 프로퍼티와 Application.deepLinkActivated 이벤트를 사용하여 다음 플랫폼에서 딥 링크를 지원합니다.

  • Android
  • iOS
  • 유니버설 Windows 플랫폼(UWP)

애플리케이션이 딥 링크 URL에서 활성화되면 Unity는 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에 반응하도록 설정하는 프로세스는 플랫폼마다 다릅니다.

iOS

앱이 딥 링크에 반응하도록 만드는 방법에는 두 가지, 즉 URL 체계와 유니버설 링크가 있습니다.

URL 체계

URL 체계를 추가하려면 다음 단계를 따르십시오.

  1. iOS 플레이어 설정 창(메뉴: Edit > Project Settings > Player Settings에서 iOS 선택)을 엽니다.
  2. Other를 선택한 후 Configuration으로 스크롤을 내립니다.
  3. Supported URL schemes 섹션을 확장하고 Element 0 필드에 앱과 관련된 URL 체계를 입력합니다(예: unitydl).

이렇게 하면 앱이 unitydl://로 시작하는 링크를 열고, Application.deepLinkActivated 이벤트에서 URL을 처리할 수 있습니다.

유니버설 링크

앱이 Unity 에디터의 유니버설 링크를 사용하도록 설정할 수 없는데, 이는 외부 웹사이트가 필요하기 때문입니다. 자세한 내용은 유니버설 링크 활성화에 대한 Apple 문서를 참조하십시오.

Android

딥 링크를 활성화하려면 표준 앱 매니페스트를 오버라이드하는 목적 필터를 설정하여 활동에 대한 특정 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을 처리할 수 있습니다.

유니버설 Windows 플랫폼(UWP)

앱에 커스텀 URI 체계를 추가하려면 다음 단계를 따르십시오.

  1. UWP 플레이어 설정 창(메뉴: Edit > Project Settings > Player Settings에서 UWP 선택)을 엽니다.
  2. Publishing Settings를 선택한 후 Protocol로 스크롤을 내립니다.
  3. Name 필드에 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>
다른 애플리케이션에서 Unity as a Library 사용
스탠드얼론
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961