目录为:Assets/Scripts/ConfigReader/目录下
ReadHeroConfig.cs
全是英雄相关信息
对应XML文件:
Assets/Resources/Config/HeroCfg.xml
部分如下:
<info un32ID="Nvyao_5">
<szNOStr>10001</szNOStr>
<HeroKind>2</HeroKind>
<eMagicCate>2</eMagicCate>
<XuetiaoHeight>6</XuetiaoHeight>
<eAttackWay>2</eAttackWay>
<n32AttackDist>1050</n32AttackDist>
<n32BaseExp>80</n32BaseExp>
<n32BasePhyAttPower>47</n32BasePhyAttPower>
<n32BaseMagAttPower>0</n32BaseMagAttPower>
<n32BasePhyDef>14</n32BasePhyDef>
<n32BaseMagDef>30</n32BaseMagDef>
<n32BaseMoveSpeed>680</n32BaseMoveSpeed>
<n32BaseMoveSpeedScaling>1000</n32BaseMoveSpeedScaling>
<n32BaseAttackSpeed>1000</n32BaseAttackSpeed>
<n32BaseMaxHP>480</n32BaseMaxHP>
<n32BaseMaxMP>260</n32BaseMaxMP>
<n32BaseHPRecover>1000</n32BaseHPRecover>
<n32BaseMPRecover>1300</n32BaseMPRecover>
<n32BaseReliveTime>3000</n32BaseReliveTime>
<n32ExpGrowth>50</n32ExpGrowth>
<n32PhyAttGrowth>2</n32PhyAttGrowth>
<n32MagAttGrowth>0</n32MagAttGrowth>
<n32PhyDefGrowth>4</n32PhyDefGrowth>
<n32MagDefGrowth>0</n32MagDefGrowth>
<n32MoveSpeedGrowth>0</n32MoveSpeedGrowth>
<n32AttackSpeedGrowth>10</n32AttackSpeedGrowth>
<n32MaxHPGrowth>102</n32MaxHPGrowth>
<n32MaxMPGrowth>28</n32MaxMPGrowth>
<n32HPRecoverGrowth>150</n32HPRecoverGrowth>
<n32MPRecoverGrowth>120</n32MPRecoverGrowth>
<n32ReliveGrowth>3000</n32ReliveGrowth>
<n32CPRecover>4</n32CPRecover>
<n32CollideRadious>50</n32CollideRadious>
<EmitPos>0,1500,0</EmitPos>
<HitPos>0,1500,0</HitPos>
<n32LockRadious>1</n32LockRadious>
<n32RandomAttack>attack,attack2,attack3</n32RandomAttack>
<un32WalkSound>0</un32WalkSound>
<un32DeathSould>Nvyao5_Dead</un32DeathSould>
<un32Script1>Nvyao_5_line_01,Nvyao_5_line_02</un32Script1>
<n32Script1Rate>90050,90050</n32Script1Rate>
<un32SkillType1>1200101</un32SkillType1>
<un32SkillType2>1200201</un32SkillType2>
<un32SkillType3>1300101</un32SkillType3>
<un32SkillType4>1300201</un32SkillType4>
<un32SkillType5>1100101</un32SkillType5>
<un32SkillType6>1100001</un32SkillType6>
<un32SkillTypeP>11000101</un32SkillTypeP>
<un32PreItem>30032,30001,30003</un32PreItem>
<un32MidItem>30085,30007,30031</un32MidItem>
<un32ProItem>30088,30007,30031,30106,30035,30006</un32ProItem>
</info>
ReadHeroConfig.cs
using System;
using UnityEngine;
using System.Xml;
using System.Collections.Generic;
//英雄相关
//对应配置文件:Assets/Resources/Config/HeroCfg.xml
public class ReadHeroConfig
{
XmlDocument xmlDoc = null;
//构造函数
public ReadHeroConfig(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 ("herocfg").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;
HeroConfigInfo heroSelectInfo = new HeroConfigInfo ();
heroSelectInfo.HeroName = Convert.ToString (typeName);
foreach (XmlElement xEle in infoNodeList[i].ChildNodes)
{
switch (xEle.Name)
{
case "szNOStr":
heroSelectInfo.HeroNum = Convert.ToInt32 (xEle.InnerText);
break;
case "eMagicCate":
heroSelectInfo.HeroMgicCate = Convert.ToInt32 (xEle.InnerText);
break;
case "XuetiaoHeight":
heroSelectInfo.HeroXueTiaoHeight = Convert.ToInt32 (xEle.InnerText);
break;
case "n32AttackDist":
heroSelectInfo.HeroBaseExp = Convert.ToSingle (xEle.InnerText);
break;
case "n32BaseExp":
heroSelectInfo.HeroBaseExp = Convert.ToSingle (xEle.InnerText);
break;
case "n32BasePhyAttPower":
heroSelectInfo.HeroPhyAtt = Convert.ToSingle (xEle.InnerText);
break;
case "n32BaseMagAttPower":
heroSelectInfo.HeroMagAtt = Convert.ToSingle (xEle.InnerText);
break;
case "n32BasePhyDef":
heroSelectInfo.HeroPhyDef = Convert.ToSingle (xEle.InnerText);
break;
case "n32BaseMagDef":
heroSelectInfo.HeroMagDef = Convert.ToSingle (xEle.InnerText);
break;
case "n32BaseMoveSpeed":
heroSelectInfo.HeroMoveSpeed = Convert.ToSingle (xEle.InnerText);
break;
case "n32BaseMoveSpeedScaling":
heroSelectInfo.n32BaseMoveSpeedScaling = Convert.ToSingle (xEle.InnerText);
break;
case "n32BaseAttackCD":
heroSelectInfo.HeroBaseAtkCd = Convert.ToSingle (xEle.InnerText);
break;
case "n32BaseMaxHp":
heroSelectInfo.HeroMaxHp = Convert.ToSingle (xEle.InnerText);
break;
case "n32BaseMxpMp":
heroSelectInfo.HeroMaxMp = Convert.ToSingle (xEle.InnerText);
break;
case "n32BaseHpRecover":
heroSelectInfo.HeroHpRecover = Convert.ToSingle (xEle.InnerText);
break;
case "n32BaseMpRecover":
heroSelectInfo.HeroMpRecover = Convert.ToSingle (xEle.InnerText);
break;
case "n32BaseReliveTime":
heroSelectInfo.HeroRelieveTime = Convert.ToSingle (xEle.InnerText);
break;
case "n32ExpGrowth":
heroSelectInfo.HeroExpGrowth = Convert.ToSingle (xEle.InnerText);
break;
case "n32PhyAttGrowth":
heroSelectInfo.HeroPhyAttGrowth = Convert.ToSingle (xEle.InnerText);
break;
case "n32MagAttGrowth":
heroSelectInfo.HeroMagAttGrowth = Convert.ToSingle (xEle.InnerText);
break;
case "n32PhyDefGrowth":
heroSelectInfo.HeroPhyDefGrowth = Convert.ToSingle (xEle.InnerText);
break;
case "n32MagDefGrowth":
heroSelectInfo.HeroMagDefGrowth = Convert.ToSingle (xEle.InnerText);
break;
case "n32AttackCDGrowth":
heroSelectInfo.HeroAtkCdGrowth = Convert.ToSingle (xEle.InnerText);
break;
case "n32MaxHPGrowth":
heroSelectInfo.HeroMaxHpGrowth = Convert.ToSingle (xEle.InnerText);
break;
case "n32MaxMPGrowth":
heroSelectInfo.HeroMaxHpGrowth = Convert.ToSingle (xEle.InnerText);
break;
case "n32HPRecoverGrowth":
heroSelectInfo.HeroHpRecoverGrowth = Convert.ToSingle (xEle.InnerText);
break;
case "n32MPRecoverGrowth":
heroSelectInfo.HeroMpRecoverGrowth = Convert.ToSingle (xEle.InnerText);
break;
case "n32ReliveGrowth":
heroSelectInfo.HeroReliveGrowth = Convert.ToSingle (xEle.InnerText);
break;
case "n32CPRecover":
heroSelectInfo.HeroCpRecover = Convert.ToSingle (xEle.InnerText);
break;
case "n32CollideRadious":
heroSelectInfo.HeroCollideRadious = Convert.ToSingle (xEle.InnerText);
break;
case "un32DeathSould":
heroSelectInfo.HeroDeathsould = Convert.ToString (xEle.InnerText);
break;
case "un32WalkSound":
heroSelectInfo.un32WalkSound = xEle.InnerText;
break;
case "un32Script1":
heroSelectInfo.HeroScript1 = Convert.ToSingle (xEle.InnerText);
break;
case "un32ScriptRate":
heroSelectInfo.HeroScript1Rate = Convert.ToSingle(xEle.InnerText);
break;
case "un32SkillType1":
heroSelectInfo.HeroSkillType1 = Convert.ToInt32 (xEle.InnerText);
break;
case "un32SkillType2":
heroSelectInfo.HeroSkillType2 = Convert.ToInt32 (xEle.InnerText);
break;
case "un32SkillType3":
heroSelectInfo.HeroSkillType3 = Convert.ToInt32 (xEle.InnerText);
break;
case "un32SkillType4":
heroSelectInfo.HeroSkillType4 = Convert.ToInt32 (xEle.InnerText);
break;
case "un32SkillType5":
heroSelectInfo.HeroSkillType5 = Convert.ToInt32 (xEle.InnerText);
break;
case "un32SkillType6":
heroSelectInfo.HeroSkillType6 = Convert.ToInt32 (xEle.InnerText);
break;
case "n32LockRadious":
heroSelectInfo.n32LockRadious = Convert.ToSingle (xEle.InnerText);
break;
case "n32RandomAttack":
heroSelectInfo.n32RandomAttack = GameDefine.GameMethod.ResolveToStrList (xEle.InnerText);
break;
case "un32PreItem":
{
string str = Convert.ToString (xEle.InnerText);
if (str.CompareTo ("0") != 0)
{
heroSelectInfo.HeroPreEquip = GameMethod.ResolveToIntList (str, ',');
}
}
break;
case "un32MidItem":
{
string str = Convert.ToString (xEle.InnerText);
if (str.CompareTo ("0") != 0)
{
heroSelectInfo.HeroMidEquip = GameMethod.ResolveToIntList (str, ',');
}
}
break;
case "un32ProItem":
{
string str = Convert.ToString (xEle.InnerText);
if (str.CompareTo ("0") != 0)
{
heroSelectInfo.HeroLatEquip = GameMethod.ResolveToIntList (str, ',');
}
}
break;
case "HeroKind":
{
string str = Convert.ToString (xEle.InnerText);
List<int> list = GameMethod.ResolveToIntList (str, ',');
for (int j = 0; j < list.Count; j++)
{
heroSelectInfo.heroKind.Add ((HeroType)list.ElementAt (j));
}
}
break;
case "un32SkillTypeP":
heroSelectInfo.HeroSkillTypeP = Convert.ToInt32 (xEle.InnerText);
break;
}
}
ConfigReader.heroXmlInfoDict.Add (heroSelectInfo.HeroNum, heroSelectInfo);
}
}
}
/*
XML格式:
<info un32ID="Jinglingnan_6">
<szNOStr>19999</szNOStr>
<HeroKind>1</HeroKind>
<eMagicCate>2</eMagicCate>
<XuetiaoHeight>6</XuetiaoHeight>
<eAttackWay>1</eAttackWay>
<n32AttackDist>400</n32AttackDist>
<n32BaseExp>10</n32BaseExp>
<n32BasePhyAttPower>220</n32BasePhyAttPower>
<n32BaseMagAttPower>0</n32BaseMagAttPower>
<n32BasePhyDef>120</n32BasePhyDef>
<n32BaseMagDef>120</n32BaseMagDef>
<n32BaseMoveSpeed>720</n32BaseMoveSpeed>
<n32BaseMoveSpeedScaling>1000</n32BaseMoveSpeedScaling>
<n32BaseAttackSpeed>1000</n32BaseAttackSpeed>
<n32BaseMaxHP>1080</n32BaseMaxHP>
<n32BaseMaxMP>560</n32BaseMaxMP>
<n32BaseHPRecover>10000</n32BaseHPRecover>
<n32BaseMPRecover>1200</n32BaseMPRecover>
<n32BaseReliveTime>3000</n32BaseReliveTime>
<n32ExpGrowth>10</n32ExpGrowth>
<n32PhyAttGrowth>10</n32PhyAttGrowth>
<n32MagAttGrowth>0</n32MagAttGrowth>
<n32PhyDefGrowth>4</n32PhyDefGrowth>
<n32MagDefGrowth>0</n32MagDefGrowth>
<n32MoveSpeedGrowth>0</n32MoveSpeedGrowth>
<n32AttackSpeedGrowth>20</n32AttackSpeedGrowth>
<n32MaxHPGrowth>100</n32MaxHPGrowth>
<n32MaxMPGrowth>30</n32MaxMPGrowth>
<n32HPRecoverGrowth>10000</n32HPRecoverGrowth>
<n32MPRecoverGrowth>200</n32MPRecoverGrowth>
<n32ReliveGrowth>500</n32ReliveGrowth>
<n32CPRecover>4</n32CPRecover>
<n32CollideRadious>50</n32CollideRadious>
<EmitPos>0,1300,0</EmitPos>
<HitPos>0,1300,0</HitPos>
<n32LockRadious>1</n32LockRadious>
<n32RandomAttack>attack,attack2,attack3</n32RandomAttack>
<un32WalkSound>0</un32WalkSound>
<un32DeathSould>Jinglingnan5_Dead</un32DeathSould>
<un32Script1>Jinglingnan_5_line_01,Jinglingnan_5_line_02</un32Script1>
<n32Script1Rate>90050,90050</n32Script1Rate>
<un32SkillType1>1200301</un32SkillType1>
<un32SkillType2>1200401</un32SkillType2>
<un32SkillType3>1300301</un32SkillType3>
<un32SkillType4>1300401</un32SkillType4>
<un32SkillType5>1100201</un32SkillType5>
<un32SkillType6>1100001</un32SkillType6>
<un32SkillTypeP>11000201</un32SkillTypeP>
<un32PreItem>0</un32PreItem>
<un32MidItem>0</un32MidItem>
<un32ProItem>0</un32ProItem>
</info>
*/
public class HeroConfigInfo: System.Object
{
#region 道具信息
public string HeroName;
public int HeroNum;
public int HeroMgicCate;
public float HeroXueTiaoHeight;
public float HeroAtkDis;
public float HeroBaseExp;
public float HeroPhyAtt;
public float HeroMagAtt;
public float HeroPhyDef;
public float HeroMagDef;
public float HeroMoveSpeed;
public float n32BaseMoveSpeedScaling;
public float HeroBaseAtkCd;
public float HeroMaxHp;
public float HeroMaxMp;
public float HeroHpRecover;
public float HeroMpRecover;
public float HeroRelieveTime;
public float HeroExpGrowth;
public float HeroPhyAttGrowth;
public float HeroMagAttGrowth;
public float HeroPhyDefGrowth;
public float HeroMagDefGrowth;
public float HeroAtkCdGrowth;
public float HeroMaxHpGrowth;
public float HeroMaxMpGrowth;
public float HeroHpRecoverGrowth;
public float HeroMpRecoverGrowth;
public float HeroReliveGrowth;
public float HeroCpRecover;
public float HeroCollideRadious;
public float n32LockRadious;
public string un32WalkSound;
public string HeroDeathsould;
public string HeroScript1;
public string HeroScript1Rate;
public int HeroSkillType1;
public int HeroSkillType2;
public int HeroSkillType3;
public int HeroSkillType4;
public int HeroSkillType5;
public int HeroSkillType6;
public int HeroSkillTypeP;
public List<string> n32RandomAttack;
public List<int> HeroPreEquip = new List<int> ();
public List<int> HeroMidEquip = new List<int> ();
public List<int> HeroLatEquip = new List<int> ();
public List<HeroType> heroKind = new List<HeroType> ();
#endregion
}