protected virtual void OnDisable()
 {
     PersistentDataManager.UnregisterPersistentData(this.gameObject);
 }
 protected virtual void OnEnable()
 {
     PersistentDataManager.RegisterPersistentData(gameObject);
 }
        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();
        }
Beispiel #4
0
 /// <summary>
 /// Only listen for OnDestroy if the script has been enabled.
 /// </summary>
 public void OnEnable()
 {
     listenForOnDestroy = true;
     PersistentDataManager.RegisterPersistentData(gameObject);
 }
Beispiel #5
0
 public override void OnBeforeSceneChange()
 {
     PersistentDataManager.LevelWillBeUnloaded();
 }
Beispiel #6
0
 /// <summary>
 /// Applies the recorded state of the game to the current scene.
 /// </summary>
 public void Apply()
 {
     PersistentDataManager.Apply();
 }
 /// <summary>
 /// Only listen for OnDestroy if the script has been enabled.
 /// </summary>
 protected virtual void OnEnable()
 {
     PersistentDataManager.RegisterPersistentData(gameObject);
     listenForOnDestroy = true;
 }
Beispiel #8
0
 /// <summary>
 /// Records the state of the game.
 /// </summary>
 public void Record()
 {
     PersistentDataManager.Record();
 }
Beispiel #9
0
 public override void ApplyData(string data)
 {
     PersistentDataManager.ApplySaveData(data);
 }
Beispiel #10
0
 public override string RecordData()
 {
     return(PersistentDataManager.GetSaveData());
 }
 public override void OnDisable()
 {
     base.OnDisable();
     SceneManager.sceneLoaded -= RecordCurrentScene;
     PersistentDataManager.UnregisterPersistentData(gameObject);
 }
Beispiel #12
0
 /// <summary>
 /// Only listen for OnDestroy if the script has been enabled.
 /// </summary>
 public void OnEnable()
 {
     listenForOnDestroy = !awakeMarkedForDestroy;
     PersistentDataManager.RegisterPersistentData(gameObject);
 }