예제 #1
0
        private static IEnumerator LoadSceneCoroutine(SavedGameData savedGameData, string spawnpointName)
        {
            if (savedGameData == null)
            {
                yield break;
            }
            if (debug)
            {
                Debug.Log("Save System: Loading scene " + savedGameData.sceneName +
                          (string.IsNullOrEmpty(spawnpointName) ? string.Empty : " [spawn at " + spawnpointName + "]"));
            }
            m_savedGameData = savedGameData;
            BeforeSceneChange();
            yield return(LoadSceneInternal(savedGameData.sceneName));

            ApplyDataImmediate();
            // Allow other scripts to spin up scene first:
            for (int i = 0; i < framesToWaitBeforeApplyData; i++)
            {
                yield return(null);
            }
            yield return(new WaitForEndOfFrame());

            m_playerSpawnpoint = !string.IsNullOrEmpty(spawnpointName) ? GameObject.Find(spawnpointName) : null;
            if (!string.IsNullOrEmpty(spawnpointName) && m_playerSpawnpoint == null)
            {
                Debug.LogWarning("Save System: Can't find spawnpoint '" + spawnpointName + "'. Is spelling and capitalization correct?");
            }
            ApplySavedGameData(savedGameData);
        }
        public void UpdateSavedGameInfoToFile(int slotNumber, SavedGameData savedGameData)
        {
            var slotIndex = slotNumber;

            for (int i = m_savedGameInfo.Count; i <= slotIndex; i++)
            {
                m_savedGameInfo.Add(new SavedGameInfo(string.Empty));
            }
            m_savedGameInfo[slotIndex].sceneName = (savedGameData != null) ? savedGameData.sceneName : string.Empty;
            var filename = GetSavedGameInfoFilename();

            if (debug)
            {
                Debug.Log("Save System: DiskSavedGameDataStorer updating " + filename);
            }
            try
            {
                using (StreamWriter streamWriter = new StreamWriter(filename))
                {
                    for (int i = 0; i < m_savedGameInfo.Count; i++)
                    {
                        streamWriter.WriteLine(m_savedGameInfo[i].sceneName.Replace("\n", "<cr>"));
                    }
                }
            }
            catch (System.Exception)
            {
                Debug.LogError("Save System: DiskSavedGameDataStorer - Can't create file: " + filename);
            }
        }
예제 #3
0
 /// <summary>
 /// Applies the saved game data to the savers in the current scene.
 /// </summary>
 /// <param name="savedGameData">Saved game data.</param>
 public static void ApplySavedGameData(SavedGameData savedGameData)
 {
     if (savedGameData == null)
     {
         return;
     }
     m_savedGameData = savedGameData;
     if (m_savers.Count <= 0)
     {
         return;
     }
     for (int i = m_savers.Count - 1; i >= 0; i--) // A saver may remove itself from list during apply.
     {
         try
         {
             if (0 <= i && i < m_savers.Count)
             {
                 var saver = m_savers[i];
                 if (saver != null)
                 {
                     saver.ApplyData(savedGameData.GetData(saver.key));
                 }
             }
         }
         catch (System.Exception e)
         {
             Debug.LogException(e);
         }
     }
     saveDataApplied();
 }
        public override void StoreSavedGameData(int slotNumber, SavedGameData savedGameData)
        {
            var s = SaveSystem.Serialize(savedGameData);

            if (debug)
            {
                Debug.Log("Save System: Storing in PlayerPrefs key " + GetPlayerPrefsKey(slotNumber) + ": " + s);
            }
            PlayerPrefs.SetString(GetPlayerPrefsKey(slotNumber), s);
        }
        public override void StoreSavedGameData(int slotNumber, SavedGameData savedGameData)
        {
            var s = SaveSystem.Serialize(savedGameData);

            if (debug)
            {
                Debug.Log("Save System: Storing in PlayerPrefs key " + GetPlayerPrefsKey(slotNumber) + ": " + s);
            }
            PlayerPrefs.SetString(GetPlayerPrefsKey(slotNumber), encrypt ? EncryptionUtility.Encrypt(s, encryptionPassword) : s);
            PlayerPrefs.Save();
        }
        public override void StoreSavedGameData(int slotNumber, SavedGameData savedGameData)
        {
            var s = SaveSystem.Serialize(savedGameData);

            if (debug)
            {
                Debug.Log("Save System: DiskSavedGameDataStorer - Saving " + GetSaveGameFilename(slotNumber) + ": " + s);
            }
            WriteStringToFile(GetSaveGameFilename(slotNumber), encrypt ? EncryptionUtility.Encrypt(s, encryptionPassword) : s);
            UpdateSavedGameInfoToFile(slotNumber, savedGameData);
        }
예제 #7
0
 /// <summary>
 /// Loads the scene recorded in the saved game data (if saveCurrentScene is true) and
 /// applies the saved game data to it.
 /// </summary>
 /// <param name="savedGameData"></param>
 public static void LoadGame(SavedGameData savedGameData)
 {
     if (saveCurrentScene)
     {
         instance.StartCoroutine(LoadSceneCoroutine(savedGameData, null));
     }
     else
     {
         ApplySavedGameData(savedGameData);
     }
 }
예제 #8
0
 static void InitStaticVariables()
 {
     m_instance               = null;
     m_savers                 = new List <Saver>();
     m_savedGameData          = new SavedGameData();
     m_serializer             = null;
     m_storer                 = null;
     m_sceneTransitionManager = null;
     m_playerSpawnpoint       = null;
     m_currentSceneIndex      = NoSceneIndex;
     m_addedScenes            = new List <string>();
     m_currentAsyncOperation  = null;
     m_isQuitting             = false;
 }
예제 #9
0
 public static void ApplySavedGameData(SavedGameData savedGameData)
 {
     for (int i = m_savers.Count - 1; i >= 0; i--) // A saver may remove itself from list during apply.
     {
         try
         {
             var saver = m_savers[i];
             saver.ApplyData(savedGameData.GetData(saver.key));
         }
         catch (System.Exception e)
         {
             Debug.LogException(e);
         }
     }
 }
예제 #10
0
 /// <summary>
 /// Loads the scene recorded in the saved game data (if saveCurrentScene is true) and
 /// applies the saved game data to it.
 /// </summary>
 /// <param name="savedGameData"></param>
 public static void LoadGame(SavedGameData savedGameData)
 {
     if (savedGameData == null)
     {
         if (Debug.isDebugBuild)
         {
             Debug.LogWarning("SaveSystem.LoadGame received null saved game data. Not loading.");
         }
     }
     else if (saveCurrentScene)
     {
         instance.StartCoroutine(LoadSceneCoroutine(savedGameData, null));
     }
     else
     {
         ApplySavedGameData(savedGameData);
     }
 }
예제 #11
0
        private static IEnumerator LoadSceneCoroutine(SavedGameData savedGameData, string spawnpointName)
        {
            if (savedGameData == null)
            {
                yield break;
            }
            if (debug)
            {
                Debug.Log("Save System: Loading scene " + savedGameData.sceneName +
                          (string.IsNullOrEmpty(spawnpointName) ? string.Empty : " [spawn at " + spawnpointName + "]"));
            }
            m_savedGameData = savedGameData;
            BeforeSceneChange();
            yield return(LoadSceneInternal(savedGameData.sceneName));

            yield return(null); // Need time to spin up scene first.

            m_playerSpawnpoint = !string.IsNullOrEmpty(spawnpointName) ? GameObject.Find(spawnpointName) : null;
            ApplySavedGameData(savedGameData);
        }
 /// <summary>
 /// Asynchronously store the saved game data in the specified slot. The base version of
 /// this method just calls the synchronous version, StoreSavedGameData(). If you override
 /// it, keep the progress property updated so any watchers will know how far along it is.
 /// </summary>
 public virtual IEnumerator StoreSavedGameDataAsync(int slotNumber, SavedGameData savedGameData)
 {
     StoreSavedGameData(slotNumber, savedGameData);
     progress = 1;
     yield break;
 }
예제 #13
0
 public static void LoadGame(SavedGameData savedGameData)
 {
     instance.StartCoroutine(LoadSceneCoroutine(savedGameData, null));
 }
예제 #14
0
 public override void StoreSavedGameData(int slotNumber, SavedGameData savedGameData)
 {
     Debug.LogError("DiskSavedGameDataStorer is not supported on this build platform.");
 }
예제 #15
0
 public static void ClearSavedGameData()
 {
     m_savedGameData = new SavedGameData();
 }
 public abstract void StoreSavedGameData(int slotNumber, SavedGameData savedGameData);
 public override void StoreSavedGameData(int slotNumber, SavedGameData savedGameData)
 {
     Debug.LogError("DiskSavedGameDataStorer is currently only supported in Standalone (desktop) builds.");
 }