目录为:Assets/Scripts/ConfigReader/目录下
ReadHeroSkinConfig.cs
英雄皮肤相关
对应XML配置文件:
Assets/Resources/Config/SkinCfg.xml
部分如下:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<SkinCfg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<info un32ID="110001">
<SkinName>精灵之翼(默认)</SkinName>
<n32Level>0</n32Level>
<un8ConsumeType>0</un8ConsumeType>
<n32Price>0</n32Price>
<Time>0</Time>
<Description>0</Description>
<Icon>32</Icon>
<ResourcesID>0</ResourcesID>
<Skill1Effect>0</Skill1Effect>
<Skill2Effect>0</Skill2Effect>
</info>
<info un32ID="110002">
<SkinName>精灵之翼(默认)</SkinName>
<n32Level>0</n32Level>
<un8ConsumeType>0</un8ConsumeType>
<n32Price>0</n32Price>
<Time>0</Time>
<Description>0</Description>
<Icon>16</Icon>
<ResourcesID>0</ResourcesID>
<Skill1Effect>0</Skill1Effect>
<Skill2Effect>0</Skill2Effect>
</info>
ReadHeroSkinConfig.cs
using System;
using UnityEngine;
using System.Xml;
using System.Collections.Generic;
//英雄皮肤
//Assets/Resources/Config/skinCfg.xml
public class ReadHeroSkinConfig
{
XmlDocument xmlDoc = null;
public ReadHeroSkinConfig(string xmlFilePath)
{
ResourceUnit xmlfileUnit = ResourcesManager.Instance.loadImmediate (xmlFilePath);
TextAsset xmlfile = xmlfileUnit.Asset as TextAsset;
if (!xmlfile)
{
Debug.LogError(" error infos: 没有找到指定的xml文件:"+xmlFilePath);
}
xmlDoc = new XmlDocument ();
xmlDoc.LoadXml (xmlfile.text);
XmlNodeList infoNodeList = xmlDoc.SelectSingleNode ("SkinCfg").ChildNodes;
for (int i = 0; i < infoNodeList.Count; i++)
{
if ((infoNodeList[i] as XmlElement).GetAttributeNode("un32ID") == null)
{
continue;
}
string typeName = (infoNodeList [i] as XmlElement).GetAttributeNode ("un32ID").InnerText;
HeroSkinConfigInfo heroSkinInfo = new HeroSkinConfigInfo ();
heroSkinInfo.GoodsId = Convert.ToInt32 (typeName);
string un8ConsumeType = "";
string n32Price = "";
foreach (XmlElement xEle in infoNodeList[i].ChildNodes)
{
switch (xEle.Name)
{
case "SkinName":
heroSkinInfo.SkinName = Convert.ToString (xEle.InnerText);
break;
case "un8ConsumeType":
un8ConsumeType = Convert.ToString (xEle.InnerText);
break;
case "n32Price":
n32Price = Convert.ToString (xEle.InnerText);
break;
case "Description":
heroSkinInfo.Description = Convert.ToString (xEle.InnerText);
break;
case "Time":
heroSkinInfo.Time = Convert.ToInt32 (xEle.InnerText);
break;
case "Icon":
heroSkinInfo.Icon = Convert.ToString (xEle.InnerText);
break;
case "ResourcesID":
heroSkinInfo.ResourcesID = Convert.ToString (xEle.InnerText);
break;
case "Skill1Effect":
heroSkinInfo.Skill1Effect = Convert.ToString (xEle.InnerText);
break;
case "Skill2Effect":
heroSkinInfo.Skill2Effect = Convert.ToString (xEle.InnerText);
break;
}
}
heroSkinInfo.Consume = GameMethod.ResolveToIntDict (un8ConsumeType, n32Price);
ConfigReader.heroSkinXmlInfoDict.Add (heroSkinInfo.GoodsId, heroSkinInfo);
}
}
}
/*
XML格式:
<info un32ID="110001">
<SkinName>精灵之翼(默认)</SkinName>
<n32Level>0</n32Level>
<un8ConsumeType>0</un8ConsumeType>
<n32Price>0</n32Price>
<Time>0</Time>
<Description>0</Description>
<Icon>32</Icon>
<ResourcesID>0</ResourcesID>
<Skill1Effect>0</Skill1Effect>
<Skill2Effect>0</Skill2Effect>
</info>
*/
public class HeroSkinConfigInfo: System.Object
{
#region 道具信息
public int GoodsId;
public string SkinName;
public Dictionary<int, int> Consume;
public int Time;
public string Description;
public string Icon;
public string ResourcesID;
public string Skill1Effect;
public string Skill2Effect;
#endregion
}