|
I save a xml file by XMlSerializer, the result as below:
<?xml version="1.0" ?>
- <SaveStageData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" n="12">
<friendlist />
- <enemylist>
<RoleCharacter /> <==== there no attributes I set
</enemylist>
<thinglist />
</SaveStageData>
the enemylist is A List,its element is RoleCharacter.
RoleCharacter has some attributes, but in the xml file has no any attribute of
ObjectBase and CCharacter. Do somebody know how to solve this problem?
I am sure one key point The RoleCharacter has data.
public class RoleCharacter
{
public RoleCharacter()//for xml save must have a default constructor
{
}
public RoleCharacter(ENUM_OBJECT_CATEGORY nCate, ENUM_OBJECT_TYPE nType, int _nModelID, Point _point2D, Vector3 _translate, Vector3 _rotate, Vector3 _scale, CCharacter _char)
{
if (nType == ENUM_OBJECT_TYPE.Static)
{
m_object_base = new StaticObject(nCate, nType, _nModelID, _point2D, _translate, _rotate, _scale);
}
else if (nType == ENUM_OBJECT_TYPE.Dynamic)
{
m_object_base = new DynamicObject(nCate, nType, _nModelID, _point2D, _translate, _rotate, _scale);
}
m_charData = _char;
}
public ObjectBase GetObjectBase()
{
return m_object_base;
}
ObjectBase m_object_base;
CCharacter m_charData;
}
[Serializable]
[XmlInclude(typeof(RoleCharacter)), XmlInclude(typeof(CCharacter)),XmlInclude(typeof(ThingObject)), XmlInclude(typeof(ObjectBase)), XmlInclude(typeof(DynamicObject)), XmlInclude(typeof(StaticObject))]
public class SaveStageData
{
public SaveStageData()
{
friendlist = new List<RoleCharacter>();
enemylist = new List<RoleCharacter>();
thinglist = new List<ThingObject>();
n = 12;
}
public int n;
public List<RoleCharacter> friendlist;
public List<RoleCharacter> enemylist;
public List<ThingObject> thinglist;
}
my blog: akira32 ?程之家 Yahoo |
|