ConfigReader(四十一)—— ReadOtherItemConfig

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

对应配置文件:Assets/Resources/Config/OtherItemCfg.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<OtherItemCfg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <info ID="130001">
        <Name>双倍金币卡(1天)</Name>
        <EffectID>1001</EffectID>
        <EffectValue>100</EffectValue>
        <ConsumeType>0</ConsumeType>
        <PriceSeries>0</PriceSeries>
        <bIsGetUse>1</bIsGetUse>
        <bIsShowInShop>0</bIsShowInShop>
        <Time>24</Time>
        <Icon>11</Icon>
    </info>
    <info ID="130002">
        <Name>双倍经验卡(1天)</Name>
        <EffectID>1002</EffectID>
        <EffectValue>100</EffectValue>
        <ConsumeType>0</ConsumeType>
        <PriceSeries>0</PriceSeries>
        <bIsGetUse>1</bIsGetUse>
        <bIsShowInShop>0</bIsShowInShop>
        <Time>24</Time>
        <Icon>12</Icon>
    </info>
    <info ID="130003">
        <Name>全英雄体验卷(1天)</Name>
        <EffectID>1003</EffectID>
        <EffectValue>1</EffectValue>
        <ConsumeType>0</ConsumeType>
        <PriceSeries>0</PriceSeries>
        <bIsGetUse>1</bIsGetUse>
        <bIsShowInShop>0</bIsShowInShop>
        <Time>24</Time>
        <Icon>8</Icon>
    </info>
    <info ID="130004">
        <Name>单英雄体验卷(1天)</Name>
        <EffectID>1004</EffectID>
        <EffectValue>1</EffectValue>
        <ConsumeType>0</ConsumeType>
        <PriceSeries>0</PriceSeries>
        <bIsGetUse>0</bIsGetUse>
        <bIsShowInShop>0</bIsShowInShop>
        <Time>72</Time>
        <Icon>0</Icon>
    </info>
    <info ID="130005">
        <Name>一级洗炼卷</Name>
        <EffectID>1005</EffectID>
        <EffectValue>1</EffectValue>
        <ConsumeType>1</ConsumeType>
        <PriceSeries>3</PriceSeries>
        <bIsGetUse>0</bIsGetUse>
        <bIsShowInShop>0</bIsShowInShop>
        <Time>-1</Time>
        <Icon>1</Icon>
    </info>
    <info ID="130006">
        <Name>二级洗炼卷</Name>
        <EffectID>1005</EffectID>
        <EffectValue>2</EffectValue>
        <ConsumeType>1</ConsumeType>
        <PriceSeries>10</PriceSeries>
        <bIsGetUse>0</bIsGetUse>
        <bIsShowInShop>0</bIsShowInShop>
        <Time>-1</Time>
        <Icon>2</Icon>
    </info>
    <info ID="130007">
        <Name>三级洗炼卷</Name>
        <EffectID>1005</EffectID>
        <EffectValue>3</EffectValue>
        <ConsumeType>1</ConsumeType>
        <PriceSeries>30</PriceSeries>
        <bIsGetUse>0</bIsGetUse>
        <bIsShowInShop>0</bIsShowInShop>
        <Time>-1</Time>
        <Icon>3</Icon>
    </info>
    <info ID="130008">
        <Name>四级洗炼卷</Name>
        <EffectID>1005</EffectID>
        <EffectValue>4</EffectValue>
        <ConsumeType>1</ConsumeType>
        <PriceSeries>70</PriceSeries>
        <bIsGetUse>0</bIsGetUse>
        <bIsShowInShop>0</bIsShowInShop>
        <Time>-1</Time>
        <Icon>4</Icon>
    </info>
    <info ID="130009">
        <Name>五级洗炼卷</Name>
        <EffectID>1005</EffectID>
        <EffectValue>5</EffectValue>
        <ConsumeType>1</ConsumeType>
        <PriceSeries>200</PriceSeries>
        <bIsGetUse>0</bIsGetUse>
        <bIsShowInShop>0</bIsShowInShop>
        <Time>-1</Time>
        <Icon>5</Icon>
    </info>
    <info ID="130010">
        <Name>六级洗炼卷</Name>
        <EffectID>1005</EffectID>
        <EffectValue>6</EffectValue>
        <ConsumeType>1</ConsumeType>
        <PriceSeries>480</PriceSeries>
        <bIsGetUse>0</bIsGetUse>
        <bIsShowInShop>0</bIsShowInShop>
        <Time>-1</Time>
        <Icon>6</Icon>
    </info>
    <info ID="130011">
        <Name>符文页</Name>
        <EffectID>1006</EffectID>
        <EffectValue>1</EffectValue>
        <ConsumeType>2</ConsumeType>
        <PriceSeries>238</PriceSeries>
        <bIsGetUse>1</bIsGetUse>
        <bIsShowInShop>0</bIsShowInShop>
        <Time>-1</Time>
        <Icon>0</Icon>
    </info>
</OtherItemCfg>

ReadOtherItemConfig.cs

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

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

    //构造函数
    public ReadOtherItemConfig (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 ("OtherItemCfg").ChildNodes;

        for (int i = 0; i < infoNodeList.Count; i++)
        {
            XmlAttribute xmlAttr = (infoNodeList [i] as XmlElement).GetAttributeNode ("ID");

            if (xmlAttr == null)
            {
                continue;
            }

            OtherItemConfigInfo otherItemInfo = new OtherItemConfigInfo ();

            foreach (XmlElement xEle in infoNodeList[i].ChildNodes)
            {
                switch (xEle.Name)
                {
                case "Name":
                    otherItemInfo.sName = xEle.InnerText;
                    break;

                case "EffectID":
                    otherItemInfo.effectid = Convert.ToUInt32 (xEle.InnerText);
                    break;

                case "EffectValue":
                    otherItemInfo.effectValue = Convert.ToUInt32 (xEle.InnerText);
                    break;

                case "ConsumeType":
                    otherItemInfo.consumetpye = Convert.ToUInt32 (xEle.InnerText);
                    break;

                case "PriceSeries":
                    otherItemInfo.priceseries = Convert.ToUInt32 (xEle.InnerText);
                    break;

                case "bIsShowInShop":
                    otherItemInfo.isShowInShop = Convert.ToUInt32 (xEle.InnerText);
                    break;

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

                case "Icon":
                    otherItemInfo.icon = xEle.InnerText;
                    break;
                }
            }

            ConfigReader.otherItemXmlInfoDic.Add (Convert.ToUInt32 (xmlAttr.InnerText), otherItemInfo);
        }
    }
}

/*
XML格式:
<info ID="130009">
        <Name>五级洗炼卷</Name>
        <EffectID>1005</EffectID>
        <EffectValue>5</EffectValue>
        <ConsumeType>1</ConsumeType>
        <PriceSeries>200</PriceSeries>
        <bIsGetUse>0</bIsGetUse>
        <bIsShowInShop>0</bIsShowInShop>
        <Time>-1</Time>
        <Icon>5</Icon>
    </info>
*/
public class OtherItemConfigInfo: System.Object
{
    public string sName;
    public uint effectid;
    public uint effectValue;
    public uint consumetpye;
    public uint priceseries;
    public bool isShowInShop;
    public int time;
    public string icon;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值