beatrate / QuirkySave

Modular saving system for Unity.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

QuirkySave

A modular saving system from one of my projects.

Requires Json.NET installed. Can use the com.unity.nuget.newtonsoft-json package or a Json.NET asset from the Asset Store.

You need to have a SaveSystem component in your scene.

Saveable objects need a SavedEntity component on their root object. SavedEntity will control the saving of saveable components on the object and its children. You can use the autogenerated guid ids or switch the id mode to identifier and manually add a human readable id.

Saveable scripts implement the ISavedComponent interface. Saved fields are marked with a [SaveField] attribute. Further serialization and deserialization is handled automatically.

public class ExampleSavedComponent : MonoBehaviour, ISavedComponent
{
    [SaveField]
    private bool someBool;
    [SaveField]
    private Vector3 someVector;

    // You can override if saving should be skipped for an object that hasn't changed from its default state.
    public bool ShouldSave()
    {
        return true;
    }

    // Use this callback to convert your runtime data into your saveable fields.
    public void Save()
    {

    }
    
    // Use this callback to convert your saved fields to runtime data if default serialization
    // doesn't handle it fully.
    public void Load()
    {

    }

    public void Start()
    {
        // Thanks to execution order the loading has already run by this point at Start().
    }
}

About

Modular saving system for Unity.

License:MIT License


Languages

Language:C# 100.0%