# 教材 平台 軟體跳轉相關 無論是平台或教材,跳轉都是開啟事先設定好的 `URI 連結` ,只要開啟軟體的 `URI 連結` 即可跳轉。 只要將 `URI 連結` 視為一般網址使用即可,在網頁瀏覽器直接輸入 `URI 連結` 也可測試開啟。 # A. 如何跳轉 DeepLink 到目標軟體 ➡️ 以下範例皆已開啟 EWova 為範例 自定義跳轉連結為 `ewova://` ## A1. Windows PC :::warning ⚠️ EWova 必須打開執行過一次才能跳轉 ( 軟體需要執行過一次才能正確套用跳轉到 Windows註冊表,關於這點還在想辦法處理... 未來可能會透過 Installer 安裝軟體時就預先登記註冊表 ) ::: - Unity 環境下 ```csharp Application.OpenURL("ewova://"); ``` - 瀏覽器 環境下 以 `EWova` 為例 ![image](https://hackmd.io/_uploads/HyKml3-bxe.png) ## A2. Android and 一體機 :::warning ⚠️ 目標軟體必須事先安裝到裝置內 ( 安裝即可 無需事先啟動 ) ::: - Unity 環境下 ```csharp Application.OpenURL("ewova://"); ``` - VR 瀏覽器 環境下 ( 有較嚴格的大小寫問題 ) ![image](https://hackmd.io/_uploads/r1RuenWZel.png) # B. 設定你的專屬連結 DeepLink 讓別人跳轉 ⬅️ ## B1. Windows PC :::danger ⛔ 目前無法直接透過簡單的方法設定 我是購買以下 [Deep linking for Windows (Standalone/EXE)](https://assetstore.unity.com/packages/tools/integration/deep-linking-for-windows-standalone-exe-264033) 來額外做處理的 ::: ## B2. Android and 一體機 :::warning ⚠️ Scheme 請盡量全小寫 Android 環境有滿嚴格的大小寫問題,全小寫為避免不可控因素 若有 `uses-permission` 需求請自行擴增 ::: 1. 創建 `Editor 資料夾` 在任一位置,並建立一個空 `Script` 可直接參照下圖 ![image](https://hackmd.io/_uploads/HydZV9vblg.png) 1. 打開你的 script 後,修改 `MY_DEEPLINK_SCHEME` 常數到你的 Scheme ```csharp using System.IO; using System.Xml; using UnityEditor.Android; using UnityEngine; public class MyDeepLinkPostProcessor : IPostGenerateGradleAndroidProject { // 請修改為你的 Scheme              ↓ private const string MY_DEEPLINK_SCHEME = "ewova"; // 確保 '插入 deeplink' 的邏輯 是最後執行 public int callbackOrder => 10000; public void OnPostGenerateGradleAndroidProject(string path) { string manifestPath = Path.Combine(path, "src", "main", "AndroidManifest.xml"); if (!File.Exists(manifestPath)) { Debug.LogError("AndroidManifest.xml not found: " + manifestPath); return; } var doc = new XmlDocument(); doc.Load(manifestPath); XmlNamespaceManager nsManager = new XmlNamespaceManager(doc.NameTable); nsManager.AddNamespace("android", "http://schemas.android.com/apk/res/android"); XmlNode manifestNode = doc.SelectSingleNode("/manifest"); XmlNode applicationNode = manifestNode.SelectSingleNode("application"); XmlNode activityNode = applicationNode.SelectSingleNode("activity"); XmlElement intentFilter = doc.CreateElement("intent-filter"); XmlElement action = doc.CreateElement("action"); action.SetAttribute("name", "http://schemas.android.com/apk/res/android", "android.intent.action.VIEW"); intentFilter.AppendChild(action); XmlElement categoryDefault = doc.CreateElement("category"); categoryDefault.SetAttribute("name", "http://schemas.android.com/apk/res/android", "android.intent.category.DEFAULT"); intentFilter.AppendChild(categoryDefault); XmlElement categoryBrowsable = doc.CreateElement("category"); categoryBrowsable.SetAttribute("name", "http://schemas.android.com/apk/res/android", "android.intent.category.BROWSABLE"); intentFilter.AppendChild(categoryBrowsable); XmlElement data = doc.CreateElement("data"); data.SetAttribute("scheme", "http://schemas.android.com/apk/res/android", MY_DEEPLINK_SCHEME); intentFilter.AppendChild(data); activityNode.AppendChild(intentFilter); doc.Save(manifestPath); Debug.Log($"已完成將你的 DeepLink {MY_DEEPLINK_SCHEME}:// 加入到 AndroidManifest.xml"); } } ``` 3. 現在你可以透過你專屬的 `URI 連結` 來開啟你的軟體了! ```csharp Application.OpenURL("ewova://"); ```