I wondered if there was any examples of saving and loading a static class using the Pixel crushers dialog system. I tried something like this, but the ISaveable didn't exist.
Im looking for an example on how to serialize, save and load custom data.
Code: Select all
using UnityEngine;
using System.Collections.Generic;
using PixelCrushers;
public class GlobalVariablesSaver : MonoBehaviour, PixelCrushers.ISaveable
{
[System.Serializable]
public struct SaveDataStruct
{
public int CurrentLocationID;
public int CurrentZoneID;
public Vector3 newPlayerPosition;
public int PlayerSceneIndex;
}
public string key = "globalVariables";
public object SaveData()
{
return new SaveDataStruct
{
CurrentLocationID = GlobalVariables.CurrentLocationID,
CurrentZoneID = GlobalVariables.CurrentZoneID,
newPlayerPosition = GlobalVariables.newPlayerPosition,
PlayerSceneIndex = GlobalVariables.PlayerSceneIndex,
};
}
public void LoadData(object data)
{
var saveData = (SaveDataStruct)data;
GlobalVariables.CurrentLocationID = saveData.CurrentLocationID;
GlobalVariables.CurrentZoneID = saveData.CurrentZoneID;
GlobalVariables.newPlayerPosition = saveData.newPlayerPosition;
GlobalVariables.PlayerSceneIndex = saveData.PlayerSceneIndex;
}
void OnEnable()
{
SaveSystem.RegisterSaver(this);
}
void OnDisable()
{
SaveSystem.UnregisterSaver(this);
}
}