Skip to content

Instantly share code, notes, and snippets.

@corycorvus
Created December 18, 2019 21:08
Show Gist options
  • Save corycorvus/71fb38df9707f4b2753d816880a4bdcc to your computer and use it in GitHub Desktop.
Save corycorvus/71fb38df9707f4b2753d816880a4bdcc to your computer and use it in GitHub Desktop.
using UnityEngine;
using Viveport;
public class QuitGoHome
{
const int SUCCESS = 0;
private static bool isSubscriber = false;
static void Quit()
{
Debug.Log("Quitting");
if(isSubscriber)
Deeplink.GoToStore(DeeplinkGoToStoreCallback);
}
[RuntimeInitializeOnLoadMethod]
static void RunOnStart()
{
Application.quitting += Quit;
Subscription.IsReady(IsReadyHandler); // check for viveport init and isready
}
private static void DeeplinkGoToStoreCallback(int code, string message)
{
if (code == SUCCESS)
{
Debug.Log("[VIVEPORT][DEEPLINK][GOTOSTORE] Go to store success.");
}
else
{
Debug.Log(string.Format("[VIVEPORT][DEEPLINK][GOTOSTORE] Code: {0}, Message: {1}", code, message));
}
}
private static void IsReadyHandler(int nResult, string message)
{
if (nResult == 0)
{
Viveport.Core.Logger.Log("Subscription is ready");
CheckSubscriber(); // check if user is subscriber
}
else
{
Viveport.Core.Logger.Log("Subscription IsReadyHandler error: " + nResult + " Message : " + message);
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// !!!IMPORTANT!!! Please wait for the IsReadyHandler before calling the GetUserStatus function ///
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
// check if user is infinity member
private static void CheckSubscriber()
{
var userStatus = Subscription.GetUserStatus();
if (userStatus.Type != SubscriptionStatus.TransactionType.Unknown)
isSubscriber = true;
if (isSubscriber)
Debug.Log("Viveport Infinity Member");
else
Debug.Log("Not Viveport Infinity Member");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment