Save manager signalling system. You can use this to be notified about various events in the save game system.
コード例 #1
0
        /// <summary>
        /// Decodes a Save Point from JSON text format and loads it.
        /// </summary>
        public static void Decode(string saveDataJSON)
        {
            var savePointData = JsonUtility.FromJson <SavePointData>(saveDataJSON);

            UnityAction <Scene, LoadSceneMode> onSceneLoadedAction = null;

            onSceneLoadedAction = (scene, mode) => {
                // Additive scene loads and non-matching scene loads could happen if the client is using the
                // SceneManager directly. We just ignore these events and hope they know what they're doing!
                if (mode == LoadSceneMode.Additive ||
                    scene.name != savePointData.SceneName)
                {
                    return;
                }

                SceneManager.sceneLoaded -= onSceneLoadedAction;

                // Look for a SaveData component in the scene to process the save data items.
                var saveData = GameObject.FindObjectOfType <SaveData>();
                if (saveData != null)
                {
                    saveData.Decode(savePointData.SaveDataItems);
                }

                SaveManagerSignals.DoSavePointLoaded(savePointData.savePointKey);
            };

            SceneManager.sceneLoaded += onSceneLoadedAction;
            SceneManager.LoadScene(savePointData.SceneName);
        }
コード例 #2
0
        /// <summary>
        /// Handler function called when the Restart button is pressed.
        /// </summary>
        public virtual void Restart()
        {
            var saveManager = FungusManager.Instance.SaveManager;

            if (string.IsNullOrEmpty(saveManager.StartScene))
            {
                Debug.LogError("No start scene specified");
                return;
            }

            PlayClickSound();

            // Reset the Save History for a new game
            saveManager.ClearHistory();

            if (restartDeletesSave)
            {
                SaveManager.Delete(saveDataKey);
            }
            SaveManagerSignals.DoSaveReset();
            SceneManager.LoadScene(saveManager.StartScene);
        }
コード例 #3
0
        /// <summary>
        /// Creates a new Save Point using a key and description, and adds it to the Save History.
        /// </summary>
        public virtual void AddSavePoint(string savePointKey, string savePointDescription)
        {
            saveHistory.AddSavePoint(savePointKey, savePointDescription);

            SaveManagerSignals.DoSavePointAdded(savePointKey, savePointDescription);
        }