/// <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();
                }
            }
        }
예제 #2
0
        private IEnumerator LoadLevelCoroutine(string levelName, int levelIndex)
        {
            PersistentDataManager.Record();

            // Load the level:
            PersistentDataManager.LevelWillBeUnloaded();
            if (CanLoadAsync())
            {
                AsyncOperation async = !string.IsNullOrEmpty(levelName) ? Tools.LoadLevelAsync(levelName) : Tools.LoadLevelAsync(levelIndex);
                isLoading = true;
                while (!async.isDone)
                {
                    yield return(null);
                }
                isLoading = false;
            }
            else
            {
                if (!string.IsNullOrEmpty(levelName))
                {
                    Tools.LoadLevel(levelName);
                }
                else
                {
                    Tools.LoadLevel(levelIndex);
                }
            }

            // Wait two frames for objects in the level to finish their Start() methods:
            yield return(null);

            yield return(null);

            // Apply position data, but don't apply player's position:
            var player        = GameObject.FindGameObjectWithTag("Player");
            var persistentPos = (player != null) ? player.GetComponent <PersistentPositionData>() : null;
            var originalValue = false;

            if (persistentPos != null)
            {
                originalValue = persistentPos.restoreCurrentLevelPosition;
                persistentPos.restoreCurrentLevelPosition = false;
            }

            PersistentDataManager.Apply();
            if (persistentPos != null)
            {
                persistentPos.restoreCurrentLevelPosition = originalValue;
            }

            // Update quest tracker HUD:
            DialogueManager.SendUpdateTracker();
        }
예제 #3
0
        /// <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();
            }
        }
예제 #4
0
        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();
        }