I’m building a game project where there are simple container objects that can have children. I somehow need to save the “state” of the game and serializa to XML. Then I will simply be loading the game back by serializing XML, but I need to save the state of the objects, links, etc. What is the best practice to achieve this? To demonstrate, think of these:
GameObject Bag (ID 1234)
--------------
Sword (object ID 5678, some reference to another object in game: 0987)
and so on. I’ve got in-game references between objects and I need to preserve this state while saving/loading to XML. I have no problem with XML serialization itself in a simple scenario, but I don’t know how to preserve the “links” between objects.
Use a serializer that supports references. DatacontractSerializer can do it for example.
For xml, you can enable it in the DataContractSerializer for example
http://blogs.msdn.com/b/sowmy/archive/2006/03/26/561188.aspx