ConfigReader(七)—— ReadDailyBonusConfig

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

这里主要读取关于日常奖励的Config文件

对应读取的XML文件为:
Assets/Resources/Config/
dailybonus.xml

一部分如下:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<DailyBonus xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <info n32Days="1">
        <n32Type>1</n32Type>
        <n32ItemID>2</n32ItemID>
        <n32ItemNum>120</n32ItemNum>
    </info>
    <info n32Days="2">
        <n32Type>1</n32Type>
        <n32ItemID>100010</n32ItemID>
        <n32ItemNum>1</n32ItemNum>
    </info>
    <info n32Days="3">
        <n32Type>1</n32Type>
        <n32ItemID>130002</n32ItemID>
        <n32ItemNum>1</n32ItemNum>
    </info>

ReadDailyBonusConfig.cs

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

//日常奖励配置文件
//响应配置Config路径为:Assets/Resources/Config/dailybonus.xml
public class ReadDailyBonusConfig
{
    XmlDocument xmlDoc = null;

    //构造函数
    public ReadDailyBonusConfig(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 ("DailyBonus").ChildNodes;
        for (int i = 0; i < infoNodeList.Count; i++)
        {
            XmlAttribute xmlAttr = (infoNodeList [i] as XmlElement).GetAttributeNode ("n32Days");

            if (xmlAttr == null)
            {
                continue;
            }

            DailyBonusConfigInfo dailyBonusInfo = new DailyBonusConfigInfo ();

            foreach (XmlElement xEle in infoNodeList[i].ChildNodes)
            {
                #region 搜索
                switch (xEle.Name)
                {
                case "n32Type":
                    dailyBonusInfo.n32Type = xEle.InnerText.Split(new char[] { ',' });
                    break;

                case "n32ItemID":
                    dailyBonusInfo.n32ItemID = xEle.InnerText.Split(new char[] { ',' });
                    break;

                case "n32ItemNum":
                    dailyBonusInfo.n32ItemNum = xEle.InnerText.Split(new char[] { ',' });
                    break;
                }
                #endregion
            }

            ConfigReader.dailyBonusXmlInfoDic.Add (Convert.ToUInt32 (xmlAttr.InnerText), dailyBonusInfo);
        }
    }
}


/*
相应xml文件格式:
<info n32Days="1">
    <n32Type>1</n32Type>
    <n32ItemID>2</n32ItemID>
    <n32ItemNum>120</n32ItemNum>
</info>
*/
public class DailyBonusConfigInfo: System.Object
{
    public string[] n32Type;
    public string[] n32ItemID;
    public string[] n32ItemNum;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值