Browse Source

Added SavePicker dialog

master
Christopher 8 years ago
parent
commit
5c7ca33cd0
  1. 12
      Assets/Fungus/Scripts/Components/GameSaver.cs
  2. 9
      Assets/Fungus/Scripts/Components/SaveManager.cs
  3. 24
      Assets/Fungus/Scripts/EventHandlers/SavePointLoaded.cs
  4. 13
      Assets/Fungus/Scripts/SavePoints/SavePointData.cs
  5. 956
      Assets/FungusExamples/SaveGame/Menu.unity
  6. 24
      Assets/FungusExamples/SaveGame/SavePicker.cs
  7. 12
      Assets/FungusExamples/SaveGame/SavePicker.cs.meta

12
Assets/Fungus/Scripts/Components/GameSaver.cs

@ -15,24 +15,12 @@ namespace Fungus
public List<Flowchart> Flowcharts { get { return flowcharts; } } public List<Flowchart> Flowcharts { get { return flowcharts; } }
public virtual void Load(int slot)
{
var saveManager = FungusManager.Instance.SaveManager;
saveManager.Load(slot, startScene);
}
public virtual void Save() public virtual void Save()
{ {
var saveManager = FungusManager.Instance.SaveManager; var saveManager = FungusManager.Instance.SaveManager;
saveManager.Save(); saveManager.Save();
} }
public virtual void Delete(int slot)
{
var saveManager = FungusManager.Instance.SaveManager;
saveManager.Delete(slot);
}
public virtual void LoadScene(string sceneName) public virtual void LoadScene(string sceneName)
{ {
SceneManager.LoadScene(sceneName); SceneManager.LoadScene(sceneName);

9
Assets/Fungus/Scripts/Components/SaveManager.cs

@ -16,7 +16,7 @@ namespace Fungus
return string.Format(SlotKeyFormat, slot); return string.Format(SlotKeyFormat, slot);
} }
protected virtual bool LoadNewGame(string key, string startScene) protected virtual bool LoadNewGame(string key)
{ {
if (PlayerPrefs.HasKey(key) && if (PlayerPrefs.HasKey(key) &&
PlayerPrefs.GetString(key) != "") PlayerPrefs.GetString(key) != "")
@ -27,8 +27,7 @@ namespace Fungus
// Create a new save entry // Create a new save entry
PlayerPrefs.SetString(key, ""); PlayerPrefs.SetString(key, "");
// Load the start scene SavePointLoaded.NotifyEventHandlers("new_game");
SceneManager.LoadScene(startScene);
return true; return true;
} }
@ -80,13 +79,13 @@ namespace Fungus
saveBuffer = ""; saveBuffer = "";
} }
public virtual void Load(int slot, string startScene = "") public virtual void Load(int slot)
{ {
ActiveSlot = slot; ActiveSlot = slot;
var key = FormatSaveKey(slot); var key = FormatSaveKey(slot);
if (LoadNewGame(key, startScene)) if (LoadNewGame(key))
{ {
return; return;
} }

24
Assets/Fungus/Scripts/EventHandlers/SavePointLoaded.cs

@ -11,19 +11,27 @@ namespace Fungus
"Execute this block when a saved point is loaded.")] "Execute this block when a saved point is loaded.")]
public class SavePointLoaded : EventHandler public class SavePointLoaded : EventHandler
{ {
[Tooltip("Block will execute if the Save Key of the loaded save point matches an entry in the Save Keys list.")] [Tooltip("Block will execute if the Save Key of the loaded save point matches this save key.")]
[SerializeField] protected List<string> saveKeys = new List<string>(); [SerializeField] protected string saveKey = "";
protected void OnSavePointLoaded(string _saveKey)
{
if (string.Compare(saveKey, _saveKey, true) == 0)
{
ExecuteBlock();
}
}
#region Public methods #region Public methods
/// <summary> public static void NotifyEventHandlers(string _saveKey)
/// Called when a save point is loaded.
/// </summary>
public void OnSavePointLoaded(string saveKey)
{ {
if (saveKeys.Contains(saveKey)) // Fire any matching SavePointLoaded event handler with matching save key.
var eventHandlers = Object.FindObjectsOfType<SavePointLoaded>();
for (int i = 0; i < eventHandlers.Length; i++)
{ {
ExecuteBlock(); var eventHandler = eventHandlers[i];
eventHandler.OnSavePointLoaded(_saveKey);
} }
} }

13
Assets/Fungus/Scripts/SavePoints/SavePointData.cs

@ -36,22 +36,11 @@ namespace Fungus
FlowchartData.Decode(flowchartData); FlowchartData.Decode(flowchartData);
} }
NotifyEventHandlers(savePointData); SavePointLoaded.NotifyEventHandlers(savePointData.saveKey);
ExecuteBlocks(savePointData); ExecuteBlocks(savePointData);
} }
protected static void NotifyEventHandlers(SavePointData savePointData)
{
// Fire any matching SavePointLoaded event handler with matching save key.
var eventHandlers = Object.FindObjectsOfType<SavePointLoaded>();
for (int i = 0; i < eventHandlers.Length; i++)
{
var eventHandler = eventHandlers[i];
eventHandler.OnSavePointLoaded(savePointData.SaveKey);
}
}
protected static void ExecuteBlocks(SavePointData savePointData) protected static void ExecuteBlocks(SavePointData savePointData)
{ {
// Execute any block containing a Label matching the save key // Execute any block containing a Label matching the save key

956
Assets/FungusExamples/SaveGame/Menu.unity

File diff suppressed because it is too large Load Diff

24
Assets/FungusExamples/SaveGame/SavePicker.cs

@ -0,0 +1,24 @@
using UnityEngine;
using System.Collections;
namespace Fungus
{
public class SavePicker : MonoBehaviour
{
#region Public methods
public virtual void Select(int slot)
{
var saveManager = FungusManager.Instance.SaveManager;
saveManager.Load(slot);
}
public virtual void Delete(int slot)
{
var saveManager = FungusManager.Instance.SaveManager;
saveManager.Delete(slot);
}
#endregion
}
}

12
Assets/FungusExamples/SaveGame/SavePicker.cs.meta

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 60a19f3f0e9b84b14b2b310a296de1b1
timeCreated: 1479485750
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Loading…
Cancel
Save