ISaveSystem
Contract for save/load operations by slot, with event notifications.
A failed save raises. It never returns quietly as though it had worked, which is the failure mode that loses someone their afternoon.
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;
}
engine.SaveSystem is a SaveSystemFacade. Save(slot) and Load(slot) only raise its SaveRequested and LoadRequested events, and OnSaved / OnLoaded fire only when the engine calls NotifySaved / NotifyLoaded. In the current engine nothing handles those requests or calls those hooks, and HasSaveData(slot) / DeleteSave(slot) work on a slot{N}.sav file in Application.persistentDataPath that the engine does not write (the engine saves named folders under Saves/, see the Save System guide). For real saves use the in-game menus or, in the Source and Studio editions, SavegameManager.
Methods
Save(int slot)
Save the current game state to a slot.
| Parameter | Type | Description |
|---|---|---|
slot | int | Save slot index (typically 0-2) |
Requests a save of all registered SavableObject instances to a JSON file. The actual persistence runs on the engine's coroutine-based SavegameManager, so treat the call as asynchronous — subscribe to OnSaved to know when the save has completed.
Load(int slot)
Load a game state from a slot.
| Parameter | Type | Description |
|---|---|---|
slot | int | Save 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.
| Parameter | Type | Description |
|---|---|---|
slot | int | Save slot index to check |
Returns: bool -- true if the slot contains save data.
DeleteSave(int slot)
Delete save data from a slot.
| Parameter | Type | Description |
|---|---|---|
slot | int | Save slot index to delete |
Events
OnSaved
Fired after a successful save operation.
Signature: event Action<int> OnSaved
| Parameter | Type | Description |
|---|---|---|
slot | int | The slot that was saved to |
OnLoaded
Fired after a successful load operation.
Signature: event Action<int> OnLoaded
| Parameter | Type | Description |
|---|---|---|
slot | int | The slot that was loaded from |
Usage Example
using OpenMon.MCE.SDK;
using Zenject;
public class SaveLoadUI : MonoBehaviour
{
// Only IMonsterCaptureEngine is bound in DI; reach subsystems through it.
[Inject] private IMonsterCaptureEngine engine;
private ISaveSystem saveSystem;
private void Awake()
{
saveSystem = engine.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}");
};
}
}