Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

Arbitrary object deserialization

Started by Wavesonics Jan 29, 2008 at 3:12 PM 1 replies 1.3k views
Original Post
Wavesonics
Wavesonics
So here is the idea. We have game objects described in XML, such as:

<GameObject>
  <width>100</width>
  <height>50</height>
  <texturepath>button.png</texturepath>
</GameObject>



Obviously simplified, but what we do is load this from XML into a Property object. Then the calling code gets this object and can tweak the values easily to make a unique button. Once done, the Property object is passed to a templated function: createObject
Zahlman
Zahlman
It doesn't; the object classes do. Give them a constructor that accepts a dictionary of values and sets its members accordingly. The factory determines the type of thing to instantiate and calls an appropriate constructor, passing it the dictionary that it created by parsing the XML.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.