Save System
Components
Example Workflow
Example Code
Last updated
// Example implmentation of the Save System for a collectable object, like a pickup item in a game.
public class Collectable : SaveableMonoBehaviour<CollectableState>
{
protected override CollectableState DefaultState => CollectableState.NotCollected;
protected override void Awake()
{
base.Awake();
// Deactive the collectable GameObject if it was already collected during a previous session
if (_currentState == CollectableStatus.Collected && DeactivateOnComplete)
{
gameObject.SetActive(false);
}
}
// Update the save status of the collectable GameObject so it is not active in the next session
public void GetCollected()
{
State = CollectableState.Collected;
SetSaveStatus();
if (DeactivateOnComplete)
{
gameObject.SetActive(false);
}
}
}