Пример #1
0
        private static IEnumerator Synchronize(CloudData cloudData)
        {
            bool synchronized;

            var localData = LocalSaveSystem.LoadLocalData();

            if (!localData.Synchronized)
            {
                localData.Synchronized = true;

                if (cloudData == null)
                {
                    var defaultCloudData = CloudData.FromLocalData(localData);
                    PlayGamesServices.SaveCloudData(defaultCloudData);
                }
                else
                {
                    localData.Characters   = cloudData.characters;
                    localData.Platforms    = cloudData.platforms;
                    localData.Environments = cloudData.environments;
                    localData.SaveTime     = cloudData.saveTime;
                    localData.HighScore    = cloudData.highScore;
                    localData.Coins        = cloudData.coins;
                }

                synchronized = true;
            }
            else
            {
                if (localData.SaveTime > cloudData.saveTime)
                {
                    var newCloudData = CloudData.FromLocalData(localData);
                    PlayGamesServices.SaveCloudData(newCloudData);

                    PlayGamesServices.ReportScore(Gps.LeaderboardHighScore, localData.HighScore);
                }
                else if (localData.SaveTime < cloudData.saveTime)
                {
                    localData.Characters   = cloudData.characters;
                    localData.Platforms    = cloudData.platforms;
                    localData.Environments = cloudData.environments;
                    localData.SaveTime     = cloudData.saveTime;
                    localData.HighScore    = cloudData.highScore;
                    localData.Coins        = cloudData.coins;
                }

                synchronized = true;
            }

            LoadGameData(localData);

            yield return(new WaitUntil(() => synchronized));
        }
        private void SyncLocalWithCloud()
        {
            var localData = LocalSaveSystem.LoadLocalData();

            localData.Synchronized = true;
            LocalSaveSystem.SaveLocalData(localData);

            var defaultCloudData = CloudData.FromLocalData(localData);

            PlayGamesServices.SaveCloudData(defaultCloudData);

            PlayGamesServices.ReportScore(Gps.LeaderboardHighScore, localData.HighScore);

            ActivateAccountPanels(new[] { "signed" });
        }
        private void SaveProgress()
        {
            earnedScoreLabel.text = _earnedScore.ToString();
            earnedCoinsLabel.text = _earnedCoins.ToString();

            if (_earnedCoins > 0 && InternetConnection.Available())
            {
                multiplyCoinsButton.gameObject.SetActive(true);
            }

            var localData = LocalSaveSystem.LoadLocalData();

            var highScore = _gameData.HighScore;

            if (highScore < _earnedScore)
            {
                localData.HighScore = _earnedScore;
                _gameData.HighScore = _earnedScore;
                newRecordLabel.gameObject.SetActive(true);

                if (PlayGamesServices.IsAuthenticated && InternetConnection.Available())
                {
                    PlayGamesServices.ReportScore(Gps.LeaderboardHighScore, _earnedScore);
                }
            }

            localData.SaveTime = DateTime.Now.Ticks;
            localData.Coins   += _earnedCoins;
            _gameData.Coins   += _earnedCoins;

            if (PlayGamesServices.IsAuthenticated && InternetConnection.Available())
            {
                PlayGamesServices.SaveCloudData(CloudData.FromLocalData(localData));
            }
            LocalSaveSystem.SaveLocalData(localData);
        }