diff --git a/Assets/Fungus/Scripts/Components/SaveManager.cs b/Assets/Fungus/Scripts/Components/SaveManager.cs
index 17b91c61..5ae5b3a7 100644
--- a/Assets/Fungus/Scripts/Components/SaveManager.cs
+++ b/Assets/Fungus/Scripts/Components/SaveManager.cs
@@ -169,11 +169,6 @@ namespace Fungus
#region Public members
- ///
- /// The default key used for storing save game data in PlayerPrefs.
- ///
- public const string DefaultSaveDataKey = "save_data";
-
///
/// The scene that should be loaded when restarting a game.
///
@@ -192,7 +187,7 @@ namespace Fungus
///
/// Writes the Save History to persistent storage.
///
- public virtual void Save(string saveDataKey = DefaultSaveDataKey)
+ public virtual void Save(string saveDataKey)
{
WriteSaveHistory(saveDataKey);
}
@@ -200,7 +195,7 @@ namespace Fungus
///
/// Loads the Save History from persistent storage and loads the latest Save Point.
///
- public void Load(string saveDataKey = DefaultSaveDataKey)
+ public void Load(string saveDataKey)
{
// Set a load action to be executed on next update
var key = saveDataKey;
@@ -210,7 +205,7 @@ namespace Fungus
///
/// Deletes a previously stored Save History from persistent storage.
///
- public void Delete(string saveDataKey = DefaultSaveDataKey)
+ public void Delete(string saveDataKey)
{
PlayerPrefs.DeleteKey(saveDataKey);
PlayerPrefs.Save();
@@ -219,7 +214,7 @@ namespace Fungus
///
/// Returns true if save data has previously been stored using this key.
///
- public bool SaveDataExists(string saveDataKey = DefaultSaveDataKey)
+ public bool SaveDataExists(string saveDataKey)
{
return PlayerPrefs.HasKey(saveDataKey);
}
diff --git a/Assets/Fungus/Scripts/Components/SaveMenu.cs b/Assets/Fungus/Scripts/Components/SaveMenu.cs
index 2640ba18..353458d8 100644
--- a/Assets/Fungus/Scripts/Components/SaveMenu.cs
+++ b/Assets/Fungus/Scripts/Components/SaveMenu.cs
@@ -14,6 +14,9 @@ namespace Fungus
///
public class SaveMenu : MonoBehaviour
{
+ [Tooltip("String key used when storing save game data in PlayerPrefs.")]
+ [SerializeField] protected string saveDataKey = FungusConstants.DefaultSaveDataKey;
+
[Tooltip("Automatically load the most recently saved game on startup")]
[SerializeField] protected bool loadOnStart = true;
@@ -88,9 +91,9 @@ namespace Fungus
if (loadOnStart)
{
- if (saveManager.SaveDataExists())
+ if (saveManager.SaveDataExists(saveDataKey))
{
- saveManager.Load();
+ saveManager.Load(saveDataKey);
}
}
}
@@ -118,7 +121,7 @@ namespace Fungus
}
if (loadButton != null)
{
- loadButton.interactable = saveManager.SaveDataExists();
+ loadButton.interactable = saveManager.SaveDataExists(saveDataKey);
}
}
@@ -158,7 +161,7 @@ namespace Fungus
if (autoSave &&
saveManager.NumSavePoints > 0)
{
- saveManager.Save();
+ saveManager.Save(saveDataKey);
}
}
@@ -216,7 +219,7 @@ namespace Fungus
if (saveManager.NumSavePoints > 0)
{
PlayClickSound();
- saveManager.Save();
+ saveManager.Save(saveDataKey);
}
}
@@ -227,10 +230,10 @@ namespace Fungus
{
var saveManager = FungusManager.Instance.SaveManager;
- if (saveManager.SaveDataExists())
+ if (saveManager.SaveDataExists(saveDataKey))
{
PlayClickSound();
- saveManager.Load();
+ saveManager.Load(saveDataKey);
}
}
@@ -281,7 +284,7 @@ namespace Fungus
saveManager.ClearHistory();
if (restartDeletesSave)
{
- saveManager.Delete();
+ saveManager.Delete(saveDataKey);
}
SceneManager.LoadScene(saveManager.StartScene);
diff --git a/Assets/Fungus/Scripts/Utils/FungusConstants.cs b/Assets/Fungus/Scripts/Utils/FungusConstants.cs
index f7276c9d..4676b4b4 100644
--- a/Assets/Fungus/Scripts/Utils/FungusConstants.cs
+++ b/Assets/Fungus/Scripts/Utils/FungusConstants.cs
@@ -42,6 +42,11 @@ namespace Fungus
///
public static Color DefaultProcessBlockTint = new Color(1.0f, 0.882f, 0.0f, 1.0f);
+ ///
+ /// The default key used for storing save game data in PlayerPrefs.
+ ///
+ public const string DefaultSaveDataKey = "save_data";
+
#endregion
}
}
\ No newline at end of file
diff --git a/Assets/FungusExamples/SaveGame/SaveGame.unity b/Assets/FungusExamples/SaveGame/SaveGame.unity
index f2981ac7..73b72e39 100644
--- a/Assets/FungusExamples/SaveGame/SaveGame.unity
+++ b/Assets/FungusExamples/SaveGame/SaveGame.unity
@@ -2034,7 +2034,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: abe25ebf9ddc8416ead6f30d4671fdbf, type: 3}
m_Name:
m_EditorClassIdentifier:
+ saveDataKey: save_example_data
loadOnStart: 1
+ autoSave: 0
restartDeletesSave: 0
saveMenuGroup: {fileID: 178630601}
saveMenuButton: {fileID: 1058705593}