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 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); } }
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 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 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); }