Game Development Reference
In-Depth Information
editor that was at parity only with the features that were currently being used in
the legacy-authoring tool. By keeping parity with a minimal set of features, I could
provide a smooth transition to the new tool for the development team.
It was not until I needed to save out data from the new authoring tool that
I began to wrestle with formats. Unity, by default, will serialize objects for you
with a few API calls. However, Unity stores your objects in a binary format, which
doesn't allow for easy merging. The legacy-authoring tool used XML for this reason,
since multiple people can work on a single layout and merge changes after. At this
point, I remembered that the .NET XML serializer allowed for an easy way to write
objects to disk. This allowed me to have the best of both worlds: an XML format
for storing the layouts during authoring and a binary version that could be saved
elsewhere for runtime. Both of these serialization methods were supported from
the same class with custom attributes for each serializer.
12.4.2 .NET XML Serialization
Let's take our XML example from before and have it automatically parsed by the
XML serialization class from .NET. First, we need to whip our XML document
into shape by converting Listing 12.1 into something digestible by .NET, shown in
Lisiting 12.5.
<?xml version="1.0" encoding="utf-8"?>
<Characters xmlns:usos="urn:schemas-microsoft-com:office:spreadsheet">
<CharacterData>
<Character>MasterChieftain</Character>
<Description>One bad mamma jamma</Description>
<HitPoints>50.0</HitPoints>
<MoveSpeed>10.0</MoveSpeed>
<AttackPower>30.0</AttackPower>
<Class>Armored</Class>
<Thumbnail>mstrchf1.png</Thumbnail>
</CharacterData>
<CharacterData>
<Character>SolidSerpent</Character>
<Description>A slick fellow</Description>
<HitPoints>63.0</HitPoints>
<MoveSpeed>20.0</MoveSpeed>
<AttackPower>15.0</AttackPower>
<Class>Standard</Class>
<Thumbnail>solid8.png</Thumbnail>
</CharacterData>
<CharacterData>
<Character>NathanDraco</Character>
<Description>An adventurous lad</Description>
<HitPoints>35.0</HitPoints>
<MoveSpeed>20.0</MoveSpeed>
<AttackPower>18.0</AttackPower>
<Class>Standard</Class>
<Thumbnail>draco3.png</Thumbnail>
</CharacterData>
</Characters>
Listing 12.5. Simpler XML document (xformed.xml).
Search WWH ::




Custom Search