Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Latest commit

 

History

History
55 lines (41 loc) · 1.36 KB

File metadata and controls

55 lines (41 loc) · 1.36 KB

ICustomSavable

ICustomSavable can be used to make a cube behaviour save data into the save file

Making a cube behaviour save data

First add this to OnApplicationStart if you haven't already

PMFHelper.AutoInject(System.Reflection.Assembly.GetExecutingAssembly());

(make sure you add this after PMFSystem.EnableSystem<PMFHelper>();)

Than add ICustomSavable to your behaviour, implement the interface and add CustomSaveFileSystem.RequestLoad(this); inside your constructor

public class SaveFileTestingObject : MonoBehaviour, ICustomCubeBehaviour, ICustomSavable
{
    public class SaveData
    {
        public Color32 overlayColor;
    }

    public SaveFileTestingObject(System.IntPtr ptr) : base(ptr)
    {
        CustomSaveFileSystem.RequestLoad(this);
    }


    public string Save()
    {
        PMFLog.Message("Saveing...");

        var saveData = new SaveData()
        {
            overlayColor = GetComponent<MeshRenderer>().material.color 

        }

        return JsonConvert.SerializeObject(saveData);
    }

    public void Load(string json)
    {
        PMFLog.Message("Loading... "+json);

        
        var saveData = JsonConvert.DeserializeObject<SaveData>(json);
        if (saveData != null)
        {
            GetComponent<MeshRenderer>().material.color = saveData.overlayColor;

            return;
        }

    }
}