/// <summary> /// Raises the <see cref="OnCloudLoadComplete"/> event. /// </summary> /// <param name="success">If the load was successful or not.</param> public void RaiseOnCloudLoadComplete(bool success) { #if CO_DEBUG Debug.Log("OnCloudLoadComplete: " + (success ? "Cloud load was successful." : "Cloud load failed.")); #endif CloudOnceUtils.SafeInvoke(OnCloudLoadComplete, success); }
/// <summary> /// Raises the <see cref="OnPlayerImageDownloaded"/> event. /// </summary> public void RaiseOnPlayerImageDownloaded(Texture2D playerImage) { #if CLOUDONCE_DEBUG Debug.Log("OnPlayerImageDownloaded"); #endif CloudOnceUtils.SafeInvoke(OnPlayerImageDownloaded, playerImage); }
/// <summary> /// Raises the <see cref="OnNewCloudValues"/> event. /// </summary> /// <param name="changedKeys">A <see cref="string"/> array of the changed interal IDs.</param> public void RaiseOnNewCloudValues(string[] changedKeys) { #if CLOUDONCE_DEBUG Debug.Log("OnNewCloudValues: " + changedKeys.Length + " values have changed."); #endif CloudOnceUtils.SafeInvoke(OnNewCloudValues, changedKeys); }
/// <summary> /// Raises the <see cref="OnSignInFailed"/> event. /// </summary> public void RaiseOnSignInFailed() { #if CLOUDONCE_DEBUG Debug.Log("OnSignInFailed"); #endif CloudOnceUtils.SafeInvoke(OnSignInFailed); }
/// <summary> /// Raises the <see cref="OnCloudSaveComplete"/> event. /// </summary> /// <param name="success">If the save was successful or not.</param> public void RaiseOnCloudSaveComplete(bool success) { #if CLOUDONCE_DEBUG Debug.Log("OnCloudSaveComplete: " + (success ? "Cloud save was successful." : "Cloud save failed.")); #endif CloudOnceUtils.SafeInvoke(OnCloudSaveComplete, success); }
/// <summary> /// Emulates initialization with a randomized delay. /// </summary> /// <param name="activateCloudSave">Whether or not Cloud Saving should be activated.</param> /// <param name="autoSignIn"> /// Whether or not <see cref="SignIn"/> will be called automatically once the cloud provider is initialized. /// </param> /// <param name="autoCloudLoad"> /// Whether or not cloud data should be loaded automatically if the user is successfully signed in. /// Ignored if Cloud Saving is deactivated or the user fails to sign in. /// </param> public override void Initialize(bool activateCloudSave = true, bool autoSignIn = true, bool autoCloudLoad = true) { CloudSaveInitialized = activateCloudSave; cloudSaveEnabled = activateCloudSave; var delay = Random.Range(0.5f, 2f); Debug.Log(string.Format("Simulating random Initialize delay of {0} seconds", delay)); // Normal MonoBehaviour Invoke uses scalable delta time, some games use timescale to pause and use unscaled time in GUI // To Simulate Random Cloud Init Delay right we need to invoke at unscaled time if (autoSignIn) { var onInitializeComplete = new UnityAction(() => { SignIn(autoCloudLoad, arg0 => cloudOnceEvents.RaiseOnInitializeComplete()); }); StartCoroutine(CloudOnceUtils.InvokeUnscaledTime(onInitializeComplete, delay)); } else { StartCoroutine(CloudOnceUtils.InvokeUnscaledTime(cloudOnceEvents.RaiseOnInitializeComplete, delay)); } if (activateCloudSave && autoCloudLoad) { var loadDelay = Random.Range(delay, delay + 2f); Debug.Log(string.Format("Simulating random Cloud load delay of {0} seconds", loadDelay)); StartCoroutine(CloudOnceUtils.InvokeUnscaledTime(Cloud.Storage.Load, loadDelay)); } }
/// <summary> /// Reconstructs the meta data from a <see cref="JSONObject"/>. /// </summary> /// <param name="jsonObject"><see cref="JSONObject"/> containing the meta data.</param> public void FromJSONObject(JSONObject jsonObject) { var dataTypeAlias = CloudOnceUtils.GetAlias(typeof(SyncableItemMetaData).Name, jsonObject, c_aliasDataType, c_oldAliasDataType); var persistenceTypeAlias = CloudOnceUtils.GetAlias(typeof(SyncableItemMetaData).Name, jsonObject, c_aliasPersistenceType, c_oldAliasPersistenceType); if (!string.IsNullOrEmpty(jsonObject[dataTypeAlias].String)) { DataType = (DataType)Enum.Parse(typeof(DataType), jsonObject[dataTypeAlias].String); } else { DataType = (DataType)(short)jsonObject[dataTypeAlias].F; } if (!string.IsNullOrEmpty(jsonObject[persistenceTypeAlias].String)) { PersistenceType = (PersistenceType)Enum.Parse(typeof(PersistenceType), jsonObject[persistenceTypeAlias].String); } else { PersistenceType = (PersistenceType)(short)jsonObject[persistenceTypeAlias].F; } if (jsonObject.HasFields(c_aliasTimestamp)) { Timestamp = DateTime.FromBinary(Convert.ToInt64(jsonObject[c_aliasTimestamp].String)); } else if (jsonObject.HasFields(c_oldAliasTimestamp)) { Timestamp = DateTime.FromBinary(Convert.ToInt64(jsonObject[c_oldAliasTimestamp].String)); } }
private static void ReportError(string errorMessage, Action <CloudRequestResult <bool> > callbackAction) { #if CO_DEBUG Debug.LogWarning(errorMessage); #endif CloudOnceUtils.SafeInvoke(callbackAction, new CloudRequestResult <bool>(false, errorMessage)); }
/// <summary> /// Raises the <see cref="OnSignedInChanged"/> event. /// </summary> public void RaiseOnSignedInChanged(bool isSignedIn) { #if CLOUDONCE_DEBUG Debug.Log("OnSignedInChanged: " + (isSignedIn ? "Signed In" : "Signed Out")); #endif CloudOnceUtils.SafeInvoke(OnSignedInChanged, isSignedIn); }
/// <summary> /// Raises the <see cref="OnInitializeComplete"/> event. /// </summary> public void RaiseOnInitializeComplete() { #if CLOUDONCE_DEBUG Debug.Log("OnInitializeComplete"); #endif CloudOnceUtils.SafeInvoke(OnInitializeComplete); }
/// <summary> /// Reconstructs a <see cref="CurrencyValue"/> from a <see cref="JSONObject"/>. /// </summary> /// <param name="jsonObject"><see cref="JSONObject"/> containing a <see cref="CurrencyValue"/></param> public void FromJSONObject(JSONObject jsonObject) { var addAlias = CloudOnceUtils.GetAlias(typeof(CurrencyValue).Name, jsonObject, c_aliasAdditions, c_oldAliasAdditions); var subAlias = CloudOnceUtils.GetAlias(typeof(CurrencyValue).Name, jsonObject, c_aliasSubtractions, c_oldAliasSubtractions); Additions = jsonObject[addAlias].F; Subtractions = jsonObject[subAlias].F; }
/// <summary> /// Reconstructs the item from a <see cref="JSONObject"/>. /// </summary> /// <param name="jsonObject"><see cref="JSONObject"/> containing the item data.</param> public void FromJSONObject(JSONObject jsonObject) { var valueStringAlias = CloudOnceUtils.GetAlias(typeof(SyncableItem).Name, jsonObject, aliasValueString, oldAliasValueString); var metaDataAlias = CloudOnceUtils.GetAlias(typeof(SyncableItem).Name, jsonObject, aliasMetadata, oldAliasMetadata); valueString = jsonObject[valueStringAlias].String; Metadata = new SyncableItemMetaData(jsonObject[metaDataAlias]); }
/// <summary> /// Dummy SignIn method. /// </summary> /// <param name="autoCloudLoad"> /// Whether or not cloud data should be loaded automatically when the user is successfully signed in. /// Ignored if Cloud Saving is deactivated or the user fails to sign in. /// </param> /// <param name='callback'> /// The callback to call when authentication finishes. It will be called /// with <c>true</c> if authentication was successful, <c>false</c> otherwise. /// </param> public override void SignIn(bool autoCloudLoad = true, UnityAction <bool> callback = null) { CloudOnceUtils.SafeInvoke(callback, false); if (autoCloudLoad) { cloudOnceEvents.RaiseOnCloudLoadComplete(false); } }
/// <summary> /// Recreates the currency from a <see cref="JSONObject"/>. /// </summary> /// <param name="jsonObject"><see cref="JSONObject"/> containing the currency data.</param> public void FromJSONObject(JSONObject jsonObject) { var idAlias = CloudOnceUtils.GetAlias(typeof(SyncableCurrency).Name, jsonObject, aliasCurrencyID, oldAliasCurrencyID); var dataAlias = CloudOnceUtils.GetAlias(typeof(SyncableCurrency).Name, jsonObject, aliasCurrencyData, oldAliasCurrencyData); CurrencyID = jsonObject[idAlias].String; DeviceCurrencyValues = JsonHelper.Convert <Dictionary <string, CurrencyValue> >(jsonObject[dataAlias]); }
/// <summary> /// Signs in to Apple Game Center. /// </summary> /// <param name="autoCloudLoad"> /// Whether or not cloud data should be loaded automatically when the user is successfully signed in. /// Ignored if Cloud Saving is deactivated or the user fails to sign in. /// </param> /// <param name='callback'> /// The callback to call when authentication finishes. It will be called /// with <c>true</c> if authentication was successful, <c>false</c> otherwise. /// </param> public override void SignIn(bool autoCloudLoad = true, UnityAction <bool> callback = null) { if (isSigningIn) { return; } isSigningIn = true; if (IsSignedIn) { #if CLOUDONCE_DEBUG Debug.Log("Already signed in to Apple Game Center." + " If you want to change the user, that must be done from the iOS Settings menu."); #endif CloudOnceUtils.SafeInvoke(callback, true); if (CloudSaveEnabled && autoCloudLoad) { var iCloudWrapper = (iOSCloudSaveWrapper)Storage; iCloudWrapper.Load(); } isSigningIn = false; return; } Social.localUser.Authenticate( success => { if (success) { #if CLOUDONCE_DEBUG Debug.Log("Successfully signed in to Apple Game Center."); #endif cloudOnceEvents.RaiseOnSignedInChanged(true); cloudOnceEvents.RaiseOnPlayerImageDownloaded(Social.localUser.image); UpdateAchievementsData(); } else { #if CLOUDONCE_DEBUG Debug.LogWarning("Failed to sign in to Apple Game Center."); #endif cloudOnceEvents.RaiseOnSignInFailed(); } if (CloudSaveEnabled && autoCloudLoad) { var iCloudWrapper = (iOSCloudSaveWrapper)Storage; iCloudWrapper.Load(); } CloudOnceUtils.SafeInvoke(callback, success); isSigningIn = false; }); }
/// <summary> /// Load the user profiles accociated with the given array of user IDs. /// </summary> /// <param name="userIDs">The users to retrieve profiles for.</param> /// <param name="callback">Callback to handle the user profiles.</param> public override void LoadUsers(string[] userIDs, Action <IUserProfile[]> callback) { var profiles = new IUserProfile[userIDs.Length]; for (var i = 0; i < profiles.Length; i++) { profiles[i] = new TestUserProfile(); } CloudOnceUtils.SafeInvoke(callback, profiles); }
/// <summary> /// Signs in to Google Play Game Services. /// </summary> /// <param name="autoCloudLoad"> /// Whether or not cloud data should be loaded automatically if the user is successfully signed in. /// Ignored if Cloud Saving is deactivated or the user fails to sign in. /// </param> /// <param name='callback'> /// The callback to call when authentication finishes. It will be called /// with <c>true</c> if authentication was successful, <c>false</c> otherwise. /// </param> public override void SignIn(bool autoCloudLoad = true, UnityAction <bool> callback = null) { if (!IsGpgsInitialized) { Debug.LogWarning("SignIn called, but Google Play Game Services has not been initialized. Ignoring call."); CloudOnceUtils.SafeInvoke(callback, false); return; } if (autoCloudLoad) { SetUpAutoCloudLoad(); } IsGuestUserDefault = false; Logger.d("Attempting to sign in to Google Play Game Services."); PlayGamesPlatform.Instance.Authenticate(success => { // Success is handled by OnAutenticated method if (!success) { Logger.w("Failed to sign in to Google Play Game Services."); bool hasNoInternet; try { hasNoInternet = InternetConnectionUtils.GetConnectionStatus() != InternetConnectionStatus.Connected; } catch (NotSupportedException) { hasNoInternet = Application.internetReachability == NetworkReachability.NotReachable; } if (hasNoInternet) { Logger.d("Failure seems to be due to lack of Internet. Will try to connect again next time."); } else { Logger.d("Must assume the failure is due to player opting out" + " of the sign-in process, setting guest user as default"); IsGuestUserDefault = true; } cloudOnceEvents.RaiseOnSignInFailed(); if (autoCloudLoad) { cloudOnceEvents.RaiseOnCloudLoadComplete(false); } } CloudOnceUtils.SafeInvoke(callback, success); }); }
/// <summary> /// Load the user profiles accociated with the given array of user IDs. /// </summary> /// <param name="userIDs">The users to retrieve profiles for.</param> /// <param name="callback">Callback to handle the user profiles.</param> public override void LoadUsers(string[] userIDs, Action <IUserProfile[]> callback) { if (!IsGpgsInitialized) { Debug.LogWarning("LoadUsers called, but Google Play Game Services has not been initialized. Ignoring call."); CloudOnceUtils.SafeInvoke(callback, new IUserProfile[0]); return; } PlayGamesPlatform.Instance.LoadUsers(userIDs, callback); }
private void OnRevealCompleted(CloudRequestResult <bool> response, Action <CloudRequestResult <bool> > callbackAction) { if (response.Result) { isAchievementHidden = false; CloudOnceUtils.SafeInvoke(callbackAction, new CloudRequestResult <bool>(true)); } else { CloudOnceUtils.SafeInvoke(callbackAction, new CloudRequestResult <bool>(false, response.Error)); } }
/// <summary> /// Simulates signing in. /// </summary> /// <param name="autoCloudLoad"> /// Whether or not cloud data should be loaded automatically when the user is successfully signed in. /// Ignored if Cloud Saving is deactivated or the user fails to sign in. /// </param> /// <param name='callback'> /// The callback to call when authentication finishes. It will be called /// with <c>true</c> if authentication was successful, <c>false</c> otherwise. /// </param> public override void SignIn(bool autoCloudLoad = true, UnityAction <bool> callback = null) { isSignedIn = true; CloudOnceUtils.SafeInvoke(callback, true); cloudOnceEvents.RaiseOnSignedInChanged(true); var delay = Random.Range(0.5f, 2f); Debug.Log(string.Format("Simulating random PlayerImageDownload delay of {0} seconds", delay)); StartCoroutine( CloudOnceUtils.InvokeUnscaledTime( cloudOnceEvents.RaiseOnPlayerImageDownloaded, Texture2D.whiteTexture, delay)); }
/// <summary> /// Shows the GameCircle sign in page. If GameCircle is not initialized, /// the <see cref="Initialize"/> method will be called. /// </summary> /// <param name="autoCloudLoad"> /// Whether or not cloud data should be loaded automatically when the user is successfully signed in. /// Ignored if Cloud Saving is deactivated or the user fails to sign in. /// </param> /// <param name='callback'> /// Due to differences in how the GameCircle platform handles sign in (there is no SignIn method, only Init), /// the callback will always be <c>true</c>. /// </param> public override void SignIn(bool autoCloudLoad = true, UnityAction <bool> callback = null) { if (AGSClient.IsServiceReady()) { AGSClient.ShowSignInPage(); } else { Initialize(CloudSaveEnabled, true, autoCloudLoad); } CloudOnceUtils.SafeInvoke(callback, true); }
private void OnUnlockCompleted(CloudRequestResult <bool> response, Action <CloudRequestResult <bool> > callbackAction) { if (response.Result) { IsUnlocked = true; isAchievementHidden = false; Progress = 100.0; CloudOnceUtils.SafeInvoke(callbackAction, new CloudRequestResult <bool>(true)); } else { CloudOnceUtils.SafeInvoke(callbackAction, new CloudRequestResult <bool>(false, response.Error)); } }
private void OnIncrementCompleted(CloudRequestResult <bool> response, double progress, Action <CloudRequestResult <bool> > callbackAction) { if (response.Result) { Progress = progress; #if UNITY_IOS isAchievementHidden = false; #endif CloudOnceUtils.SafeInvoke(callbackAction, new CloudRequestResult <bool>(true)); } else { CloudOnceUtils.SafeInvoke(callbackAction, new CloudRequestResult <bool>(false, response.Error)); } }
public GameData(string serializedData) { if (string.IsNullOrEmpty(serializedData)) { SyncableItems = new Dictionary <string, SyncableItem>(); SyncableCurrencies = new Dictionary <string, SyncableCurrency>(); return; } var jsonObject = new JSONObject(serializedData); var itemsAlias = CloudOnceUtils.GetAlias(typeof(GameData).Name, jsonObject, c_syncableItemsKey, c_oldSyncableItemsKey); var currencyAlias = CloudOnceUtils.GetAlias(typeof(GameData).Name, jsonObject, c_syncableCurrenciesKey, c_oldSyncableCurrenciesKey); SyncableItems = JsonHelper.Convert <Dictionary <string, SyncableItem> >(jsonObject[itemsAlias]); SyncableCurrencies = JsonHelper.Convert <Dictionary <string, SyncableCurrency> >(jsonObject[currencyAlias]); }
private void OnUpdateAchievementCompleted(CloudRequestResult <bool> response, Action <CloudRequestResult <bool> > callbackAction) { var result = response.Result ? new CloudRequestResult <bool>(true) : new CloudRequestResult <bool>(false, response.Error); CloudOnceUtils.SafeInvoke(callbackAction, result); }
/// <summary> /// Load the user profiles accociated with the given array of user IDs. /// </summary> /// <param name="userIDs">The users to retrieve profiles for.</param> /// <param name="callback">Callback to handle the user profiles.</param> public override void LoadUsers(string[] userIDs, Action <IUserProfile[]> callback) { Debug.LogWarning("LoadUsers functionality does not exist on the Amazon GameCircle platform."); CloudOnceUtils.SafeInvoke(callback, new IUserProfile[0]); }