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; } }
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()); } } }
public void SaveMusicVolumeChanges() { var data = LocalSaveSystem.LoadLocalData(); data.Settings.MusicVolume = musicSlider.value; LocalSaveSystem.SaveLocalData(data); }
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); }
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); } }
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 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()); } }
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 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); }
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()); } } }
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" }); }); }
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()); }
private static IEnumerator InitializeLocalData() { yield return(null); LocalSaveSystem.InitializeDefaultData(); }
private static IEnumerator LoadLocalData() { yield return(null); LoadGameData(LocalSaveSystem.LoadLocalData()); }