using UnityEngine; using Viveport; using Viveport.Core; public class ViveportDemo_Subscription : MonoBehaviour { private int nWidth = 140; private int nHeight = 40; private static bool bIsReady; private int nXStart = 10; private int nYStart = 35; private static string APP_ID = "76d0898e-8772-49a9-aa55-1ec251a21686"; private static bool bInit = true; private void Start() { Api.Init(InitStatusHandler, APP_ID); } private void OnGUI() { GUIStyle style = new GUIStyle("button"); if (!bInit) { GUI.contentColor = Color.white; } else { GUI.contentColor = Color.gray; } if (GUI.Button(new Rect(nXStart, nYStart, nWidth, nHeight), "Init", style) && !bInit) { Api.Init(InitStatusHandler, APP_ID); } if (bInit) { GUI.contentColor = Color.white; } else { GUI.contentColor = Color.grey; } if (GUI.Button(new Rect(nXStart + (nWidth + 10), nYStart, nWidth, nHeight), "Shutdown", style) && bInit) { Api.Shutdown(ShutdownHandler); } if (GUI.Button(new Rect(nXStart + 2 * (nWidth + 10), nYStart, nWidth, nHeight), "IsReady", style) && bInit) { Subscription.IsReady(IsReadyHandler); } if (GUI.Button(new Rect(nXStart + 3 * (nWidth + 10), nYStart, nWidth, nHeight), "GetUserStatus", style) && bInit && bIsReady) { SubscriptionStatus userStatus = Subscription.GetUserStatus(); string text = ((!userStatus.Platforms.Contains(SubscriptionStatus.Platform.Windows)) ? "false" : "true"); string text2 = ((!userStatus.Platforms.Contains(SubscriptionStatus.Platform.Android)) ? "false" : "true"); string empty = string.Empty; switch (userStatus.Type) { case SubscriptionStatus.TransactionType.Unknown: empty = "Unknown"; break; case SubscriptionStatus.TransactionType.Paid: empty = "Paid"; break; case SubscriptionStatus.TransactionType.Redeem: empty = "Redeem"; break; case SubscriptionStatus.TransactionType.FreeTrial: empty = "FreeTrial"; break; default: empty = "Unknown"; break; } Viveport.Core.Logger.Log("User is a Windows subscriber: " + text + ". User is a Android subscriber: " + text2 + ". transactionType :" + empty); } } private static void InitStatusHandler(int nResult) { if (nResult == 0) { bInit = true; bIsReady = false; Viveport.Core.Logger.Log("InitStatusHandler is successful"); } else { bInit = false; Viveport.Core.Logger.Log("InitStatusHandler error : " + nResult); } } private static void ShutdownHandler(int nResult) { if (nResult == 0) { bInit = false; bIsReady = false; Viveport.Core.Logger.Log("ShutdownHandler is successful"); } else { Viveport.Core.Logger.Log("ShutdownHandler error: " + nResult); } } private static void IsReadyHandler(int nResult, string message) { if (nResult == 0) { Viveport.Core.Logger.Log("Subscription is ready"); bIsReady = true; return; } Viveport.Core.Logger.Log("Subscription IsReadyHandler error: " + nResult + " Message : " + message); } }