Hi I’m using the “Save and Load from XML U3 Collections” scripts from the wiki in my game. It’s working but I have a question or two. Hope somebody in here are familiar with these scripts.
First of all I would like to make sub classes in the xml structure like this:
I’m trying to make a custom class for the subclasses in the “SaveStructure” script, but it won’t register no matter what I do. This is probably because i have no idea what this ISerializable class does.
It would also be nice to have the output xml file better formatted. Right now i need to format it before it gets “human readable”.
Any help to these question would be much appreciated!
I haven’t used the “Save and Load from XML U3 Collections” you’re mentioning, but if the purpose of your script is just to save a data structure there’s no need to use the ISerializable interface and manually add each property. XML serialization using the XmlSerializer is pretty competent, without using the interface. Marking the class with the Serializable attribute is in most cases sufficient for at least my serialization needs.
Please let me know if you want more general help on serializing to XML, and I’ll try to help you out.
The using System.Runtime.Serialization.Formatters.Binary and ISerializable namespace are for BINARY serialization, which is not human readable (err, for most). You’re looking for System.Xml.Serialization.
Google C# XML Serialization, plenty of results. All applicable to Unity.
Be sure to check out the wiki version on some extra stuff you have to care about while loading in a standalone/webplayer build.
Just drop a message if you found anything that isn’t working as expected for you.