ConfigReader(四)—— ReadBuffConfig

目录为:Assets/Scripts/ConfigReader/目录下
ReadBuffConfig.cs
这里读取的配置文件是技能buff相关的。

先来看看配置文件,配置文件在编辑器内的目录为:
Assets/Resources/Config/SkillCfg_buff.xml
因为太长了就只截取两段吧。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<SkillCfg_buff xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <info un32ID="169999">
        <szName>隐身测试</szName>
        <n32UseMP>0</n32UseMP>
        <n32UseHP>0</n32UseHP>
        <n32UseCP>0</n32UseCP>
        <bIsCoolDown>1</bIsCoolDown>
        <n32TriggerRate>1000</n32TriggerRate>
        <bIfAffectBuilding>0</bIfAffectBuilding>
        <bIfAffectHero>1</bIfAffectHero>
        <bIfAffectMonster>0</bIfAffectMonster>
        <eBuffType>1</eBuffType>
        <eBuffTarget>2</eBuffTarget>
        <eTargetType>1</eTargetType>
        <eEffect0LastTick>10000</eEffect0LastTick>
        <eEffect0EffectInterval>0</eEffect0EffectInterval>
        <n32ReplaceType>2</n32ReplaceType>
        <n32RepeatTimes>1</n32RepeatTimes>
        <n32RejectID>0</n32RejectID>
        <n32ReplaceID>0</n32ReplaceID>
        <bEffect0ClearWhenDie>1</bEffect0ClearWhenDie>
        <szEffectIcon>0</szEffectIcon>
        <szEffectSound>0</szEffectSound>
        <szEffectDes>0</szEffectDes>
        <szEffection>yinshen</szEffection>
        <n32EffectID>27</n32EffectID>
        <eEffectValue>1</eEffectValue>
        <eEffectRate>0</eEffectRate>
        <eFlyEffectID>0</eFlyEffectID>
        <StartEventID>0</StartEventID>
        <IntervalEventID>0</IntervalEventID>
        <EndEventID>0</EndEventID>
    </info>
    <info un32ID="169998">
        <szName>隐身测试-被动</szName>
        <n32UseMP>0</n32UseMP>
        <n32UseHP>0</n32UseHP>
        <n32UseCP>0</n32UseCP>
        <bIsCoolDown>0</bIsCoolDown>
        <n32TriggerRate>1000</n32TriggerRate>
        <bIfAffectBuilding>0</bIfAffectBuilding>
        <bIfAffectHero>1</bIfAffectHero>
        <bIfAffectMonster>0</bIfAffectMonster>
        <eBuffType>1</eBuffType>
        <eBuffTarget>2</eBuffTarget>
        <eTargetType>1</eTargetType>
        <eEffect0LastTick>10000</eEffect0LastTick>
        <eEffect0EffectInterval>0</eEffect0EffectInterval>
        <n32ReplaceType>2</n32ReplaceType>
        <n32RepeatTimes>1</n32RepeatTimes>
        <n32RejectID>0</n32RejectID>
        <n32ReplaceID>0</n32ReplaceID>
        <bEffect0ClearWhenDie>1</bEffect0ClearWhenDie>
        <szEffectIcon>0</szEffectIcon>
        <szEffectSound>0</szEffectSound>
        <szEffectDes>0</szEffectDes>
        <szEffection>0</szEffection>
        <n32EffectID>26</n32EffectID>
        <eEffectValue>11399901</eEffectValue>
        <eEffectRate>0</eEffectRate>
        <eFlyEffectID>0</eFlyEffectID>
        <StartEventID>0</StartEventID>
        <IntervalEventID>0</IntervalEventID>
        <EndEventID>0</EndEventID>
    </info>
    <info/>

然后是ReadBuffConfig.cs

using System;
using UnityEngine;
using System.Xml;
using System.Collections.Generic;

//这个类读的配置文件是跟技能buff相关的,但是这里只读取了一部分
//这个类要读的文件在编辑器内的路径为:Assets/Resources/Config/SkillCfg_buff
public class ReadBuffConfig
{
    XmlDocument xmlDoc = null;

    //构造函数
    public ReadBuffConfig()
    {

    }

    //构造函数
    public ReadBuffConfig(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 ();
        //Load XML
        xmlDoc.LoadXml (xmlfile.text);

        XmlNodeList infoNodeList = xmlDoc.SelectSingleNode ("SkillCfg_buff").ChildNodes;
        for (int i = 0; i < infoNodeList.Count; i++)
        {
            //(XmlNode xNode in infoNodeList)
            if ((infoNodeList[i] as XmlElement).GetAttributeNode("un32ID") == null)
            {
                continue;
            }

            string typeName = (infoNodeList [i] as XmlElement).GetAttributeNode ("un32ID").InnerText;

            BuffConfigInfo buffInfo = new BuffConfigInfo ();
            buffInfo.BuffID = Convert.ToUInt32 (typeName);

            foreach (XmlElement xEle in infoNodeList[i].ChildNodes)
            {
                #region 搜索
                switch (xEle.Name)
                {
                case "szName":
                    buffInfo.BUffName = Convert.ToString(xEle.InnerText);
                    break;

                case "szEffectIcon":
                    buffInfo.IconRes = Convert.ToString(xEle.InnerText);
                    break;

                case "n32EffectID":
                    buffInfo.effectID = Convert.ToInt32(xEle.InnerText);
                    break;

                case "szEffection":
                    buffInfo.EffectRes = Convert.ToString(xEle.InnerText);
                    break;

                case "eEffect0LastTick":
                    buffInfo.TotalTime = Convert.ToInt32(xEle.InnerText) / 1000.0f;
                    break;

                case "szEffectSound":
                    buffInfo.sound = Convert.ToString(xEle.InnerText);
                    break;

                case "eFlyEffectID":
                    buffInfo.eFlyEffectID = Convert.ToInt32(xEle.InnerText);
                    break;
                }
                #endregion
            }

            ConfigReader.buffXmlInfoDict.Add (buffInfo.BuffID, buffInfo);
        }
    }

}

/*
这是这个xml文件的结构
<info un32ID="169999">
    <szName>隐身测试</szName>
    <n32UseMP>0</n32UseMP>
    <n32UseHP>0</n32UseHP>
    <n32UseCP>0</n32UseCP>
    <bIsCoolDown>1</bIsCoolDown>
    <n32TriggerRate>1000</n32TriggerRate>
    <bIfAffectBuilding>0</bIfAffectBuilding>
    <bIfAffectHero>1</bIfAffectHero>
    <bIfAffectMonster>0</bIfAffectMonster>
    <eBuffType>1</eBuffType>
    <eBuffTarget>2</eBuffTarget>
    <eTargetType>1</eTargetType>
    <eEffect0LastTick>10000</eEffect0LastTick>
    <eEffect0EffectInterval>0</eEffect0EffectInterval>
    <n32ReplaceType>2</n32ReplaceType>
    <n32RepeatTimes>1</n32RepeatTimes>
    <n32RejectID>0</n32RejectID>
    <n32ReplaceID>0</n32ReplaceID>
    <bEffect0ClearWhenDie>1</bEffect0ClearWhenDie>
    <szEffectIcon>0</szEffectIcon>
    <szEffectSound>0</szEffectSound>
    <szEffectDes>0</szEffectDes>
    <szEffection>yinshen</szEffection>
    <n32EffectID>27</n32EffectID>
    <eEffectValue>1</eEffectValue>
    <eEffectRate>0</eEffectRate>
    <eFlyEffectID>0</eFlyEffectID>
    <StartEventID>0</StartEventID>
    <IntervalEventID>0</IntervalEventID>
    <EndEventID>0</EndEventID>
</info>
*/
//看来这里只读取一部分
public class BuffConfigInfo: System.Object
{
    public uint BuffID;
    public string BUffName;
    public string IconRes;
    public string EffectRes;
    public int effectID;
    public float TotalTime;
    public string sound;
    public int eFlyEffectID;        //buff后续击飞效果id
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值