ディープリンクとは、アプリケーションの外にあって、ユーザーをアプリケーション内の特定の場所に遷移させる URL リンクです。ユーザーがアプリケーションのディープリンクをクリックすると、オペレーティングシステムが、指定された場所 (例えば、特定のシーン) で Unity アプリケーションを開きます。Unity は、Application.absoluteURL プロパティと Application.deepLinkActivated イベントを使用して、以下のプラットフォームでディープリンクをサポートしています。
ディープリンクを処理する前に、アプリケーションを、ディープリンクに反応するように設定する必要があります。特定の URL に反応するようにアプリケーションを設定するプロセスは、プラットフォームごとに異なります。Unity は、以下のプラットフォームでディープリンクをサポートしています。
ディープリンクを処理するには、以下のいずれかを行います。
Application.absoluteURL
をチェックします。以下のコードサンプルは、ディープリンク URLを処理して URL に応じてシーンをロードする方法を示しています。
using UnityEngine;
using UnityEngine.SceneManagement;
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);
}
}
ディープリンクのテストは、以下の手順で行えます。
これは、ディープリンクをテストするために使用できる HTML ファイルの例です。リンクをリダイレクトするには、いずれか 1 つの <a>
要素内の、href
属性を変更してください。
<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.