ConfigReader(三十)—— ReadHeroSkinConfig

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

英雄皮肤相关

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

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<SkinCfg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <info un32ID="110001">
        <SkinName>精灵之翼(默认)</SkinName>
        <n32Level>0</n32Level>
        <un8ConsumeType>0</un8ConsumeType>
        <n32Price>0</n32Price>
        <Time>0</Time>
        <Description>0</Description>
        <Icon>32</Icon>
        <ResourcesID>0</ResourcesID>
        <Skill1Effect>0</Skill1Effect>
        <Skill2Effect>0</Skill2Effect>
    </info>
    <info un32ID="110002">
        <SkinName>精灵之翼(默认)</SkinName>
        <n32Level>0</n32Level>
        <un8ConsumeType>0</un8ConsumeType>
        <n32Price>0</n32Price>
        <Time>0</Time>
        <Description>0</Description>
        <Icon>16</Icon>
        <ResourcesID>0</ResourcesID>
        <Skill1Effect>0</Skill1Effect>
        <Skill2Effect>0</Skill2Effect>
    </info>

ReadHeroSkinConfig.cs

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

//英雄皮肤
//Assets/Resources/Config/skinCfg.xml
public class ReadHeroSkinConfig
{
    XmlDocument xmlDoc = null;

    public ReadHeroSkinConfig(string xmlFilePath)
    {
        ResourceUnit xmlfileUnit = ResourcesManager.Instance.loadImmediate (xmlFilePath);
        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 ("SkinCfg").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;

            HeroSkinConfigInfo heroSkinInfo = new HeroSkinConfigInfo ();
            heroSkinInfo.GoodsId = Convert.ToInt32 (typeName);
            string un8ConsumeType = "";
            string n32Price = "";

            foreach (XmlElement xEle in infoNodeList[i].ChildNodes)
            {
                switch (xEle.Name)
                {
                case "SkinName":
                    heroSkinInfo.SkinName = Convert.ToString (xEle.InnerText);
                    break;

                case "un8ConsumeType":
                    un8ConsumeType = Convert.ToString (xEle.InnerText);
                    break;

                case "n32Price":
                    n32Price = Convert.ToString (xEle.InnerText);
                    break;

                case "Description":
                    heroSkinInfo.Description = Convert.ToString (xEle.InnerText);
                    break;

                case "Time":
                    heroSkinInfo.Time = Convert.ToInt32 (xEle.InnerText);
                    break;

                case "Icon":
                    heroSkinInfo.Icon = Convert.ToString (xEle.InnerText);
                    break;

                case "ResourcesID":
                    heroSkinInfo.ResourcesID = Convert.ToString (xEle.InnerText);
                    break;

                case "Skill1Effect":
                    heroSkinInfo.Skill1Effect = Convert.ToString (xEle.InnerText);
                    break;

                case "Skill2Effect":
                    heroSkinInfo.Skill2Effect = Convert.ToString (xEle.InnerText);
                    break;
                }
            }

            heroSkinInfo.Consume = GameMethod.ResolveToIntDict (un8ConsumeType, n32Price);
            ConfigReader.heroSkinXmlInfoDict.Add (heroSkinInfo.GoodsId, heroSkinInfo);
        }
    }
}

/*
XML格式:
<info un32ID="110001">
    <SkinName>精灵之翼(默认)</SkinName>
    <n32Level>0</n32Level>
    <un8ConsumeType>0</un8ConsumeType>
    <n32Price>0</n32Price>
    <Time>0</Time>
    <Description>0</Description>
    <Icon>32</Icon>
    <ResourcesID>0</ResourcesID>
    <Skill1Effect>0</Skill1Effect>
    <Skill2Effect>0</Skill2Effect>
</info>
*/
public class HeroSkinConfigInfo: System.Object
{
    #region 道具信息
    public int GoodsId;
    public string SkinName;
    public Dictionary<int, int> Consume;
    public int Time;
    public string Description;
    public string Icon;
    public string ResourcesID;
    public string Skill1Effect;
    public string Skill2Effect;
    #endregion
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值