Custom Type Inner Class issues

Discussion and help for Easy Save 3
User avatar
Joel
Moodkie Staff
Posts: 2800
Joined: Wed Nov 07, 2012 10:32 pm

Re: Custom Type Inner Class issues

Post 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
Joel @ Moodkie Interactive
Twitter - Unity

Post Reply