コード例 #1
0
        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
            }
        }
コード例 #2
0
    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);
                }
            }
        }
    }
コード例 #3
0
        /// <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();
        }
    /// <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;
        }
    }
コード例 #5
0
        /// <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);
            }
        }