Monday 15 August 2011

c# - Serialize whole instance with child instances (class serialization) and save to file -


I am creating a game with Unity3D. I have a game called GameInstance, in which it contains all existing game instance data. For the player property can return a player item in

Still, all items are one of the key keys / values, this is the only data. Now I have to do all this serial and save it in a file so that I can reload the game to restart where it was left.

That's my original intention, maybe someone would suggest better but still this is the most flexible option I have found.

I used the .NET XML object serialization last time but it is a while and I will need to get more direct advice about it. For example, should I have XML or JSON serial?

TL; DR : I have my entire contents C # /. I want to serialize a Unity 3D project with Net. How should I proceed?

Thank you!

I personally like Jason If you are using json.NET, then this would be as simple;

  string json = JsonConvert.SerializeObject (MyObject);   

or to compact it;

  file. Type all text (". / Myfile", JsonConvert.SerializeObject (MyObject));   

Then you want to;

  MyObject obj = JsonConvert.DeserializeObject & lt; MyObject & gt; (File. ReadList ("./ Myfile"));   

Edit: In response to the exception, you want to use this surcharge which allows you to change the syllable settings;

  JsonConvert.SerializeObject (ResultGroups, New JsonSerializer Settings () {ReferenceLoopHandling = ReferenceLoopHandling.Ignore});    

No comments:

Post a Comment