Usage
This section of the documentation explains how to use the asset
1. Implement ISaveable for Your Data
To make a script saveable, implement this interface:
public interface ISaveable
{
SaveData Save();
void Load(SaveData saveData);
}
Example:
public class PlayerData : MonoBehaviour, ISaveable
{
[SerializeField] private string id = Guid.NewGuid().ToString();
[SerializeField] private int health = 100;
public string UniqueId
{
get
{
if (string.IsNullOrEmpty(id))
{
id = Guid.NewGuid().ToString();
}
return id;
}
}
public SaveData Save()
{
return new SaveData
{
data = JsonUtility.ToJson(health),
uniqueID = UniqueId,
};
};
public void Load(SaveData saveData) {
health = JsonUtility.FromJson<int>(saveData.data);
}
2. Add SaveManager to Scene
Drag the SaveManager prefab into your scene or create your own by attaching SaveManager.cs to any GameObject. It will automatically find and save all active ISaveable objects.
Inspector options:
Option | Description |
---|---|
Save Format | JSON or Binary |
Encryption Type | None, XOR, or AES |
Enable Auto Save | Enables periodic background saves |
Auto Save Interval | Time in seconds between auto saves |
Auto Save Slot | The slot to use for auto saving |
Auto Save Timer Mode | JSON or Binary |
Encryption Type | None, XOR, or AES |
OnDelete (Event) | Called when a save is deleted |
OnSave (Event) | Called when a save is created |
OnLoad (Event) | Called when a save is loaded |
3. Manual Save & Load
saveManager.Save("SaveSlot1");
saveManager.Load("SaveSlot1");
4. Auto Save
Enable Auto Save in the inspector or at runtime:
saveManager.EnableAutoSave = true;
5. Encryption Options
Encryption Type | Description |
---|---|
None | No encryption |
XOR | Lightweight and fast |
AES | Secure encryption (key & IV auto-handled) |
6. Save Formats
Format | Description |
---|---|
Binary | Faster and more compact |
JSON | Human-readable |
File extensions:
.sav (Binary)
.json (JSON)
🧪 Demo Scene
Located in:
Assets > PixelArts > Basic Save System > Demo > Scene > Demo Scene.unity
Includes
The demo scene includes the following to showcase the functionalities of the asset
- Runtime Save Panel
- Dummy player data
- Slot switching
- Manual & autosave