/// <summary> /// Loads any available cloud data (if signed in and cloud saving is enabled). /// </summary> public void Load() { if (!AmazonCloudProvider.Instance.CloudSaveInitialized || !Cloud.CloudSaveEnabled) { #if CO_DEBUG Debug.LogWarning(!AmazonCloudProvider.Instance.CloudSaveInitialized ? "Cloud Save has not been initialized, aborting cloud load." : "Cloud Save is currently disabled, aborting cloud load."); #endif cloudOnceEvents.RaiseOnCloudLoadComplete(false); return; } if (AGSClient.IsServiceReady()) { #if CO_DEBUG Debug.Log("Loading cloud data"); #endif AGSWhispersyncClient.Synchronize(); cloudOnceEvents.RaiseOnCloudLoadComplete(true); } else { Debug.LogWarning("Attempted to load cloud data, but the AGS service is not ready."); cloudOnceEvents.RaiseOnCloudLoadComplete(false); } }
private void ProcessCloudData() { if (processingCloudData) { return; } processingCloudData = true; if (AGSClient.IsServiceReady()) { using (var dataMap = AGSWhispersyncClient.GetGameData()) { using (var developerString = dataMap.getDeveloperString(DataManager.DevStringKey)) { var cloudValue = developerString.getCloudValue(); if (string.IsNullOrEmpty(cloudValue)) { #if CO_DEBUG Debug.Log("No data saved to the cloud yet."); #endif processingCloudData = false; return; } if (!cloudValue.IsJson()) { try { cloudValue = cloudValue.FromBase64StringToString(); } catch (FormatException) { Debug.LogWarning("Unable to deserialize cloud data!"); return; } } #if CO_DEBUG Debug.Log("Processing cloud data"); #endif var changedKeys = DataManager.MergeLocalDataWith(cloudValue); if (changedKeys.Length > 0) { cloudOnceEvents.RaiseOnNewCloudValues(changedKeys); } processingCloudData = false; } } } else { processingCloudData = false; #if CO_DEBUG Debug.LogWarning("Attempting to process cloud data, but the AGS service is not ready!"); #endif } }
public void Initialize() { GlobaldataMap = AGSWhispersyncClient.GetGameData(); if (GlobaldataMap == null) { Debug.Log("Globaldata map es null"); Managers.GameCircleAmazon.WhisperInitialized = false; return; } Debug.Log("Inicializando WhisperScores"); ScoreList.Clear(); foreach (var packName in Globals.Constants.PackNameArray) { for (var i = 1; i <= Globals.Constants.LevelsPerPack; i++) { foreach (var enumVal in Enum.GetValues(typeof(GameType))) { SyncableLevelScore synclevelscore = new SyncableLevelScore(); synclevelscore.map = GlobaldataMap.GetMap(packName + "@" + enumVal.ToString() + "@LEVEL-" + i.ToString()); synclevelscore.score.BestScore = synclevelscore.map.GetHighestNumber("BestScore"); if (!synclevelscore.score.BestScore.IsSet()) { synclevelscore.score.BestScore.Set(0); } synclevelscore.score.PackName = synclevelscore.map.GetLatestString("PackName"); synclevelscore.score.GameType = synclevelscore.map.GetLatestString("GameType"); synclevelscore.score.LevelName = synclevelscore.map.GetLatestString("LevelName"); synclevelscore.score.PackName.Set(packName); synclevelscore.score.GameType.Set(enumVal.ToString()); synclevelscore.score.LevelName.Set("LEVEL-" + i.ToString()); /* synclevelscore.score.PackName = synclevelscore.map.GetLatestString("PackName"); * synclevelscore.score.GameType = synclevelscore.map.GetLatestString("GameType"); * synclevelscore.score.LevelName = synclevelscore.map.GetLatestString("LevelName"); * synclevelscore.score.Hits = synclevelscore.map.GetLatestNumber("Hits"); * synclevelscore.score.MaxTurns = synclevelscore.map.GetLatestNumber("MaxTurns"); * synclevelscore.score.TimeUsed = synclevelscore.map.GetLatestNumber("TimeUsed"); * */ ScoreList.Add(synclevelscore); } } } }
/// <summary> /// Clears all cloud variables currently stored in the cloud. /// </summary> private static void DeleteCloudData() { #if !UNITY_EDITOR && UNITY_ANDROID #if CLOUDONCE_AMAZON if (AGSClient.IsServiceReady()) { using (var dataMap = AGSWhispersyncClient.GetGameData()) { using (var developerString = dataMap.getDeveloperString(DevStringKey)) { developerString.setValue(string.Empty); if (AGSPlayerClient.IsSignedIn()) { AGSWhispersyncClient.Synchronize(); } else { AGSWhispersyncClient.Flush(); } } } } #elif CLOUDONCE_GOOGLE if (GooglePlayGamesCloudProvider.Instance.IsGpgsInitialized && PlayGamesPlatform.Instance.IsAuthenticated()) { PlayGamesPlatform.Instance.SavedGame.OpenWithAutomaticConflictResolution( "GameData", DataSource.ReadCacheOrNetwork, ConflictResolutionStrategy.UseLongestPlaytime, (status, metadata) => { if (status == SavedGameRequestStatus.Success) { PlayGamesPlatform.Instance.SavedGame.Delete(metadata); } }); } #endif #elif !UNITY_EDITOR && UNITY_IOS iCloudBridge.DeleteString(DevStringKey); #endif PlayerPrefs.DeleteKey(DevStringKey); PlayerPrefs.Save(); }
private void ServiceReadyEvent() { #if CLOUDONCE_DEBUG Debug.Log("OnServiceReady"); #endif if (cloudSaveEnabled) { // Due to some flaws in the Amazon SDK lib (static constructors, // where one depends on another being called first, AGSClient.Init must be called before // AGSWhispersyncClient) we put the initialization logic here. // Otherwise we will not get some of the event callbacks we need. #if CLOUDONCE_DEBUG Debug.Log("Initializing WhisperSync"); #endif AGSWhispersyncClient.InitAGSWhispersyncClient(); CloudSaveInitialized = true; } cloudOnceEvents.RaiseOnInitializeComplete(); AGSClient.ServiceReadyEvent -= ServiceReadyEvent; isInitializing = false; }
/// <summary> /// Initializes the data map if available. /// </summary> void InitializeDataMapIfAvailable() { // if the data map was already retrieved, nothing to do here. if (null != dataMap) { return; } dataMap = AGSWhispersyncClient.GetGameData(); // if the data map was retrieved for the first time, do // any first-time initialization behavior, such as subscribing // to callbacks. if (null != dataMap) { // subscribe to the new cloud data event. AGSWhispersyncClient.OnNewCloudDataEvent += OnNewCloudData; AGSWhispersyncClient.OnDataUploadedToCloudEvent += OnDataUploadedToCloud; AGSWhispersyncClient.OnThrottledEvent += OnThrottled; AGSWhispersyncClient.OnDiskWriteCompleteEvent += OnDiskWriteComplete; AGSWhispersyncClient.OnFirstSynchronizeEvent += OnFirstSynchronize; AGSWhispersyncClient.OnAlreadySynchronizedEvent += OnAlreadySynchronized; AGSWhispersyncClient.OnSyncFailedEvent += OnSyncFailed; } }
public void onSyncFailed(string failReason) { AGSClient.Log("AGSWhispersyncClient - OnSyncFailed"); AGSWhispersyncClient.OnSyncFailed(failReason); }
public void onAlreadySynchronized(string empty) { AGSClient.Log("AGSWhispersyncClient - OnAlreadySynchronized"); AGSWhispersyncClient.OnAlreadySynchronized(); }
public void onFirstSynchronize(string empty) { Debug.Log("AGSWhispersyncClient - OnFirstSynchronize"); AGSWhispersyncClient.OnFirstSynchronize(); }
public void onDiskWriteComplete(string empty) { AGSClient.Log("AGSWhispersyncClient - OnDiskWriteComplete"); AGSWhispersyncClient.OnDiskWriteComplete(); }
public void onThrottled(string empty) { AGSClient.Log("AGSWhispersyncClient - OnThrottled"); AGSWhispersyncClient.OnThrottled(); }
/// <summary> /// Saves all cloud variables, to both disk and cloud. /// If <see cref="Cloud.CloudSaveEnabled"/> is <c>false</c>, it will only save to disk. /// Skips saving if no variables have been changed. /// </summary> public void Save() { if (saveInitialized) { return; } saveInitialized = true; DataManager.SaveToDisk(); if (!AmazonCloudProvider.Instance.CloudSaveInitialized || !Cloud.CloudSaveEnabled) { #if CO_DEBUG Debug.LogWarning(!AmazonCloudProvider.Instance.CloudSaveInitialized ? "Cloud Save has not been initialized, skipping upload and only saving to disk." : "Cloud Save is currently disabled, skipping upload and only saving to disk."); #endif saveInitialized = false; cloudOnceEvents.RaiseOnCloudSaveComplete(false); return; } if (DataManager.IsLocalDataDirty) { if (AGSClient.IsServiceReady()) { #if CO_DEBUG Debug.Log("Saving cloud data"); #endif using (var dataMap = AGSWhispersyncClient.GetGameData()) { using (var developerString = dataMap.getDeveloperString(DataManager.DevStringKey)) { developerString.setValue(DataManager.SerializeLocalData().ToBase64String()); if (AGSPlayerClient.IsSignedIn()) { AGSWhispersyncClient.Synchronize(); } else { AGSWhispersyncClient.Flush(); } saveInitialized = false; DataManager.IsLocalDataDirty = false; cloudOnceEvents.RaiseOnCloudSaveComplete(true); } } } else { saveInitialized = false; Debug.LogWarning("Attempted to save cloud data, but the AGS service is not ready."); cloudOnceEvents.RaiseOnCloudSaveComplete(false); } } else { #if CO_DEBUG Debug.Log("Save called, but no data has changed since last save."); #endif saveInitialized = false; cloudOnceEvents.RaiseOnCloudSaveComplete(false); } }
public void onNewCloudData(string empty) { AGSWhispersyncClient.OnNewCloudData(); }
public void onSyncFailed(string failReason) { AGSWhispersyncClient.OnSyncFailed(failReason); }
public void onFirstSynchronize(string empty) { AGSWhispersyncClient.OnFirstSynchronize(); }
public void onThrottled(string empty) { AGSWhispersyncClient.OnThrottled(); }
/// <summary> /// Draws the menu. Note that this must be called from an OnGUI function. /// </summary> public override void DrawMenu() { // if cloud data has been received, show how long ago that was. if (lastOnNewCloudData.HasValue) { double timeElapsed = (System.DateTime.Now - lastOnNewCloudData.Value).TotalSeconds; AmazonGUIHelpers.CenteredLabel(string.Format(cloudDataLastReceivedLabel, timeElapsed)); } if (lastOnDataUploadedToCloud.HasValue) { double timeElapsed = (System.DateTime.Now - lastOnDataUploadedToCloud.Value).TotalSeconds; AmazonGUIHelpers.CenteredLabel(string.Format(uploadedToCloudLabel, timeElapsed)); } if (lastOnThrottled.HasValue) { double timeElapsed = (System.DateTime.Now - lastOnThrottled.Value).TotalSeconds; AmazonGUIHelpers.CenteredLabel(string.Format(lastThrottledLabel, timeElapsed)); } if (lastOnDiskWriteComplete.HasValue) { double timeElapsed = (System.DateTime.Now - lastOnDiskWriteComplete.Value).TotalSeconds; AmazonGUIHelpers.CenteredLabel(string.Format(diskWriteCompleteLabel, timeElapsed)); } if (lastOnFirstSynchronize.HasValue) { double timeElapsed = (System.DateTime.Now - lastOnFirstSynchronize.Value).TotalSeconds; AmazonGUIHelpers.CenteredLabel(string.Format(firstSynchronizeLabel, timeElapsed)); } if (lastOnAlreadySynchronized.HasValue) { double timeElapsed = (System.DateTime.Now - lastOnAlreadySynchronized.Value).TotalSeconds; AmazonGUIHelpers.CenteredLabel(string.Format(alreadySychronizedLabel, timeElapsed)); } if (lastOnSyncFailed.HasValue) { double timeElapsed = (System.DateTime.Now - lastOnSyncFailed.Value).TotalSeconds; AmazonGUIHelpers.CenteredLabel(string.Format(syncFailedLabel, timeElapsed, failReason)); } else { // display a message that cloud data has not been received yet. AmazonGUIHelpers.CenteredLabel(noCloudDataReceivedLabel); } // This button allows the user to synchronize GameCircle data. if (GUILayout.Button(syncDataButtonLabel)) { AGSWhispersyncClient.Synchronize(); } // a small space to spread things out. GUILayout.Label(GUIContent.none); // This button allows the user to flush GameCircle data. if (GUILayout.Button(flushButtonLabel)) { AGSWhispersyncClient.Flush(); } // a small space to spread things out. GUILayout.Label(GUIContent.none); // try and initialize the Whispersync data map. InitializeDataMapIfAvailable(); if (null == dataMap) { // if it couldn't be retrieved, bail out with an error. AmazonGUIHelpers.CenteredLabel(whispersyncUnavailableLabel); return; } // draws the available syncable numbers DrawSyncableNumbers(); // draws the available accumulating numbers DrawAccumulatingNumbers(); // draws the available syncable number lists DrawSyncableNumberLists(); // draws the available hash sets. DrawHashSets(); // draws the developer string DrawDeveloperString(); }
// ReSharper disable UnusedParameter.Global public void onNewCloudData(string empty) { AGSClient.Log("AGSWhispersyncClient - OnNewCloudData"); AGSWhispersyncClient.OnNewCloudData(); }
public void onDataUploadedToCloud(string empty) { AGSClient.Log("AGSWhispersyncClient - OnDataUploadedToCloud"); AGSWhispersyncClient.OnDataUploadedToCloud(); }
public void SynchronizeScores() { AGSWhispersyncClient.Synchronize(); }