private void LoadXMLDocument(string fileName, string xml)
{
XmlDocument xmlDoc = new XmlDocument();
XmlReaderSettings setting = new XmlReaderSettings();
setting.IgnoreComments = true;
setting.IgnoreWhitespace = true;
MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(xml));
XmlReader reader = XmlReader.Create(stream, setting);
xmlDoc.Load(reader);
XmlNode node = xmlDoc.FirstChild;
do
{
node = node.NextSibling;
}
while (node.NodeType == XmlNodeType.Comment);
string type = node.Attributes["type"].Value;
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
Type refType = assembly.GetType("Core.Template." + type);
if (refType != null)
{
XmlNodeList nodeList = node.ChildNodes;
List<PrototypeData> dataList = null;
for (int i = 0; i < nodeList.Count; i++)
{
XmlNode childNode = nodeList[i];
if (childNode.NodeType == XmlNodeType.Comment)
{
continue;
}
PrototypeData prototypeData = System.Activator.CreateInstance(refType) as PrototypeData;
prototypeData.LoadData(childNode);
if (dicData.ContainsKey(prototypeData.mPrototypeID) == false)
{
dicData.Add(prototypeData.mPrototypeID, prototypeData);
if (!mAllPrototyByType.TryGetValue(type, out dataList))
{
dataList = new List<PrototypeData>();
mAllPrototyByType.Add(type, dataList);
}
dataList.Add(prototypeData);
}
else
{
GameDebug.LogError(fileName + "表有重复ID=" + prototypeData.mPrototypeID);
}
}
}
}