/// <summary> /// Restarts the game. /// </summary> public void RestartGame() { LevelManager levelManager = FindLevelManager(); if (SaveSystem.instance != null) { var startingSceneName = (levelManager != null && !string.IsNullOrEmpty(levelManager.defaultStartingLevel)) ? levelManager.defaultStartingLevel : startingLevel; SaveSystem.RestartGame(startingSceneName); } else { if (levelManager != null) { levelManager.RestartGame(); } else { DialogueManager.ResetDatabase(DatabaseResetOptions.RevertToDefault); if (string.IsNullOrEmpty(startingLevel)) { Tools.LoadLevel(0); } else { Tools.LoadLevel(startingLevel); } // Update quest tracker HUD: DialogueManager.SendUpdateTracker(); } } }
/// <summary> /// Loads a saved game by applying a saved-game string. /// </summary> /// <param name='saveData'> /// A saved-game string previously returned by GetSaveData(). /// </param> /// <param name='databaseResetOptions'> /// Database reset options. /// </param> public static void ApplySaveData(string saveData, DatabaseResetOptions databaseResetOptions = DatabaseResetOptions.KeepAllLoaded) { if (DialogueDebug.LogInfo) { Debug.Log(string.Format("{0}: Resetting Lua environment.", new System.Object[] { DialogueDebug.Prefix })); } DialogueManager.ResetDatabase(databaseResetOptions); if (DialogueDebug.LogInfo) { Debug.Log(string.Format("{0}: Updating Lua environment with saved data.", new System.Object[] { DialogueDebug.Prefix })); } Lua.Run(saveData, DialogueDebug.LogInfo); RefreshRelationshipAndStatusTablesFromLua(); Apply(); }
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> /// Restarts the game. /// </summary> public void RestartGame() { LevelManager levelManager = GetComponentInChildren <LevelManager>(); if (levelManager != null) { levelManager.RestartGame(); } else { DialogueManager.ResetDatabase(DatabaseResetOptions.RevertToDefault); if (string.IsNullOrEmpty(startingLevel)) { Application.LoadLevel(0); } else { Application.LoadLevel(startingLevel); } } }
/// <summary> /// Restarts the game. /// </summary> public void RestartGame() { LevelManager levelManager = FindLevelManager(); if (levelManager != null) { levelManager.RestartGame(); } else { DialogueManager.ResetDatabase(DatabaseResetOptions.RevertToDefault); if (string.IsNullOrEmpty(startingLevel)) { Tools.LoadLevel(0); } else { Tools.LoadLevel(startingLevel); } // Update quest tracker HUD: DialogueManager.SendUpdateTracker(); } }
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 OnRestartGame() { DialogueManager.ResetDatabase(); }
/// <summary> /// Resets the Lua environment -- for example, when starting a new game. /// </summary> /// <param name='databaseResetOptions'> /// The database reset options can be: /// /// - RevertToDefault: Removes all but the default database, then resets it. /// - KeepAllLoaded: Keeps all loaded databases in memory and just resets them. /// </param> public static void Reset(DatabaseResetOptions databaseResetOptions) { DialogueManager.ResetDatabase(databaseResetOptions); }