Okay, so I got my things working to serialize all my map (landscape, lights, models, you name it).
I'm using this to serialize a class, which basically takes everything that is public from the class and dumps it in a XML file:
Private Sub Compile_Materials()
' Serialize
Dim filePath = pathCompiled & "maps\" & mapName & "\xml\materials.xml"
Dim stream As New System.IO.StreamWriter(filePath)
Dim inst As New XmlSerializer(CoreMaterial.GetType)
inst.Serialize(stream, CoreMaterial)
stream.Close()
End Sub
My problem is when I try to deserialize the map. It does a marvelous job at reading the file and dumping the XML file into an instance, but wouldn't be much simpler if the deserialization would feed the variables and lists of the class instead?
Private Sub Decompile_Materials()
' Deserialize
Dim filePath = pathCompiled & "maps\" & mapName & "\xml\materials.xml"
Dim stream As New System.IO.StreamReader(filePath)
Dim xml As New XmlSerializer(CoreMaterial.GetType)
Dim inst As New MaterialManager()
inst = xml.Deserialize(stream)
stream.Close()
' Rebuild
CoreMaterial.Rebuild(inst)
End Sub
I must be missing something here because it makes no sense to me that all the info be dumped in an instance and not automagically feed the variables of the CoreMaterial class. The only I found to work around this is to pass the instance to the class and rebuild the whole thing from the parameters, which is a serious pain in the butt.