目录为:Assets/Scripts/ConfigReader/目录下
ReadSkillEmitConfig.cs
读取发射系技能配置
对应配置文件:
Assets/Resources/Config/SKillCfg_emit.xml
部分如下:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<SkillCfg_emit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<info un32ID="130001">
<szName>冻法师攻击</szName>
<n32UseMP>0</n32UseMP>
<n32UseHP>0</n32UseHP>
<n32UseCP>0</n32UseCP>
<bIsCoolDown>1</bIsCoolDown>
<bIsCanMove>1</bIsCanMove>
<bIsCanBreak>1</bIsCanBreak>
<n32TriggerRate>1000</n32TriggerRate>
<bIfAffectBuilding>1</bIfAffectBuilding>
<bIfAffectHero>1</bIfAffectHero>
<bIfAffectMonster>1</bIfAffectMonster>
<EmitTarget>2</EmitTarget>
<EmitType>1</EmitType>
<FlySpeed>2700</FlySpeed>
<FlyPar1>0</FlyPar1>
<FlyPar2>0</FlyPar2>
<FlyPar3>0</FlyPar3>
<n32ProjectileNum>1</n32ProjectileNum>
<n32ProjEmitInter>0</n32ProjEmitInter>
<bIsPenetrate>0</bIsPenetrate>
<eCollideRadius>100</eCollideRadius>
<eLifeTime>3000</eLifeTime>
<attackEffect>bingqiutuowei2</attackEffect>
<FlySound>Dongfashi5_Attack</FlySound>
<EventID>120001</EventID>
</info>
<info un32ID="130002">
<szName>飞龙攻击</szName>
<n32UseMP>0</n32UseMP>
<n32UseHP>0</n32UseHP>
<n32UseCP>0</n32UseCP>
<bIsCoolDown>1</bIsCoolDown>
<bIsCanMove>1</bIsCanMove>
<bIsCanBreak>1</bIsCanBreak>
<n32TriggerRate>1000</n32TriggerRate>
<bIfAffectBuilding>1</bIfAffectBuilding>
<bIfAffectHero>1</bIfAffectHero>
<bIfAffectMonster>1</bIfAffectMonster>
<EmitTarget>2</EmitTarget>
<EmitType>1</EmitType>
<FlySpeed>2700</FlySpeed>
<FlyPar1>0</FlyPar1>
<FlyPar2>0</FlyPar2>
<FlyPar3>0</FlyPar3>
<n32ProjectileNum>1</n32ProjectileNum>
<n32ProjEmitInter>0</n32ProjEmitInter>
<bIsPenetrate>0</bIsPenetrate>
<eCollideRadius>100</eCollideRadius>
<eLifeTime>3000</eLifeTime>
<attackEffect>firerotate</attackEffect>
<FlySound>Feilong5_Attack</FlySound>
<EventID>120003</EventID>
</info>
ReadSkillEmitConfig.cs
using System;
using UnityEngine;
using System.Xml;
using System.Collections.Generic;
//读取发射系技能配置
//对应配置文件:Assets/Resources/Config/SKillCfg_emit.xml
public class ReadSkillEmitConfig
{
XmlDocument xmlDoc = null;
//构造函数
public ReadSkillEmitConfig(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 ("SkillCfg_emit").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;
SkillEmitConfig skillInfo = new SkillEmitConfig ();
skillInfo.id = (uint)Convert.ToUInt32 (typeName);
foreach (XmlElement xEle in infoNodeList[i].ChildNodes)
{
switch (xEle.Name)
{
case "szName":
skillInfo.name = Convert.ToString (xEle.InnerText);
break;
case "EmitType":
skillInfo.emitType = Convert.ToInt32 (xEle.InnerText);
break;
case "FlySpeed":
skillInfo.flySpeed = Convert.ToInt32 (xEle.InnerText);
break;
case "attackEffect":
skillInfo.effect = Convert.ToString (xEle.InnerText);
break;
case "FlySound":
skillInfo.sound = Convert.ToString (xEle.InnerText);
break;
case "eLifeTime":
skillInfo.lifeTime = Convert.ToInt32 (xEle.InnerText) / 1000.0f;
break;
case "bIsPenetrate":
skillInfo.isPenetrate = Convert.ToInt32 (xEle.InnerText);
break;
}
}
ConfigReader.skillEmitXmlInfoDic.Add (skillInfo.id, skillInfo);
}
}
}
/*
XML格式:
<info un32ID="131020">
<szName>剧毒之种等级2</szName>
<n32UseMP>0</n32UseMP>
<n32UseHP>0</n32UseHP>
<n32UseCP>0</n32UseCP>
<bIsCoolDown>1</bIsCoolDown>
<bIsCanMove>1</bIsCanMove>
<bIsCanBreak>1</bIsCanBreak>
<n32TriggerRate>1000</n32TriggerRate>
<bIfAffectBuilding>0</bIfAffectBuilding>
<bIfAffectHero>1</bIfAffectHero>
<bIfAffectMonster>1</bIfAffectMonster>
<EmitTarget>2</EmitTarget>
<EmitType>1</EmitType>
<FlySpeed>3000</FlySpeed>
<FlyPar1>0</FlyPar1>
<FlyPar2>0</FlyPar2>
<FlyPar3>0</FlyPar3>
<n32ProjectileNum>1</n32ProjectileNum>
<n32ProjEmitInter>0</n32ProjEmitInter>
<bIsPenetrate>0</bIsPenetrate>
<eCollideRadius>100</eCollideRadius>
<eLifeTime>4000</eLifeTime>
<attackEffect>poisonseed</attackEffect>
<FlySound>Zhizhu5_Skill 1</FlySound>
<EventID>160038</EventID>
</info>
*/
public class SkillEmitConfig
{
public uint id; //id
public int emitType; //发射类型
public float floatSpeed; //飞行速度
public string name; //名字
public string effect; //特效
public string sound; //声音
public float lifeTime; //声明周期
public int isPenetrate; //是否穿透
}