private void ChangeAccountState(bool authenticated)
        {
            var localData = LocalSaveSystem.LoadLocalData();

            if (InternetConnection.Available())
            {
                if (authenticated)
                {
                    StartCoroutine(LoadUser());
                    PlayGamesServicesEventSystem.Instance.UserAuthenticated(true);
                }

                if (authenticated && localData.Synchronized)
                {
                    ActivateAccountPanels(new[] { "signed" });
                }
                else if (authenticated && !localData.Synchronized)
                {
                    ActivateAccountPanels(new[] { "sync" });
                }
                else if (!authenticated)
                {
                    ActivateAccountPanels(new[] { "unsigned" });
                }
            }
            else
            {
                ActivateAccountPanels(new[] { "noInternet" });
            }
        }
        private void CloseSettings()
        {
            var localData = LocalSaveSystem.LoadLocalData();

            platformWithPlayer.SetActive(true);
            settingsPanel.SetActive(false);
            menuPanel.SetActive(true);

            if (InternetConnection.Available())
            {
                if (PlayGamesServices.IsAuthenticated && localData.Synchronized)
                {
                    ActivateAccountPanels(new[] { "signed" });
                }
                else if (PlayGamesServices.IsAuthenticated && !localData.Synchronized)
                {
                    ActivateAccountPanels(new[] { "sync" });
                }
                else if (!PlayGamesServices.IsAuthenticated)
                {
                    ActivateAccountPanels(new[] { "unsigned" });
                }
            }
            else
            {
                ActivateAccountPanels(new[] { "noInternet" });
            }
        }
        private IEnumerator Start()
        {
            yield return(null);

            var localData = LocalSaveSystem.LoadLocalData();

            musicSlider.value       = localData.Settings.MusicVolume;
            soundsSlider.value      = localData.Settings.SoundsVolume;
            antiAliasingToggle.isOn = localData.Settings.Antialiasing;
            shadowsToggle.isOn      = localData.Settings.Shadows;

            ChangeMusicVolume(localData.Settings.MusicVolume);
            ChangeSoundsVolume(localData.Settings.SoundsVolume);
            QualitySettings.antiAliasing =
                localData.Settings.Antialiasing ? (int)AntiAliasing.Enabled : (int)AntiAliasing.Disabled;
            QualitySettings.shadows =
                localData.Settings.Shadows ? ShadowQuality.HardOnly : ShadowQuality.Disable;

            switch (LocalizationSettings.SelectedLocale.Identifier.Code)
            {
            case "en":
                englishLocaleButton.GetComponent <Util.Button>().SelectOnStart();
                break;

            case "ru":
                russianLocaleButton.GetComponent <Util.Button>().SelectOnStart();
                break;
            }
        }
Exemplo n.º 4
0
        private static void LoadGameData(LocalData data)
        {
            LocalSaveSystem.SaveLocalData(data);

            var charactersData = data.Characters;
            var platformsData  = data.Platforms;
            var gameData       = DataManager.Instance.GameData;

            foreach (var characterData in charactersData)
            {
                var character = gameData.Characters.FirstOrDefault(c => c.Id == characterData.Id);
                if (character != null)
                {
                    character.IsPurchased     = characterData.IsPurchased;
                    character.IsSelected      = characterData.IsSelected;
                    character.IsEffectEnabled = characterData.IsEffectEnabled;
                }
            }

            foreach (var platformData in platformsData)
            {
                var platform = gameData.Platforms.FirstOrDefault(p => p.Id == platformData.Id);
                if (platform != null)
                {
                    platform.IsPurchased = platformData.IsPurchased;
                    platform.IsActive    = platformData.IsActive;
                }
            }

            gameData.HighScore = data.HighScore;
            gameData.Coins     = data.Coins;
        }
 private void OnSavedGameOpened(SavedGameRequestStatus status, ISavedGameMetadata game)
 {
     if (status == SavedGameRequestStatus.Success)
     {
         if (!isSaving)
         {
             LoadGame(game);
         }
         else
         {
             SaveGame(game);
         }
     }
     else
     {
         if (!isSaving)
         {
             LocalSaveSystem.LoadSplit(LocalSaveSystem.Load());
         }
         else
         {
             LocalSaveSystem.LocalSave(GameDataToString());
         }
     }
 }
Exemplo n.º 6
0
        public void SaveMusicVolumeChanges()
        {
            var data = LocalSaveSystem.LoadLocalData();

            data.Settings.MusicVolume = musicSlider.value;
            LocalSaveSystem.SaveLocalData(data);
        }
Exemplo n.º 7
0
        public void SaveSoundsVolumeChanges()
        {
            var data = LocalSaveSystem.LoadLocalData();

            data.Settings.SoundsVolume = soundsSlider.value;
            LocalSaveSystem.SaveLocalData(data);
        }
        private void ToggleShadows(bool value)
        {
            var localData = LocalSaveSystem.LoadLocalData();

            localData.Settings.Shadows = value;
            QualitySettings.shadows    = value ? ShadowQuality.HardOnly : ShadowQuality.Disable;
            LocalSaveSystem.SaveLocalData(localData);
        }
        private void ToggleAntialiasing(bool value)
        {
            var localData = LocalSaveSystem.LoadLocalData();

            localData.Settings.Antialiasing = value;
            QualitySettings.antiAliasing    = value ? (int)AntiAliasing.Enabled : (int)AntiAliasing.Disabled;
            LocalSaveSystem.SaveLocalData(localData);
        }
Exemplo n.º 10
0
        private void TogglePlatformActive(bool value)
        {
            var localData = LocalSaveSystem.LoadLocalData();

            localData.Platforms.First(p => p.Id == _currentPlatform.Id).IsActive = value;
            _currentPlatform.IsActive = value;

            LocalSaveSystem.SaveLocalData(localData);

            PlatformsPageEventSystem.Instance.ActivatePlatform(_currentPlatform);
        }
 public void SaveData() //This Saves the game. handling local save or cloud.
 {
     //save local any time you try to save, attempt cloud save too
     LocalSaveSystem.LocalSave(GameDataToString());
     if (Social.localUser.authenticated)
     {
         isSaving = true;
         ((PlayGamesPlatform)Social.Active).SavedGame.OpenWithAutomaticConflictResolution(SAVE_NAME,
                                                                                          DataSource.ReadCacheOrNetwork, ConflictResolutionStrategy.UseLongestPlaytime, OnSavedGameOpened);
     }
 }
Exemplo n.º 12
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));
        }
Exemplo n.º 13
0
        private IEnumerator Start()
        {
            yield return(null);

            var data = LocalSaveSystem.LoadLocalData();

            musicSlider.value  = data.Settings.MusicVolume;
            soundsSlider.value = data.Settings.SoundsVolume;

            ChangeMusicVolume(data.Settings.MusicVolume);
            ChangeSoundsVolume(data.Settings.SoundsVolume);
        }
        private void ToggleCharacterEffect(bool value)
        {
            var localData = LocalSaveSystem.LoadLocalData();

            localData.Characters.First(c => c.Id == _currentCharacter.Id).IsEffectEnabled = value;
            _currentCharacter.IsEffectEnabled = value;

            LocalSaveSystem.SaveLocalData(localData);

            _currentCharacter.Prefab.GetComponent <Effect>().enabled = value;
            platformWithPlayer.transform.GetChild(0).GetComponent <Effect>().enabled = value;
        }
        private void ValidatePurchase()
        {
            var totalCoins     = _gameData.Coins;
            var characterPrice = _currentCharacter.Price;

            if (totalCoins >= characterPrice)
            {
                var localData = LocalSaveSystem.LoadLocalData();

                localData.SaveTime = DateTime.Now.Ticks;
                localData.Coins   -= characterPrice;
                _gameData.Coins   -= characterPrice;

                localData.Characters.First(c => c.Id == _currentCharacter.Id).IsPurchased = true;
                _currentCharacter.IsPurchased = true;

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

                effectToggle.onValueChanged.RemoveAllListeners();
                buyButton.onClick.RemoveAllListeners();
                selectButton.onClick.RemoveAllListeners();

                failureMessage.gameObject.SetActive(false);
                effectToggle.gameObject.SetActive(true);
                buyButton.gameObject.SetActive(false);
                selectButton.gameObject.SetActive(true);

                effectToggle.isOn = _currentCharacter.IsEffectEnabled;
                effectToggle.onValueChanged.AddListener(ToggleCharacterEffect);
                selectButton.onClick.AddListener(SelectCharacter);

                CharactersPageEventSystem.Instance.PurchaseCharacter(_currentCharacter);
                StoreEventSystem.Instance.SuccessfulPurchase();
            }
            else
            {
                var buyButtonTransform = buyButton.GetComponent <RectTransform>();
                buyButtonTransform.DOKill(true);
                buyButtonTransform.DOPunchPosition(new Vector3(15, 0, 0), 0.5f);

                failureMessage.gameObject.SetActive(true);

                var failureMessageTransform = failureMessage.GetComponent <RectTransform>();
                failureMessageTransform.DOKill(true);
                failureMessageTransform.GetComponent <RectTransform>().DOPunchScale(new Vector3(0.125f, 0, 0), 0.25f, 2);
            }
        }
 public void LoadData()
 {
     if (Social.Active.localUser.authenticated)
     {
         isSaving = false;
         ((PlayGamesPlatform)Social.Active).SavedGame.OpenWithAutomaticConflictResolution(SAVE_NAME,
                                                                                          DataSource.ReadCacheOrNetwork, ConflictResolutionStrategy.UseLongestPlaytime, OnSavedGameOpened);
     }
     else
     {
         //local load
         LocalSaveSystem.LoadSplit(LocalSaveSystem.Load());
     }
 }
Exemplo n.º 17
0
        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" });
        }
Exemplo n.º 18
0
        private void IncreaseCoins(int coins)
        {
            var localData = LocalSaveSystem.LoadLocalData();

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

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

            StoreEventSystem.Instance.SuccessfulPurchase();
        }
        private void SelectCharacter()
        {
            effectToggle.onValueChanged.RemoveAllListeners();
            selectButton.onClick.RemoveAllListeners();

            failureMessage.gameObject.SetActive(false);
            selectButton.gameObject.SetActive(false);

            var localData = LocalSaveSystem.LoadLocalData();

            localData.Characters.First(c => c.Id == _gameData.SelectedCharacter.Id).IsSelected = false;
            _gameData.SelectedCharacter.IsSelected = false;
            localData.Characters.First(c => c.Id == _currentCharacter.Id).IsSelected = true;
            _currentCharacter.IsSelected = true;

            LocalSaveSystem.SaveLocalData(localData);

            effectToggle.onValueChanged.AddListener(ToggleCharacterEffect);

            CharactersPageEventSystem.Instance.ChangeSelectedCharacter(_currentCharacter);
        }
Exemplo n.º 20
0
        private void MultiplyCoins()
        {
            var multipliedCoins = _earnedCoins * CoinsMultiplayer;

            earnedCoinsLabel.text = multipliedCoins.ToString();

            var localData = LocalSaveSystem.LoadLocalData();

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

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

            multiplyCoinsButton.onClick.RemoveAllListeners();
            multiplyCoinsButton.gameObject.SetActive(false);
        }
    private void OnSavedGameDataRead(SavedGameRequestStatus status, byte[] savedData)
    {
        if (status == SavedGameRequestStatus.Success)
        {
            if (savedData != null)
            {
                string cloudDataString = Encoding.ASCII.GetString(savedData);

                if (cloudDataString != "")
                {
                    LocalSaveSystem.LoadSplit(savedData);
                    isCloudDataLoaded = true;
                }
                else
                {
                    LocalSaveSystem.LoadSplit(LocalSaveSystem.Load());
                }
            }
            else
            {
                LocalSaveSystem.LoadSplit(LocalSaveSystem.Load());
            }
        }
    }
Exemplo n.º 22
0
        private void SyncCloudWithLocal()
        {
            ActivateAccountPanels(new[] { "loader" });

            PlayGamesServices.LoadCloudData(cloudData =>
            {
                var localData = LocalSaveSystem.LoadLocalData();

                if (localData.SaveTime != cloudData.saveTime)
                {
                    localData.Synchronized = true;
                    localData.Characters   = cloudData.characters;
                    localData.Platforms    = cloudData.platforms;
                    localData.Environments = cloudData.environments;
                    localData.SaveTime     = cloudData.saveTime;
                    localData.HighScore    = cloudData.highScore;
                    localData.Coins        = cloudData.coins;

                    UpdateGameData(localData);
                }

                ActivateAccountPanels(new[] { "signed" });
            });
        }
Exemplo n.º 23
0
        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);
        }
 string GameDataToString() => LocalSaveSystem.SaveParse();
 public void CallSave()
 {
     LocalSaveSystem.LocalSave(LocalSaveSystem.SaveParse());
 }
Exemplo n.º 26
0
        private static IEnumerator InitializeLocalData()
        {
            yield return(null);

            LocalSaveSystem.InitializeDefaultData();
        }
Exemplo n.º 27
0
        private static IEnumerator LoadLocalData()
        {
            yield return(null);

            LoadGameData(LocalSaveSystem.LoadLocalData());
        }