/// <summary> /// Check if user has purchased the subscription and eligible to play /// </summary> /// <param name="callback"> Returns the boolean result whether the user is subscribed and eligible to play the game via callback when the operation is completed</param> public void GetUserEligibleToPlay(ResultCallback <bool> callback) { Report.GetFunctionLog(this.GetType().Name); ResultCallback <ItemInfo> onGotItemInfo = (itemInfoResult) => { if (itemInfoResult.IsError) { callback.TryError(itemInfoResult.Error.Code); return; } string[] skus = itemInfoResult.Value.features; string[] appIds = { AccelBytePlugin.Config.AppId }; AccelBytePlugin.GetEntitlement().GetUserEntitlementOwnershipAny(null, appIds, skus, (ownershipResult) => { if (ownershipResult.IsError) { callback.TryError(ownershipResult.Error.Code); return; } callback.TryOk(ownershipResult.Value.owned); }); }; AccelBytePlugin.GetItems().GetItemByAppId(AccelBytePlugin.Config.AppId, onGotItemInfo); }
/// <summary> /// Check whether if this static class is need to be refreshed/re-init /// </summary> private static void CheckPlugin() { if (!AccelBytePlugin.initialized) { AccelBytePlugin.Initialize(); AccelBytePlugin.initialized = true; } }
internal static void Initialize(Config config = null) { #if (UNITY_WEBGL || UNITY_PS4 || UNITY_XBOXONE || UNITY_SWITCH || UNITY_STADIA || ENABLE_IL2CPP) && !UNITY_EDITOR AccelBytePlugin.RegisterUtf8JsonResolver(); #endif AccelBytePlugin.ResetApis(); AccelBytePlugin.initialized = true; if (config == null) { var configFile = Resources.Load("AccelByteSDKConfig"); if (configFile == null) { throw new Exception("'AccelByteSDKConfig.json' isn't found in the Project/Assets/Resources directory"); } string wholeJsonText = ((TextAsset)configFile).text; AccelBytePlugin.config = wholeJsonText.ToObject <Config>(); } else { AccelBytePlugin.config = config; } AccelBytePlugin.config.CheckRequiredField(); AccelBytePlugin.config.Expand(); AccelBytePlugin.coroutineRunner = new CoroutineRunner(); AccelBytePlugin.httpClient = new AccelByteHttpClient(); AccelBytePlugin.httpClient.SetCredentials(AccelBytePlugin.config.ClientId, AccelBytePlugin.config.ClientSecret); AccelBytePlugin.httpClient.SetBaseUri(new Uri(AccelBytePlugin.config.BaseUrl)); var session = new LoginSession( AccelBytePlugin.config.IamServerUrl, AccelBytePlugin.config.Namespace, AccelBytePlugin.config.RedirectUri, AccelBytePlugin.httpClient, AccelBytePlugin.coroutineRunner, AccelBytePlugin.config.UsePlayerPrefs); AccelBytePlugin.gameClient = new GameClient(AccelBytePlugin.config, AccelBytePlugin.httpClient); AccelBytePlugin.user = new User( session, new UserAccount( AccelBytePlugin.config.IamServerUrl, AccelBytePlugin.config.Namespace, session, AccelBytePlugin.httpClient), AccelBytePlugin.coroutineRunner); ServicePointManager.ServerCertificateValidationCallback = AccelBytePlugin.OnCertificateValidated; }
static AccelBytePlugin() { #if UNITY_EDITOR // Handle an unexpected behaviour if Domain Reload (experimental) is disabled EditorApplication.playModeStateChanged += state => { if (state == PlayModeStateChange.ExitingEditMode) { AccelBytePlugin.initialized = false; AccelBytePlugin.ResetApis(); } }; #endif }