目录为:Assets/Scripts/ConfigReader/目录下
ReadHeroBuyConfig.cs
英雄购买相关
对应XML配置文件:
Assets/Resources/Config/HeroBuyCfg.xml
部分如下:
<info un32ID="100002">
<Name>破灭之剑</Name>
<HeroKind>1</HeroKind>
<un8ConsumeType>0</un8ConsumeType>
<n32Price>0</n32Price>
<bIsShowInShop>1</bIsShowInShop>
<bIsShowInHeroInfo>1</bIsShowInHeroInfo>
<UnlockHeroID>10002</UnlockHeroID>
<Time>-1</Time>
<DefaultSkin>110002</DefaultSkin>
<DefaultIcon>16</DefaultIcon>
<OnSaleSkins>0</OnSaleSkins>
</info>
<info un32ID="100003">
<Name>幽影幻刺</Name>
<HeroKind>1</HeroKind>
<un8ConsumeType>0</un8ConsumeType>
<n32Price>0</n32Price>
<bIsShowInShop>1</bIsShowInShop>
<bIsShowInHeroInfo>1</bIsShowInHeroInfo>
<UnlockHeroID>10003</UnlockHeroID>
<Time>-1</Time>
<DefaultSkin>110003</DefaultSkin>
<DefaultIcon>12</DefaultIcon>
<OnSaleSkins>0</OnSaleSkins>
</info>
ReadHeroBuyConfig.cs
using System;
using UnityEngine;
using System.Xml;
using System.Collections.Generic;
//貌似是英雄购买相关的
//对应配置文件:Assets/Resources/Config/HeroBuyCfg.xml
public class ReadHeroBuyConfig
{
XmlDocument xmlDoc = null;
//构造函数
public ReadHeroBuyConfig(string xmlFilePath)
{
ResourceUnit xmlfileUnit = ResourcesManager.Instance.loadImmediate (xmlFilePath, ResourceType.ASSET);
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 ("HeroBuyCfg").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;
HeroBuyConfigInfo heroBuyInfo = new HeroBuyConfigInfo ();
heroBuyInfo.GoodsId = Convert.ToInt32 (typeName);
string un8ConsumeType = "";
string n32Price = "";
foreach (XmlElement xEle in infoNodeList[i].ChildNodes)
{
switch (xEle.Name)
{
case "Name":
heroBuyInfo.Name = Convert.ToString (xEle.InnerText);
break;
case "HeroKind":
heroBuyInfo.HeroKind = GameMethod.ResolveToIntList (xEle.InnerText);
break;
case "un8ConsumeType":
un8ConsumeType = Convert.ToString (xEle.InnerText);
break;
case "n32Price":
n32Price = Convert.ToString (xEle.InnerText);
break;
case "UnlockHeroID":
heroBuyInfo.UnlockHeroID = Convert.ToInt32 (xEle.InnerText);
break;
case "Time":
heroBuyInfo.Time = Convert.ToInt32 (xEle.InnerText);
break;
case "DefaultSkin":
heroBuyInfo.DefaultSkin = Convert.ToInt32 (xEle.InnerText);
break;
case "DefaultIcon":
heroBuyInfo.DefaultIcon = Convert.ToString (xEle.InnerText);
break;
case "OnSaleSkins":
heroBuyInfo.OnSaleSkins = GameMethod.ResolveToStrList (xEle.InnerText);
break;
case "bIsShowInShop":
heroBuyInfo.IsShowShop = Convert.ToBoolean (Convert.ToInt32 (xEle.InnerText));
break;
case "bIsShowInHeroInfo":
heroBuyInfo.bIsShowInHeroInfo = Convert.ToBoolean (Convert.ToInt32 (xEle.InnerText));
break;
}
}
heroBuyInfo.Consume = GameMethod.ResolveToIntDict (un8ConsumeType, n32Price);
ConfigReader.heroBuyXmlInfoDict.Add (heroBuyInfo.GoodsId, heroBuyInfo);
}
}
}
/*
XML格式:
<info un32ID="100001">
<Name>飞樱漫舞</Name>
<HeroKind>2</HeroKind>
<un8ConsumeType>1</un8ConsumeType>
<n32Price>2500</n32Price>
<bIsShowInShop>1</bIsShowInShop>
<bIsShowInHeroInfo>1</bIsShowInHeroInfo>
<UnlockHeroID>10001</UnlockHeroID>
<Time>-1</Time>
<DefaultSkin>110001</DefaultSkin>
<DefaultIcon>32</DefaultIcon>
<OnSaleSkins>111001,111002</OnSaleSkins>
</info>
*/
public class HeroBuyConfigInfo: System.Object
{
#region 道具信息
public int GoodsId;
public string Name;
public List<int> HeroKind;
public Dictionary<int, int> Consume;
public int UnlockHeroID;
public int Time;
public int DefaultSkin;
public string DefaultIcon;
public List<string> OnSaleSkins;
public bool IsShowShop;
public bool bIsShowInHeroInfo;
}