ConfigReader(三十三)—— ReadItemConfig

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

对应XML文件:
Assets/Resources/Config/ItemCfg.xml
这个配置文件非常大,部分如下:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ItemCfg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <info un32GoodsID="30001">
        <sNameID>item_rechp_1</sNameID>
        <sNameCh>生命药水</sNameCh>
        <un8TypeID>1</un8TypeID>
        <attributeKeyList>0</attributeKeyList>
        <attributeValList>0</attributeValList>
        <attributePerList>0</attributePerList>
        <un8UseTimes>1</un8UseTimes>
        <bDestroyAfterUsed>1</bDestroyAfterUsed>
        <un32SkillID>1600101</un32SkillID>
        <un32PassSkillID>0</un32PassSkillID>
        <bIsCanDeathToBuy>1</bIsCanDeathToBuy>
        <bUsedAfterBuyed>0</bUsedAfterBuyed>
        <sIcon>Dicon001</sIcon>
        <un32CdTime>20</un32CdTime>
        <bUniqueID>0</bUniqueID>
        <un8OverlapTimes>5</un8OverlapTimes>
        <un8CPCostType>1</un8CPCostType>
        <n32CPCost>80</n32CPCost>
        <n32CombineCPCost>0</n32CombineCPCost>
        <un8FunctionType>0</un8FunctionType>
        <un32UniqueTypeID>0</un32UniqueTypeID>
        <sDescribe>在20秒内恢复200点生命值</sDescribe>
        <un32UseSoundID>加血</un32UseSoundID>
    </info>
    <info un32GoodsID="30002">
        <sNameID>item_rechp_2</sNameID>
        <sNameCh>速效生命药水</sNameCh>
        <un8TypeID>1</un8TypeID>
        <attributeKeyList>0</attributeKeyList>
        <attributeValList>0</attributeValList>
        <attributePerList>0</attributePerList>
        <un8UseTimes>1</un8UseTimes>
        <bDestroyAfterUsed>1</bDestroyAfterUsed>
        <un32SkillID>1600201</un32SkillID>
        <un32PassSkillID>0</un32PassSkillID>
        <bIsCanDeathToBuy>1</bIsCanDeathToBuy>
        <bUsedAfterBuyed>0</bUsedAfterBuyed>
        <sIcon>Dicon002</sIcon>
        <un32CdTime>25</un32CdTime>
        <bUniqueID>0</bUniqueID>
        <un8OverlapTimes>5</un8OverlapTimes>
        <un8CPCostType>1</un8CPCostType>
        <n32CPCost>250</n32CPCost>
        <n32CombineCPCost>0</n32CombineCPCost>
        <un8FunctionType>0</un8FunctionType>
        <un32UniqueTypeID>0</un32UniqueTypeID>
        <sDescribe>瞬间恢复200点生命值</sDescribe>
        <un32UseSoundID>加血</un32UseSoundID>
    </info>
    <info un32GoodsID="30003">
        <sNameID>item_recmp_1</sNameID>
        <sNameCh>魔法药水</sNameCh>
        <un8TypeID>1</un8TypeID>
        <attributeKeyList>0</attributeKeyList>
        <attributeValList>0</attributeValList>
        <attributePerList>0</attributePerList>
        <un8UseTimes>1</un8UseTimes>
        <bDestroyAfterUsed>1</bDestroyAfterUsed>
        <un32SkillID>1600301</un32SkillID>
        <un32PassSkillID>0</un32PassSkillID>
        <bIsCanDeathToBuy>1</bIsCanDeathToBuy>
        <bUsedAfterBuyed>0</bUsedAfterBuyed>
        <sIcon>Dicon003</sIcon>
        <un32CdTime>20</un32CdTime>
        <bUniqueID>0</bUniqueID>
        <un8OverlapTimes>5</un8OverlapTimes>
        <un8CPCostType>1</un8CPCostType>
        <n32CPCost>80</n32CPCost>
        <n32CombineCPCost>0</n32CombineCPCost>
        <un8FunctionType>0</un8FunctionType>
        <un32UniqueTypeID>0</un32UniqueTypeID>
        <sDescribe>在20秒内恢复80点魔法值</sDescribe>
        <un32UseSoundID>0</un32UseSoundID>
    </info>

ReadItemConfig.cs

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

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

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

        for (int i = 0; i < infoNodeList.Count; i++)
        {
            XmlAttribute xmlAttr = (infoNodeList [i] as XmlElement).GetAttributeNode ("un32GoodsID");
            if (xmlAttr == null)
            {
                continue;
            }

            string itemId = xmlAttr.InnerText;
            ItemConfigInfo itemInfo = new ItemConfigInfo ();
            itemInfo.GoodsId = Convert.ToInt32 (itemId);

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

                case "sNameCh":
                    itemInfo.sNameCh = xEle.InnerText;
                    break;

                case "un8TypeID":
                    itemInfo.un8typeID = Convert.ToInt32 (xEle.InnerText);
                    break;

                case "attributeKeyList":
                    itemInfo.attributeKeyList = GameDefine.GameMethod.ResolveToIntList (xEle.InnerText);
                    break;

                case "attributeValList":
                    itemInfo.attributeValList = GameDefine.GameMethod.ResolveToFloatList (xEle.InnerText);
                    break;

                case "un8UseTimes":
                    itemInfo.un8UseTimes = Convert.ToInt32 (xEle.InnerText);
                    break;

                case "bDestroyAfterUsed":
                    itemInfo.bDestroyAfterUsed = Convert.ToInt32 (xEle.InnerText);
                    break;

                case "un32SkillID":
                    itemInfo.un32SkillID = Convert.ToInt32 (xEle.InnerText);
                    break;

                case "bUsedAfterBuyed":
                    itemInfo.bUsedAfterBuyed = Convert.ToInt32 (xEle.InnerText);
                    break;

                case "sIcon":
                    itemInfo.sIcon = xEle.InnerText;
                    break;

                case "un32CdTime":
                    itemInfo.un32CdTime = Convert.ToSingle (xEle.InnerText);
                    break;

                case "bUniqueID":
                    itemInfo.bUniqueID = Convert.ToInt32 (xEle.InnerText);
                    break;

                case "un8OverlapTimes":
                    itemInfo.un8OvertlapTimes = Convert.ToInt32 (xEle.InnerText);
                    break;

                case "un8CPCostType":
                    itemInfo.un8CPCostType = Convert.ToInt32 (xEle.InnerText);
                    break;

                case "n32CPCost":
                    itemInfo.n32CPCost = Convert.ToInt32 (xEle.InnerText);
                    break;

                case "un8FunctionType":
                    itemInfo.un8FunctionType = Convert.ToInt32 (xEle.InnerText);
                    break;

                case "un32UniqueTypeID":
                    itemInfo.un32UniqueTypeID = Convert.ToInt32 (xEle.InnerText);
                    break;

                case "sDescribe":
                    itemInfo.sDescribe = xEle.InnerText;
                    break;

                case "un32UseSoundID":
                    itemInfo.un32UseSoundID = xEle.InnerText;
                }
            }

            ConfigReader.itemXmlInfoDict.Add (itemInfo.GoodsId, itemInfo);
        }
    }
}

/*
对应的Item配置文件很大
XML格式:
<info un32GoodsID="30001">
        <sNameID>item_rechp_1</sNameID>
        <sNameCh>生命药水</sNameCh>
        <un8TypeID>1</un8TypeID>
        <attributeKeyList>0</attributeKeyList>
        <attributeValList>0</attributeValList>
        <attributePerList>0</attributePerList>
        <un8UseTimes>1</un8UseTimes>
        <bDestroyAfterUsed>1</bDestroyAfterUsed>
        <un32SkillID>1600101</un32SkillID>
        <un32PassSkillID>0</un32PassSkillID>
        <bIsCanDeathToBuy>1</bIsCanDeathToBuy>
        <bUsedAfterBuyed>0</bUsedAfterBuyed>
        <sIcon>Dicon001</sIcon>
        <un32CdTime>20</un32CdTime>
        <bUniqueID>0</bUniqueID>
        <un8OverlapTimes>5</un8OverlapTimes>
        <un8CPCostType>1</un8CPCostType>
        <n32CPCost>80</n32CPCost>
        <n32CombineCPCost>0</n32CombineCPCost>
        <un8FunctionType>0</un8FunctionType>
        <un32UniqueTypeID>0</un32UniqueTypeID>
        <sDescribe>在20秒内恢复200点生命值</sDescribe>
        <un32UseSoundID>加血</un32UseSoundID>
    </info>
*/
public class ItemConfigInfo: System.Object
{
    public int GoodsId;
    public string sNameID;
    public string sNameCh;
    public int un8typeID;
    public List<int> attributeKeyList;
    public List<float> attributeValList;
    public int un8UseTimes;
    public int bDestroyAfterUsed;
    public int un32SkillID;
    public int bUsedAfterBuyed;
    public string sIcon;
    public int bUniqueID;
    public int un8OvertlapTimes;
    public int un8CPCostType;
    public int n32CPCost;
    public int un8FunctionType;
    public int un32UniqueTypeID;
    public string sDescribe;
    public string un32UseSoundID;
    public float un32CdTime;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值