示例#1
0
 void AdvanceSet()
 {
     if (currentSpawnSet == SpawnerData.GetSetCount() - 1)
     {
         return;
     }
     currentSpawnSet++;
     SpawnerData.GetNextSpawnData(currentSpawnSet);
     dataUpdated.Invoke();
     Debug.Log("Set updated");
 }
        private void CloudDataWasReadCallback(SavedGameRequestStatus status, byte[] data)
        {
            if (status == SavedGameRequestStatus.Success)
            {
                GameData loadedGameData;
                var      jsonString = Encoding.ASCII.GetString(data);

                try
                {
                    loadedGameData = JsonUtility.FromJson <GameData>(jsonString);
                    loadedGameData.NormalizeData();
                }
                catch
                {
                    loadedGameData = new GameData();
                }

                if (loadedGameData.dataVersion == GameData.DataVersionReference &&
                    (loadedGameData.gameProgress > GameData.gameProgress ||
                     loadedGameData.gameProgress == GameData.gameProgress && loadedGameData.SaveDate > GameData.SaveDate))
                {
                    _resolvingGameData = loadedGameData;
                    OnGameDataUpdated?.Invoke(this, new GameDataUpdatedEventArgs(true));
                    UpdateCloudStatus(CloudStatus.CloudUpdated);
                }
                else
                {
                    UpdateCloudStatus(CloudStatus.CloudUpdated);
                    OpenCloud(CloudAction.Saving);
                }
            }
            else
            {
                UpdateCloudStatus(CloudStatus.CloudDisconnected);
            }
        }
        public void LoadLocalData()
        {
            UpdateCloudStatus(CloudStatus.CloudDisconnected);

            if (File.Exists(_gameDataPath))
            {
                using (var streamReader = File.OpenText(_gameDataPath))
                {
                    var jsonString = streamReader.ReadToEnd();

                    try
                    {
                        var loadedGameData = JsonUtility.FromJson <GameData>(jsonString);
                        if (loadedGameData.dataVersion != GameData.DataVersionReference)
                        {
                            GameData = new GameData();
                        }
                        else
                        {
                            GameData = loadedGameData;
                            GameData.NormalizeData();
                        }
                    }
                    catch
                    {
                        GameData = new GameData();
                    }
                }
            }
            else
            {
                GameData = new GameData();
            }

            OnGameDataUpdated?.Invoke(this, new GameDataUpdatedEventArgs(false));
        }
 public void GameDataUpdated()
 {
     OnGameDataUpdated?.Invoke();
 }