using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace Fungus
{
///
/// Serializable container for a Save Point.
///
[System.Serializable]
public class SavePointData
{
[SerializeField] protected string savePointKey;
[SerializeField] protected string savePointDescription;
[SerializeField] protected string sceneName;
[SerializeField] protected List flowchartDatas = new List();
protected static SavePointData tempSavePointData;
protected static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
if (scene.name != tempSavePointData.SceneName)
{
return;
}
SceneManager.sceneLoaded -= OnSceneLoaded;
var savePointData = tempSavePointData;
for (int i = 0; i < savePointData.FlowchartDatas.Count; i++)
{
var flowchartData = savePointData.FlowchartDatas[i];
FlowchartData.Decode(flowchartData);
}
ExecuteBlocks(savePointData.savePointKey);
}
protected static void ExecuteBlocks(string savePointKey)
{
SavePointLoaded.NotifyEventHandlers(savePointKey);
// Execute any block containing a SavePoint command matching the save key, with Resume From Here enabled
var savePoints = Object.FindObjectsOfType();
for (int i = 0; i < savePoints.Length; i++)
{
var savePoint = savePoints[i];
if (savePoint.ResumeFromHere &&
string.Compare(savePoint.SavePointKey, savePointKey, true) == 0)
{
int index = savePoint.CommandIndex;
var block = savePoint.ParentBlock;
var flowchart = savePoint.GetFlowchart();
flowchart.ExecuteBlock(block, index + 1);
// Assume there's only one SavePoint using this key
break;
}
}
// Execute any block containing a Label matching the save key
var labels = Object.FindObjectsOfType