Browse Source

Added autosave option (off by default).

master
Christopher 8 years ago
parent
commit
d11df62faf
  1. 37
      Assets/Fungus/Scripts/Components/SaveMenu.cs

37
Assets/Fungus/Scripts/Components/SaveMenu.cs

@ -12,6 +12,9 @@ namespace Fungus
[Tooltip("Automatically load the most recently saved game on startup")]
[SerializeField] protected bool loadOnStart = true;
[Tooltip("Automatically save game to disk after each Save Point command executes. This also disables the Save and Load menu buttons.")]
[SerializeField] protected bool autoSave = false;
[Tooltip("Delete the save game data from disk when player restarts the game. Useful for testing, but best switched off for release builds.")]
[SerializeField] protected bool restartDeletesSave = false;
@ -91,6 +94,17 @@ namespace Fungus
{
var saveManager = FungusManager.Instance.SaveManager;
// Hide the Save and Load buttons if autosave is on
bool showSaveAndLoad = !autoSave;
if (saveButton.IsActive() != showSaveAndLoad)
{
saveButton.gameObject.SetActive(showSaveAndLoad);
loadButton.gameObject.SetActive(showSaveAndLoad);
}
if (showSaveAndLoad)
{
if (saveButton != null)
{
// Don't allow saving unless there's at least one save point in the history,
@ -101,6 +115,8 @@ namespace Fungus
{
loadButton.interactable = saveManager.SaveDataExists();
}
}
if (rewindButton != null)
{
rewindButton.interactable = saveManager.NumSavePoints > 0;
@ -120,6 +136,27 @@ namespace Fungus
}
}
protected virtual void OnEnable()
{
SaveManagerSignals.OnSavePointAdded += OnSavePointAdded;
}
protected virtual void OnDisable()
{
SaveManagerSignals.OnSavePointAdded -= OnSavePointAdded;
}
protected virtual void OnSavePointAdded(string savePointKey, string savePointDescription)
{
var saveManager = FungusManager.Instance.SaveManager;
if (autoSave &&
saveManager.NumSavePoints > 0)
{
saveManager.Save();
}
}
protected void PlayClickSound()
{
if (clickAudioSource != null)

Loading…
Cancel
Save