Created
August 17, 2020 11:21
-
-
Save DVDPT/7fecac297e05233c4c7eaa8bf50e9bb9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
// | |
// Made by furic | |
// https://github.com/furic | |
// | |
// A deep linking controller to be used with the Unity plugin Universal Deep Linking (https://assetstore.unity.com/packages/slug/125172?aid=1100l8RBa) | |
// It uses a share file to pass information when the standalone app is already launched, for more details check the plugin documentation: | |
// Documentation on integration with a launcher application: https://universaldeeplinking.imaginationoverflow.com/docs/Internals/#standalone-activation-after-launch | |
// | |
// You can find the launcher code in github: https://gist.github.com/DVDPT/3f81d9216f0cbfab3b4746fb5d529467 | |
// | |
// Replace 'Block42' with your executable name | |
// Replace 'ShareLink' with your shared file name | |
// | |
/// <summary> | |
/// A controller to create and receive the share link | |
/// </summary> | |
public class ShareLinkController : MonoBehaviour | |
{ | |
#region Deep link receiver | |
private void Start() | |
{ | |
#if UNITY_STANDALONE_LINUX || UNITY_STANDALONE_WIN | |
string launcherPath = System.IO.Path.Combine(Application.dataPath , "..", "Block42.exe"); | |
launcherPath = new System.IO.FileInfo(launcherPath).FullName; | |
Debug.Log("Registering link launcher - " + launcherPath); | |
ImaginationOverflow.UniversalDeepLinking.LinkProviderFactory.DeferredExePath = launcherPath; | |
InvokeRepeating("CheckShareLinkFile", 10, 1); | |
#endif | |
ImaginationOverflow.UniversalDeepLinking.DeepLinkManager.Instance.LinkActivated += OnLinkActivated; | |
} | |
private void CheckShareLinkFile() | |
{ | |
string linkFilePath = System.IO.Path.Combine(Application.dataPath, "..", "ShareLink.txt"); | |
linkFilePath = new System.IO.FileInfo(linkFilePath).FullName; | |
Debug.Log("Checking link file - " + linkFilePath); | |
if (System.IO.File.Exists(linkFilePath)) { | |
string fileContent = System.IO.File.ReadAllText(linkFilePath); | |
if (!string.IsNullOrEmpty(fileContent)) { | |
ImaginationOverflow.UniversalDeepLinking.DeepLinkManager.Instance.ManuallyTriggerDeepLink(fileContent); | |
System.IO.File.WriteAllText(linkFilePath, string.Empty); | |
} | |
} | |
} | |
private void OnLinkActivated(ImaginationOverflow.UniversalDeepLinking.LinkActivation linkActivation) | |
{ | |
var url = linkActivation.Uri; | |
var id = linkActivation.QueryString["id"]; | |
// Do whatever you want | |
} | |
#endregion | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment