|
|
@ -8,6 +8,8 @@ namespace Fungus |
|
|
|
{ |
|
|
|
{ |
|
|
|
public class SaveGameHelper : MonoBehaviour |
|
|
|
public class SaveGameHelper : MonoBehaviour |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
const string SaveDataKey = "save_data"; |
|
|
|
|
|
|
|
|
|
|
|
const string NewGameSavePointKey = "new_game"; |
|
|
|
const string NewGameSavePointKey = "new_game"; |
|
|
|
|
|
|
|
|
|
|
|
[SerializeField] protected string startScene = ""; |
|
|
|
[SerializeField] protected string startScene = ""; |
|
|
@ -16,7 +18,13 @@ namespace Fungus |
|
|
|
|
|
|
|
|
|
|
|
[SerializeField] protected bool restartDeletesSave = false; |
|
|
|
[SerializeField] protected bool restartDeletesSave = false; |
|
|
|
|
|
|
|
|
|
|
|
[SerializeField] protected AudioClip buttonClickClip; |
|
|
|
[SerializeField] protected Button saveButton; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[SerializeField] protected Button loadButton; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[SerializeField] protected Button rewindButton; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[SerializeField] protected Button restartButton; |
|
|
|
|
|
|
|
|
|
|
|
[SerializeField] protected SaveGameObjects saveGameObjects = new SaveGameObjects(); |
|
|
|
[SerializeField] protected SaveGameObjects saveGameObjects = new SaveGameObjects(); |
|
|
|
|
|
|
|
|
|
|
@ -40,6 +48,26 @@ namespace Fungus |
|
|
|
CheckSavePointKeys(); |
|
|
|
CheckSavePointKeys(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void Update() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var saveManager = FungusManager.Instance.SaveManager; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (saveButton != null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Don't allow saving unless there's at least one save point in the history, |
|
|
|
|
|
|
|
// This avoids the case where you could try to load a save data with 0 save points. |
|
|
|
|
|
|
|
saveButton.interactable = saveManager.NumSavePoints > 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (loadButton != null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
loadButton.interactable = saveManager.SaveDataExists(SaveDataKey); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (rewindButton != null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
rewindButton.interactable = saveManager.NumSavePoints > 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected void CheckSavePointKeys() |
|
|
|
protected void CheckSavePointKeys() |
|
|
|
{ |
|
|
|
{ |
|
|
|
List<string> keys = new List<string>(); |
|
|
|
List<string> keys = new List<string>(); |
|
|
@ -79,18 +107,24 @@ namespace Fungus |
|
|
|
|
|
|
|
|
|
|
|
public virtual void Save() |
|
|
|
public virtual void Save() |
|
|
|
{ |
|
|
|
{ |
|
|
|
PlayClickSound(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var saveManager = FungusManager.Instance.SaveManager; |
|
|
|
var saveManager = FungusManager.Instance.SaveManager; |
|
|
|
saveManager.Save(); |
|
|
|
|
|
|
|
|
|
|
|
if (saveManager.NumSavePoints > 0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
PlayClickSound(); |
|
|
|
|
|
|
|
saveManager.Save(SaveDataKey); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public virtual void Load() |
|
|
|
public virtual void Load() |
|
|
|
{ |
|
|
|
{ |
|
|
|
PlayClickSound(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var saveManager = FungusManager.Instance.SaveManager; |
|
|
|
var saveManager = FungusManager.Instance.SaveManager; |
|
|
|
saveManager.Load(); |
|
|
|
|
|
|
|
|
|
|
|
if (saveManager.SaveDataExists(SaveDataKey)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
PlayClickSound(); |
|
|
|
|
|
|
|
saveManager.Load(SaveDataKey); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public virtual void Rewind() |
|
|
|
public virtual void Rewind() |
|
|
@ -98,21 +132,30 @@ namespace Fungus |
|
|
|
PlayClickSound(); |
|
|
|
PlayClickSound(); |
|
|
|
|
|
|
|
|
|
|
|
var saveManager = FungusManager.Instance.SaveManager; |
|
|
|
var saveManager = FungusManager.Instance.SaveManager; |
|
|
|
saveManager.Rewind(); |
|
|
|
if (saveManager.NumSavePoints > 1) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
saveManager.Rewind(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public virtual void Restart() |
|
|
|
public virtual void Restart() |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(startScene)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Debug.LogError("No start scene specified"); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var saveManager = FungusManager.Instance.SaveManager; |
|
|
|
var saveManager = FungusManager.Instance.SaveManager; |
|
|
|
saveManager.ClearHistory(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PlayClickSound(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
saveManager.ClearHistory(); |
|
|
|
if (restartDeletesSave) |
|
|
|
if (restartDeletesSave) |
|
|
|
{ |
|
|
|
{ |
|
|
|
saveManager.Delete(); |
|
|
|
saveManager.Delete(SaveDataKey); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
PlayClickSound(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SceneManager.LoadScene(startScene); |
|
|
|
SceneManager.LoadScene(startScene); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|