diff --git a/Assets/Fungus/Scripts/Commands/SavePoint.cs b/Assets/Fungus/Scripts/Commands/SavePoint.cs index bb9c67da..b1ce72e1 100644 --- a/Assets/Fungus/Scripts/Commands/SavePoint.cs +++ b/Assets/Fungus/Scripts/Commands/SavePoint.cs @@ -12,7 +12,7 @@ namespace Fungus "Creates a save point which can be saved to persistant storage and loaded again later.")] public class SavePoint : Command { - [SerializeField] protected Block resumeBlock; + [SerializeField] protected string saveKey; [SerializeField] protected bool saveNow; @@ -22,7 +22,7 @@ namespace Fungus { var saveManager = FungusManager.Instance.SaveManager; - saveManager.PopulateSaveBuffer(GetFlowchart(), resumeBlock.BlockName); + saveManager.PopulateSaveBuffer(GetFlowchart(), saveKey); if (saveNow) { @@ -34,12 +34,7 @@ namespace Fungus public override string GetSummary() { - if (resumeBlock == null) - { - return "Error: No resume block set"; - } - - return resumeBlock.BlockName; + return saveKey; } public override Color GetButtonColor() @@ -47,14 +42,6 @@ namespace Fungus return new Color32(235, 191, 217, 255); } - public override void GetConnectedBlocks(ref List connectedBlocks) - { - if (resumeBlock != null) - { - connectedBlocks.Add(resumeBlock); - } - } - #endregion } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Components/Flowchart.cs b/Assets/Fungus/Scripts/Components/Flowchart.cs index 4ebdd2b7..a61f40f5 100644 --- a/Assets/Fungus/Scripts/Components/Flowchart.cs +++ b/Assets/Fungus/Scripts/Components/Flowchart.cs @@ -3,7 +3,6 @@ using UnityEngine; using UnityEngine.EventSystems; -using UnityEngine.Serialization; using System; using System.Text; using System.Linq; diff --git a/Assets/Fungus/Scripts/Components/SaveManager.cs b/Assets/Fungus/Scripts/Components/SaveManager.cs index 6f9da2e9..c4354849 100644 --- a/Assets/Fungus/Scripts/Components/SaveManager.cs +++ b/Assets/Fungus/Scripts/Components/SaveManager.cs @@ -55,14 +55,14 @@ namespace Fungus return true; } - protected virtual string CreateSaveData(Flowchart flowchart, string resumeBlockName) + protected virtual string CreateSaveData(Flowchart flowchart, string saveKey) { var saveData = new SavePointData(); // Store the scene, flowchart and block to execute on resume saveData.sceneName = SceneManager.GetActiveScene().name; saveData.flowchartName = flowchart.name; - saveData.resumeBlockName = resumeBlockName; + saveData.saveKey = saveKey; for (int i = 0; i < flowchart.Variables.Count; i++) { @@ -147,7 +147,27 @@ namespace Fungus flowchart.SetStringVariable(stringVar.key, stringVar.value); } - flowchart.ExecuteBlock(saveData.resumeBlockName); + // Fire any matching GameLoaded event handler with matching save key. + var eventHandlers = Object.FindObjectsOfType(); + for (int i = 0; i < eventHandlers.Length; i++) + { + var eventHandler = eventHandlers[i]; + eventHandler.OnGameLoaded(saveData.saveKey); + } + + // Execute any block with a Label matching the save key + var labels = Object.FindObjectsOfType