ConfigReader(五十一)—— ReadSkillEmitConfig

本文介绍了一个用于读取游戏技能配置文件的C#类ReadSkillEmitConfig。该类从指定的XML文件中读取发射系技能的各项参数,并将其解析成SkillEmitConfig对象,方便在游戏中使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录为: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;     //是否穿透
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值