Skip to main content

ISaveSystem

Contract for save/load operations. Supports multiple save slots with event notifications.

Namespace: OpenMon.MCE.SDK

Definition

public interface ISaveSystem
{
void Save(int slot);
void Load(int slot);
bool HasSaveData(int slot);
void DeleteSave(int slot);
event Action<int> OnSaved;
event Action<int> OnLoaded;
}

Methods

Save(int slot)

Save the current game state to a slot.

ParameterTypeDescription
slotintSave slot index (typically 0-2)

Serializes all registered SavableObject instances to a JSON file. The save is synchronous and completes before the method returns.

Load(int slot)

Load a game state from a slot.

ParameterTypeDescription
slotintSave slot index to load from

Deserializes the JSON file and applies the state to all registered SavableObject instances. May trigger scene transitions if the saved position is in a different scene.

HasSaveData(int slot)

Check if a save slot has data.

ParameterTypeDescription
slotintSave slot index to check

Returns: bool -- true if the slot contains save data.

DeleteSave(int slot)

Delete save data from a slot.

ParameterTypeDescription
slotintSave slot index to delete

Events

OnSaved

Fired after a successful save operation.

Signature: event Action<int> OnSaved

ParameterTypeDescription
slotintThe slot that was saved to

OnLoaded

Fired after a successful load operation.

Signature: event Action<int> OnLoaded

ParameterTypeDescription
slotintThe slot that was loaded from

Usage Example

using OpenMon.MCE.SDK;
using Zenject;

public class SaveLoadUI : MonoBehaviour
{
[Inject] private ISaveSystem saveSystem;

[SerializeField] private Button[] saveButtons;
[SerializeField] private Button[] loadButtons;
[SerializeField] private Button[] deleteButtons;
[SerializeField] private Text[] slotLabels;

private void Start()
{
// Update slot labels
for (int i = 0; i < 3; i++)
{
int slot = i; // Capture for closure
slotLabels[i].text = saveSystem.HasSaveData(i)
? $"Slot {i + 1}: Saved"
: $"Slot {i + 1}: Empty";

saveButtons[i].onClick.AddListener(() => saveSystem.Save(slot));
loadButtons[i].onClick.AddListener(() =>
{
if (saveSystem.HasSaveData(slot))
saveSystem.Load(slot);
});
deleteButtons[i].onClick.AddListener(() =>
{
saveSystem.DeleteSave(slot);
slotLabels[slot].text = $"Slot {slot + 1}: Empty";
});
}

// Listen for save events
saveSystem.OnSaved += (slot) =>
{
slotLabels[slot].text = $"Slot {slot + 1}: Saved";
Debug.Log($"Game saved to slot {slot + 1}");
};
}
}