Using XNA's XML content pipeline to read arrays of objects with different subtypes
Posted
by
Mcguirk
on Game Development
See other posts from Game Development
or by Mcguirk
Published on 2012-04-02T04:23:29Z
Indexed on
2012/04/02
5:43 UTC
Read the original article
Hit count: 543
Using XNA's XML content importer, is it possible to read in an array of objects with different subtypes?
For instance, assume these are my class definitions:
public abstract class MyBaseClass
{
public string MyBaseData;
}
public class MySubClass0 : MyBaseClass
{
public int MySubData0;
}
public class MySubClass1 : MyBaseClass
{
public bool MySubData1;
}
And this is my XML file:
<XnaContent>
<Asset Type="MyBaseClass[]">
<Item> <!-- I want this to be an instance of MySubClass0 -->
<MyBaseData>alpha</MyBaseData>
<MySubData0>314</MySubData0>
</Item>
<Item> <!-- I want this to be an instance of MySubClass1 -->
<MyBaseData>bravo</MyBaseData>
<MySubData1>true</MySubData1>
</Item>
</Asset>
</XnaContent>
How do I specify that I want the first Item to be an instance of MySubclass0 and the second Item to be an instance of MySubclass1?
© Game Development or respective owner