Page 2 of 2

Re: Custom Type Inner Class issues

Posted: Mon May 18, 2020 6:54 am
by Joel
Hi there,

I've tried with the script below and it appears to be working as expected for me.

Just one thing to note, in your SOME_DATA class your fields are readonly. As there is no safe way of determining whether they have already been assigned to, these are not serialisable and are treated in the same way as constants.

Code: Select all

using UnityEngine;

public class mdeim_Test : MonoBehaviour
{
    static ES3File Cache;

    void Start()
    {
        string savefilepath = "SaveFile.es3";
        Cache = new ES3File(savefilepath);
        Save(savefilepath);
    }

    void Save(string savefilepath)
    {
        if (!ES3.FileExists(savefilepath))
        {
            Cache.Save<string>("Test", "Some Value");
            SyncStorage(savefilepath);
        }

        SomeClass.SOME_DATA Data = new SomeClass.SOME_DATA();
        Cache.Save("SomeData...", Data);
        SyncStorage(savefilepath);
    }

    void SyncStorage(string savefilepath)
    {
        Cache.Sync(savefilepath);
    }
}

public class SomeClass
{
    public class SOME_DATA
    {
        public readonly string Name = "";
        public readonly string SomethingElse = "";

        public SOME_DATA()
        {
            Name = "Name value";
            SomethingElse = "Something else value";
        }
    }
}
The output I get from this is:

Code: Select all

{
	"Test" : {
		"__type" : "System.String",
		"value" : "Some Value"
	},
	"SomeData..." : {
		"__type" : "SomeClass+SOME_DATA,Assembly-CSharp",
		"value" : {
	}
	}
}
All the best,
Joel