Browse Source

Moved start scene property to the SaveManager

master
Christopher 8 years ago
parent
commit
9c46bef317
  1. 4
      Assets/Fungus/Scripts/Commands/SavePoint.cs
  2. 5
      Assets/Fungus/Scripts/Components/SaveManager.cs
  3. 21
      Assets/Fungus/Scripts/Components/SaveMenu.cs

4
Assets/Fungus/Scripts/Commands/SavePoint.cs

@ -3,6 +3,7 @@
using UnityEngine; using UnityEngine;
using System.Collections; using System.Collections;
using UnityEngine.SceneManagement;
namespace Fungus namespace Fungus
{ {
@ -56,6 +57,9 @@ namespace Fungus
#region Public members #region Public members
/// <summary>
/// Marks this Save Point as the starting point for Flowchart execution in the scene. Each scene in your game should have exactly one Save Point with this enabled.
/// </summary>
public bool IsStartPoint { get { return isStartPoint; } set { isStartPoint = value; } } public bool IsStartPoint { get { return isStartPoint; } set { isStartPoint = value; } }
/// <summary> /// <summary>

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

@ -174,6 +174,11 @@ namespace Fungus
/// </summary> /// </summary>
public const string DefaultSaveDataKey = "save_data"; public const string DefaultSaveDataKey = "save_data";
/// <summary>
/// The scene that should be loaded when restarting a game.
/// </summary>
public string StartScene { get; set; }
/// <summary> /// <summary>
/// Returns the number of Save Points in the Save History. /// Returns the number of Save Points in the Save History.
/// </summary> /// </summary>

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

@ -47,8 +47,6 @@ namespace Fungus
protected static SaveMenu instance; protected static SaveMenu instance;
protected string startScene = "";
protected virtual void Awake() protected virtual void Awake()
{ {
// Only one instance of SaveMenu may exist // Only one instance of SaveMenu may exist
@ -67,17 +65,21 @@ namespace Fungus
protected virtual void Start() protected virtual void Start()
{ {
// Assume that the first scene that contains the SaveMenu is also the scene to load on restart.
startScene = SceneManager.GetActiveScene().name;
if (!saveMenuActive) if (!saveMenuActive)
{ {
saveMenuGroup.alpha = 0f; saveMenuGroup.alpha = 0f;
} }
var saveManager = FungusManager.Instance.SaveManager;
// Make a note of the current scene. This will be used when restarting the game.
if (string.IsNullOrEmpty(saveManager.StartScene))
{
saveManager.StartScene = SceneManager.GetActiveScene().name;
}
if (loadOnStart) if (loadOnStart)
{ {
var saveManager = FungusManager.Instance.SaveManager;
if (saveManager.SaveDataExists()) if (saveManager.SaveDataExists())
{ {
saveManager.Load(); saveManager.Load();
@ -223,7 +225,9 @@ namespace Fungus
/// </summary> /// </summary>
public virtual void Restart() public virtual void Restart()
{ {
if (string.IsNullOrEmpty(startScene)) var saveManager = FungusManager.Instance.SaveManager;
if (string.IsNullOrEmpty(saveManager.StartScene))
{ {
Debug.LogError("No start scene specified"); Debug.LogError("No start scene specified");
return; return;
@ -232,14 +236,13 @@ namespace Fungus
PlayClickSound(); PlayClickSound();
// Reset the Save History for a new game // Reset the Save History for a new game
var saveManager = FungusManager.Instance.SaveManager;
saveManager.ClearHistory(); saveManager.ClearHistory();
if (restartDeletesSave) if (restartDeletesSave)
{ {
saveManager.Delete(); saveManager.Delete();
} }
SceneManager.LoadScene(startScene); SceneManager.LoadScene(saveManager.StartScene);
} }
#endregion #endregion

Loading…
Cancel
Save