You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
3.3 KiB
105 lines
3.3 KiB
8 years ago
|
using UnityEngine;
|
||
|
using System.Collections.Generic;
|
||
|
using Fungus;
|
||
|
using UnityEngine.SceneManagement;
|
||
|
|
||
|
namespace Fungus
|
||
|
{
|
||
8 years ago
|
/// <summary>
|
||
|
/// The Save History is a list of previously created Save Points, sorted chronologically.
|
||
|
/// </summary>
|
||
8 years ago
|
[System.Serializable]
|
||
|
public class SaveHistory
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// Version number of current save data format.
|
||
|
/// </summary>
|
||
|
protected const int SaveDataVersion = 1;
|
||
|
|
||
|
[SerializeField] protected int version = SaveDataVersion;
|
||
|
|
||
|
[SerializeField] protected List<string> savePoints = new List<string>();
|
||
|
|
||
8 years ago
|
[SerializeField] protected List<string> rewoundSavePoints = new List<string>();
|
||
|
|
||
8 years ago
|
#region Public methods
|
||
|
|
||
8 years ago
|
/// <summary>
|
||
|
/// Returns the number of Save Points in the Save History.
|
||
|
/// </summary>
|
||
8 years ago
|
public int NumSavePoints { get { return savePoints.Count; } }
|
||
|
|
||
8 years ago
|
/// <summary>
|
||
|
/// Returns the current number of rewound Save Points in the Save History.
|
||
|
/// </summary>
|
||
8 years ago
|
public int NumRewoundSavePoints { get { return rewoundSavePoints.Count; } }
|
||
|
|
||
8 years ago
|
/// <summary>
|
||
|
/// Creates a new Save Point using a key and description, and adds it to the Save History.
|
||
|
/// </summary>
|
||
8 years ago
|
public void AddSavePoint(string savePointKey, string savePointDescription)
|
||
8 years ago
|
{
|
||
|
string sceneName = SceneManager.GetActiveScene().name;
|
||
8 years ago
|
var savePointData = SavePointData.Encode(savePointKey, savePointDescription, sceneName);
|
||
8 years ago
|
savePoints.Add(savePointData);
|
||
|
}
|
||
|
|
||
8 years ago
|
/// <summary>
|
||
|
/// Rewinds to the previous Save Point in the Save History.
|
||
|
/// The latest Save Point is moved to a seperate list of rewound save points.
|
||
|
/// </summary>
|
||
8 years ago
|
public void Rewind()
|
||
8 years ago
|
{
|
||
|
if (savePoints.Count > 0)
|
||
|
{
|
||
8 years ago
|
rewoundSavePoints.Add(savePoints[savePoints.Count - 1]);
|
||
8 years ago
|
savePoints.RemoveAt(savePoints.Count - 1);
|
||
|
}
|
||
|
}
|
||
|
|
||
8 years ago
|
/// <summary>
|
||
|
/// Fast forwards to the next Save Point in the Save History.
|
||
|
/// The most recently rewound Save Point is moved back to the main list of save points.
|
||
|
/// </summary>
|
||
8 years ago
|
public void FastForward()
|
||
|
{
|
||
|
if (rewoundSavePoints.Count > 0)
|
||
|
{
|
||
|
savePoints.Add(rewoundSavePoints[rewoundSavePoints.Count - 1]);
|
||
|
rewoundSavePoints.RemoveAt(rewoundSavePoints.Count - 1);
|
||
|
}
|
||
|
}
|
||
|
|
||
8 years ago
|
/// <summary>
|
||
|
/// Loads the latest Save Point.
|
||
|
/// </summary>
|
||
8 years ago
|
public void LoadLatestSavePoint()
|
||
|
{
|
||
|
if (savePoints.Count > 0)
|
||
|
{
|
||
|
var savePointData = savePoints[savePoints.Count - 1];
|
||
|
SavePointData.Decode(savePointData);
|
||
|
}
|
||
|
}
|
||
|
|
||
8 years ago
|
/// <summary>
|
||
|
/// Clears all Save Points.
|
||
|
/// </summary>
|
||
8 years ago
|
public void Clear()
|
||
|
{
|
||
|
savePoints.Clear();
|
||
8 years ago
|
rewoundSavePoints.Clear();
|
||
|
}
|
||
|
|
||
8 years ago
|
/// <summary>
|
||
|
/// Clears rewound Save Points only. The main Save Point list is not changed.
|
||
|
/// </summary>
|
||
8 years ago
|
public void ClearRewoundSavePoints()
|
||
|
{
|
||
|
rewoundSavePoints.Clear();
|
||
8 years ago
|
}
|
||
|
|
||
|
#endregion
|
||
|
}
|
||
|
}
|