ConfigReader(五十三)—— ReadSkillLeadingConfig

目录为:Assets/Scripts/ConfigReader/目录下
ReadSkillLeadingConfig.cs

对应配置文件:
Assets/Resources/Config/SkillCfg_leading.xml
部分如下:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<SkillCfg_leading xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <info un32ID="150001">
        <szName>暴风雪等级1</szName>
        <n32UseMP>0</n32UseMP>
        <n32UseHP>0</n32UseHP>
        <n32UseCP>0</n32UseCP>
        <bIsCoolDown>1</bIsCoolDown>
        <n32TriggerRate>1000</n32TriggerRate>
        <bIfAffectBuilding>0</bIfAffectBuilding>
        <bIfAffectHero>1</bIfAffectHero>
        <bIfAffectMonster>1</bIfAffectMonster>
        <eTargetType>2</eTargetType>
        <eLeadingTime>4100</eLeadingTime>
        <eLeadingAction>skill</eLeadingAction>
        <eLeadingEffect>0</eLeadingEffect>
        <eLeadingSound>0</eLeadingSound>
        <bIsCanMove>0</bIsCanMove>
        <bIsCheckTargetSta>0</bIsCheckTargetSta>
        <EventID>0</EventID>
    </info>
    <info un32ID="150002">
        <szName>暴风雪等级2</szName>
        <n32UseMP>0</n32UseMP>
        <n32UseHP>0</n32UseHP>
        <n32UseCP>0</n32UseCP>
        <bIsCoolDown>1</bIsCoolDown>
        <n32TriggerRate>1000</n32TriggerRate>
        <bIfAffectBuilding>0</bIfAffectBuilding>
        <bIfAffectHero>1</bIfAffectHero>
        <bIfAffectMonster>1</bIfAffectMonster>
        <eTargetType>2</eTargetType>
        <eLeadingTime>4100</eLeadingTime>
        <eLeadingAction>skill</eLeadingAction>
        <eLeadingEffect>0</eLeadingEffect>
        <eLeadingSound>0</eLeadingSound>
        <bIsCanMove>0</bIsCanMove>
        <bIsCheckTargetSta>0</bIsCheckTargetSta>
        <EventID>0</EventID>
    </info>
    <info un32ID="150003">
        <szName>暴风雪等级3</szName>
        <n32UseMP>0</n32UseMP>
        <n32UseHP>0</n32UseHP>
        <n32UseCP>0</n32UseCP>
        <bIsCoolDown>1</bIsCoolDown>
        <n32TriggerRate>1000</n32TriggerRate>
        <bIfAffectBuilding>0</bIfAffectBuilding>
        <bIfAffectHero>1</bIfAffectHero>
        <bIfAffectMonster>1</bIfAffectMonster>
        <eTargetType>2</eTargetType>
        <eLeadingTime>4100</eLeadingTime>
        <eLeadingAction>skill</eLeadingAction>
        <eLeadingEffect>0</eLeadingEffect>
        <eLeadingSound>0</eLeadingSound>
        <bIsCanMove>0</bIsCanMove>
        <bIsCheckTargetSta>0</bIsCheckTargetSta>
        <EventID>0</EventID>
    </info>

ReadSkillLeadingConfig.cs

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

//对应配置文件:Assets/Resources/Config/SkillCfg_leading.xml
public class ReadSkillLeadingConfig
{
    XmlDocument xmlDoc = null;

    //构造函数
    public ReadSkillLeadingConfig(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_leading").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;
            SkillLeadingConfig skillInfo = new SkillLeadingConfig ();
            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 "eLeadingTime":
                    skillInfo.time = Convert.ToInt32 (xEle.InnerText) / 1000.0f;
                    break;

                case "eLeadingAction":
                    skillInfo.action = Convert.ToString (xEle.InnerText);
                    break;

                case "eLeadingSound":
                    skillInfo.sound = Convert.ToString (xEle.InnerText);
                    break;

                case "eLeadingEffect":
                    skillInfo.effect = Convert.ToString (xEle.InnerText);
                    break;
                }
            }

            ConfigReader.skillLeadingInfoDic.Add (skillInfo.id, skillInfo);
        }
    }
}

/*
XML格式:
<info un32ID="150015">
        <szName>刃雨等级2</szName>
        <n32UseMP>0</n32UseMP>
        <n32UseHP>0</n32UseHP>
        <n32UseCP>0</n32UseCP>
        <bIsCoolDown>1</bIsCoolDown>
        <n32TriggerRate>1000</n32TriggerRate>
        <bIfAffectBuilding>0</bIfAffectBuilding>
        <bIfAffectHero>1</bIfAffectHero>
        <bIfAffectMonster>1</bIfAffectMonster>
        <eTargetType>2</eTargetType>
        <eLeadingTime>1800</eLeadingTime>
        <eLeadingAction>skill2</eLeadingAction>
        <eLeadingEffect>0</eLeadingEffect>
        <eLeadingSound>0</eLeadingSound>
        <bIsCanMove>0</bIsCanMove>
        <bIsCheckTargetSta>0</bIsCheckTargetSta>
        <EventID>0</EventID>
    </info>
*/
public class SkillLeadingConfig
{
    public uint id;
    public string name;
    public float time;
    public string action;
    public string sound;
    public string effect;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当使用 ConfigReader 获取中文时出现乱码,可能是以下原因导致的: 1. 配置文件编码问题:配置文件的编码格式不是 UTF-8,而 ConfigReader 默认使用的编码格式是 UTF-8。可以尝试将配置文件的编码格式转换为 UTF-8,或者在 ConfigReader 中指定配置文件的编码格式。 2. Java 代码编码问题:Java 代码的编码格式不是 UTF-8,而 ConfigReader 默认使用的编码格式是 UTF-8。可以尝试将 Java 代码的编码格式转换为 UTF-8,或者在 Java 代码中指定编码格式。 3. 操作系统编码问题:操作系统的编码格式不是 UTF-8,而 ConfigReader 默认使用的编码格式是 UTF-8。可以尝试将操作系统的编码格式设置为 UTF-8,或者在 ConfigReader 中指定操作系统的编码格式。 针对以上问题,可以尝试以下解决方案: 1. 在 ConfigReader 中指定配置文件的编码格式,例如: ```java ConfigReader reader = new ConfigReader("config.properties", "GBK"); ``` 2. 在 Java 代码中指定编码格式,例如: ```java System.setProperty("file.encoding", "GBK"); ``` 3. 在操作系统中设置编码格式为 UTF-8,例如: - Windows 系统:在注册表中创建以下键值,将其值设置为 UTF-8: ``` HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage\OEMCP ``` - Linux 系统:在 /etc/environment 文件中添加以下行: ``` LANG=en_US.UTF-8 ``` 通过以上方法,可以解决 ConfigReader 获取中文乱码的问题。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值