deeplink redirect GPT
Redirect¶
The redirect script transforms the custom unityasset:// URI into a standard http://localhost:5000/ URL, so it can be handled by the local server inside Unity.
How the Redirect Works¶
When an external app (e.g., a web browser, another program, or even a script) tries to open a unityasset:// link, Windows/macOS doesn’t know how to handle it by default. The script converts the unityasset:// URI into an HTTP request and sends it to Unity’s local server.
-
User clicks a link
- Example:unityasset://Assets/MyFolder/MyPrefab.prefab -
OS invokes the redirect script
- On Windows, the.batscript runs
- On macOS, the.shscript runs -
Script modifies the URI
- It replacesunityasset://withhttp://localhost:5000/
- Becomes:http://localhost:5000/Assets/MyFolder/MyPrefab.prefab -
Script opens the modified URL
- The script launches the modified URL usingstart(Windows) oropen(macOS), sending the request to Unity’s deep link server. -
Unity receives the request
- The local HTTP server in Unity processes the request and opens the asset.
Windows Redirect Script (redirect.bat)¶
Explanation:¶
%1is the first argument (the full URI passed to the script).set URL=%URL:unityasset://=http://localhost:5000/%replacesunityasset://withhttp://localhost:5000/.start "" "%URL%"opens the modified URL in the browser, sending the request to Unity.
How to Register the Protocol in Windows¶
- Open Registry Editor (
regedit). - Navigate to
HKEY_CLASSES_ROOT. - Create a new key called
unityasset. - Inside
unityasset, create ashell\open\commandsubkey. - Set the default value of
commandto:
Mac Redirect Script (redirect.sh)¶
Explanation:¶
${1}is the first argument (the full URI).${1//unityasset:\/\//http://localhost:5000/}replacesunityasset://withhttp://localhost:5000/.open "$url"sends the request to Unity via a browser.
How to Register the Protocol on macOS¶
- Add the following to your app’s
Info.plist:
- Associate
unityasset://links withredirect.shusingopencommand.