public override void ApplyData(string data) { if (saveRawData) { var rawData = SaveSystem.Deserialize <RawData>(data); if (rawData != null && rawData.bytes != null) { PersistentDataManager.ApplyRawData(rawData.bytes); } } else { PersistentDataManager.ApplySaveData(data); } }
private IEnumerator LoadLevel(string saveData) { string levelName = defaultStartingLevel; if (string.IsNullOrEmpty(saveData)) { // If no saveData, reset the database. DialogueManager.ResetDatabase(DatabaseResetOptions.RevertToDefault); } else { // Put saveData in Lua so we can get Variable["SavedLevelName"]: Lua.Run(saveData, true); levelName = DialogueLua.GetVariable("SavedLevelName").AsString; if (string.IsNullOrEmpty(levelName)) { levelName = defaultStartingLevel; } } // Load the level: PersistentDataManager.LevelWillBeUnloaded(); if (Application.HasProLicense()) { AsyncOperation async = Application.LoadLevelAsync(levelName); IsLoading = true; while (!async.isDone) { yield return(null); } IsLoading = false; } else { Application.LoadLevel(levelName); } // Wait two frames for objects in the level to finish their Start() methods: yield return(null); yield return(null); // Then apply saveData to the objects: if (!string.IsNullOrEmpty(saveData)) { PersistentDataManager.ApplySaveData(saveData); } }
/// <summary> /// Loads the game from the data saved under the PlayerPrefs key. /// </summary> public void LoadGame(int slot) { if (SaveSystem.instance != null) { SaveSystem.LoadFromSlot(slot); } else { if (string.IsNullOrEmpty(playerPrefsKey)) { if (DialogueDebug.logWarnings) { Debug.LogWarning(string.Format("{0}: PlayerPrefs Key isn't set. Not loading.", new System.Object[] { DialogueDebug.Prefix })); } return; } string key = playerPrefsKey + slot.ToString(); if (!PlayerPrefs.HasKey(key)) { if (DialogueDebug.logWarnings) { Debug.LogWarning(string.Format("{0}: No saved game in PlayerPrefs key '{1}'. Not loading.", new System.Object[] { DialogueDebug.Prefix, key })); } return; } if (DialogueDebug.logInfo) { Debug.Log(string.Format("{0}: Loading save data from slot {1} and applying it.", new System.Object[] { DialogueDebug.Prefix, slot })); } // Load using the LevelManager if available; otherwise just apply saved-game data: string saveData = PlayerPrefs.GetString(key); LevelManager levelManager = FindLevelManager(); if (levelManager != null) { levelManager.LoadGame(saveData); } else { PersistentDataManager.ApplySaveData(saveData, DatabaseResetOptions.KeepAllLoaded); DialogueManager.SendUpdateTracker(); // Update quest tracker HUD. } } }
public override void ApplyData(string data) { if (m_appliedImmediate) { m_appliedImmediate = false; if (skipApplyDataAfterFramesIfApplyImmediate) { PersistentDataManager.Apply(); return; } } if (saveRawData) { var rawData = SaveSystem.Deserialize <RawData>(data); if (rawData != null && rawData.bytes != null) { PersistentDataManager.ApplyRawData(rawData.bytes); } } else { PersistentDataManager.ApplySaveData(data); } }
private IEnumerator LoadLevelFromSaveData(string saveData) { if (DialogueDebug.logInfo) { Debug.Log("Dialogue System: LevelManager: Starting LoadLevelFromSaveData coroutine"); } string levelName = defaultStartingLevel; if (string.IsNullOrEmpty(saveData)) { // If no saveData, reset the database. if (DialogueDebug.logInfo) { Debug.Log("Dialogue System: LevelManager: Save data is empty, so just resetting database"); } DialogueManager.ResetDatabase(DatabaseResetOptions.RevertToDefault); } else { // Put saveData in Lua so we can get Variable["SavedLevelName"]: if (DialogueDebug.logInfo) { Debug.Log("Dialogue System: LevelManager: Applying save data to get value of 'SavedLevelName' variable"); } Lua.Run(saveData, DialogueDebug.logInfo); levelName = DialogueLua.GetVariable("SavedLevelName").asString; if (string.IsNullOrEmpty(levelName) || string.Equals(levelName, "nil")) { levelName = defaultStartingLevel; if (DialogueDebug.logInfo) { Debug.Log("Dialogue System: LevelManager: 'SavedLevelName' isn't defined. Using default level " + levelName); } } else { if (DialogueDebug.logInfo) { Debug.Log("Dialogue System: LevelManager: SavedLevelName = " + levelName); } } } // Load the level: PersistentDataManager.LevelWillBeUnloaded(); if (CanLoadAsync()) { AsyncOperation async = Tools.LoadLevelAsync(levelName); isLoading = true; while (!async.isDone) { yield return(null); } isLoading = false; } else { Tools.LoadLevel(levelName); } // Wait two frames for objects in the level to finish their Start() methods: if (DialogueDebug.logInfo) { Debug.Log("Dialogue System: LevelManager finished loading level " + levelName + ". Waiting 2 frames for scene objects to start."); } yield return(null); yield return(null); // Then apply saveData to the objects: if (!string.IsNullOrEmpty(saveData)) { if (DialogueDebug.logInfo) { Debug.Log("Dialogue System: LevelManager waited 2 frames. Appling save data: " + saveData); } PersistentDataManager.ApplySaveData(saveData); } // Update quest tracker HUD: DialogueManager.SendUpdateTracker(); }
public override void ApplyData(string data) { PersistentDataManager.ApplySaveData(data); }