ConfigReader(三十四)—— ReadLevelConfig

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

英雄升级所需经验相关

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

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<WildMonsterCfg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <info UserLevel="1">
        <LevelUpExp>100</LevelUpExp>
    </info>
    <info UserLevel="2">
        <LevelUpExp>113</LevelUpExp>
    </info>
    <info UserLevel="3">
        <LevelUpExp>131</LevelUpExp>
    </info>
    <info UserLevel="4">
        <LevelUpExp>151</LevelUpExp>
    </info>
    <info UserLevel="5">
        <LevelUpExp>175</LevelUpExp>
    </info>
    <info UserLevel="6">
        <LevelUpExp>202</LevelUpExp>
    </info>
    <info UserLevel="7">
        <LevelUpExp>230</LevelUpExp>
    </info>
    <info UserLevel="8">
        <LevelUpExp>262</LevelUpExp>
    </info>
    <info UserLevel="9">
        <LevelUpExp>295</LevelUpExp>
    </info>
    <info UserLevel="10">
        <LevelUpExp>330</LevelUpExp>
    </info>
    <info UserLevel="11">
        <LevelUpExp>367</LevelUpExp>
    </info>
    <info UserLevel="12">
        <LevelUpExp>407</LevelUpExp>
    </info>
    <info UserLevel="13">
        <LevelUpExp>447</LevelUpExp>
    </info>
    <info UserLevel="14">
        <LevelUpExp>490</LevelUpExp>
    </info>
    <info UserLevel="15">
        <LevelUpExp>534</LevelUpExp>
    </info>
    <info UserLevel="16">
        <LevelUpExp>580</LevelUpExp>
    </info>
    <info UserLevel="17">
        <LevelUpExp>627</LevelUpExp>
    </info>
    <info UserLevel="18">
        <LevelUpExp>676</LevelUpExp>
    </info>
    <info UserLevel="19">
        <LevelUpExp>726</LevelUpExp>
    </info>
    <info UserLevel="20">
        <LevelUpExp>778</LevelUpExp>
    </info>
    <info UserLevel="21">
        <LevelUpExp>831</LevelUpExp>
    </info>
    <info UserLevel="22">
        <LevelUpExp>886</LevelUpExp>
    </info>
    <info UserLevel="23">
        <LevelUpExp>941</LevelUpExp>
    </info>
    <info UserLevel="24">
        <LevelUpExp>998</LevelUpExp>
    </info>
    <info UserLevel="25">
        <LevelUpExp>1057</LevelUpExp>
    </info>
    <info UserLevel="26">
        <LevelUpExp>1116</LevelUpExp>
    </info>
    <info UserLevel="27">
        <LevelUpExp>1177</LevelUpExp>
    </info>
    <info UserLevel="28">
        <LevelUpExp>1239</LevelUpExp>
    </info>
    <info UserLevel="29">
        <LevelUpExp>1302</LevelUpExp>
    </info>
    <info UserLevel="30">
        <LevelUpExp>0</LevelUpExp>
    </info>
</WildMonsterCfg>

ReadLevelConfig.cs

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

//升级经验配置
//对应配置文件:Assets/Resources/Config/UserAccountCfg.xml
public class ReadLevelConfig
{
    XmlDocument xmlDoc = null;

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

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

            string level = (infoNodeList [i] as XmlElement).GetAttributeNode ("UserLevel").InnerText;

            LevelConfigInfo levelInfo = new LevelConfigInfo ();
            levelInfo.UserLevel = Convert.ToInt32 (level);

            foreach (XmlElement xEle in infoNodeList[i].ChildNodes)
            {
                switch (xEle.Name)
                {
                case "LevelUpExp":
                    levelInfo.LevelUpExp = Convert.ToSingle (xEle.InnerText);
                    break;
                }
            }

            ConfigReader.levelXmlInfoDict.Add (levelInfo.UserLevel, levelInfo);
        }
    }
}

/*
XML格式:
<info UserLevel="1">
    <LevelUpExp>100</LevelUpExp>
</info>
*/
public class LevelConfigInfo: System.Object
{
    public int UserLevel;
    public float LevelUpExp;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值