163 lines
3.8 KiB
C#
163 lines
3.8 KiB
C#
using UnityEngine;
|
|
using Viveport;
|
|
using Viveport.Core;
|
|
|
|
public class ViveportDemo_Deeplink : MonoBehaviour
|
|
{
|
|
private static string VIVEPORT_ID = "VIVEPORT ID of the content";
|
|
|
|
private static string VIVEPORT_KEY = "VIVEPORT Key of the content";
|
|
|
|
private string GoToApp_Viveport_ID = "VIVEPORT ID of target APP";
|
|
|
|
private string GoToStore_Viveport_ID = "VIVEPORT ID of target APP";
|
|
|
|
private string LaunchData = "Start_Content";
|
|
|
|
private string LaunchBranchName = "PROD";
|
|
|
|
private const int SUCCESS = 0;
|
|
|
|
private static bool bInitComplete;
|
|
|
|
private void Awake()
|
|
{
|
|
MainThreadDispatcher mainThreadDispatcher = Object.FindObjectOfType<MainThreadDispatcher>();
|
|
if (!mainThreadDispatcher)
|
|
{
|
|
GameObject gameObject = new GameObject();
|
|
gameObject.AddComponent<MainThreadDispatcher>();
|
|
gameObject.name = "MainThreadDispatcher";
|
|
}
|
|
}
|
|
|
|
private void OnGUI()
|
|
{
|
|
GUI.Label(new Rect(100f, 20f, 600f, 600f), " Show Message in Console log \n KeyDown \" Q \" Use GoToApp \n KeyDown \" W \" Use GoToApp with BranchName \n KeyDown \" E \" Use GoToStore \n KeyDown \" R \" Use GoToAppOrGoToStore \n KeyDown \" A \" Use GetAppLaunchData \n");
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
Api.Init(InitStatusHandler, VIVEPORT_ID);
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
Api.Shutdown(ShutdownHandler);
|
|
}
|
|
|
|
private static void InitStatusHandler(int nResult)
|
|
{
|
|
if (nResult == 0)
|
|
{
|
|
Debug.Log("VIVEPORT init pass");
|
|
Deeplink.IsReady(IsReadyHandler);
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("VIVEPORT init fail");
|
|
Application.Quit();
|
|
}
|
|
}
|
|
|
|
private static void IsReadyHandler(int nResult)
|
|
{
|
|
if (nResult == 0)
|
|
{
|
|
Debug.Log("VIVEPORT Deeplink.IsReady pass");
|
|
bInitComplete = true;
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("VIVEPORT Deeplink.IsReady fail");
|
|
Application.Quit();
|
|
}
|
|
}
|
|
|
|
private static void ShutdownHandler(int nResult)
|
|
{
|
|
if (nResult == 0)
|
|
{
|
|
bInitComplete = false;
|
|
Viveport.Core.Logger.Log("ShutdownHandler is successful");
|
|
}
|
|
else
|
|
{
|
|
Viveport.Core.Logger.Log("ShutdownHandler error: " + nResult);
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.Q) && bInitComplete)
|
|
{
|
|
Deeplink.GoToApp(GoToAppHandler, GoToApp_Viveport_ID, LaunchData);
|
|
}
|
|
if (Input.GetKeyDown(KeyCode.W) && bInitComplete)
|
|
{
|
|
Deeplink.GoToApp(GoToAppHandler, GoToApp_Viveport_ID, LaunchData, LaunchBranchName);
|
|
}
|
|
if (Input.GetKeyDown(KeyCode.E) && bInitComplete)
|
|
{
|
|
Deeplink.GoToStore(GoToStoreHandler, GoToStore_Viveport_ID);
|
|
}
|
|
if (Input.GetKeyDown(KeyCode.R) && bInitComplete)
|
|
{
|
|
Deeplink.GoToAppOrGoToStore(GoToAppOrGoToStoreHandler, GoToStore_Viveport_ID, LaunchData);
|
|
}
|
|
if (Input.GetKeyDown(KeyCode.A) && bInitComplete)
|
|
{
|
|
string appLaunchData = Deeplink.GetAppLaunchData();
|
|
Debug.Log(appLaunchData);
|
|
}
|
|
}
|
|
|
|
private static void GoToAppHandler(int errorCode, string message)
|
|
{
|
|
if (errorCode == 0)
|
|
{
|
|
MainThreadDispatcher.Instance().Enqueue(delegate
|
|
{
|
|
Debug.Log("GoToApp is successful");
|
|
});
|
|
return;
|
|
}
|
|
MainThreadDispatcher.Instance().Enqueue(delegate
|
|
{
|
|
Debug.Log("GoToApp errorCode : " + errorCode + " ErrorMessage : " + message);
|
|
});
|
|
}
|
|
|
|
private static void GoToStoreHandler(int errorCode, string message)
|
|
{
|
|
if (errorCode == 0)
|
|
{
|
|
MainThreadDispatcher.Instance().Enqueue(delegate
|
|
{
|
|
Debug.Log("GoToStore is successful");
|
|
});
|
|
return;
|
|
}
|
|
MainThreadDispatcher.Instance().Enqueue(delegate
|
|
{
|
|
Debug.Log("GoToStore errorCode : " + errorCode + " ErrorMessage : " + message);
|
|
});
|
|
}
|
|
|
|
private static void GoToAppOrGoToStoreHandler(int errorCode, string message)
|
|
{
|
|
if (errorCode == 0)
|
|
{
|
|
MainThreadDispatcher.Instance().Enqueue(delegate
|
|
{
|
|
Debug.Log("GoToAppOrGoToStore is successful");
|
|
});
|
|
return;
|
|
}
|
|
MainThreadDispatcher.Instance().Enqueue(delegate
|
|
{
|
|
Debug.Log("GoToAppOrGoToStore errorCode : " + errorCode + " ErrorMessage : " + message);
|
|
});
|
|
}
|
|
}
|