ConfigReader(十五)—— ReadGuideKillHeroTaskConfig

来源:互联网 发布:k线图 知乎 编辑:程序博客网 时间:2024/05/17 03:24

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

新手教程相关
对应的配置文件:
Assets/Resources/Config/killhero.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><killhero xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">    <info id="19001">        <deadnpcid>10009</deadnpcid>        <times>1</times>        <deadreason>0,1,2</deadreason>    </info>    <info id="19002">        <deadnpcid>10008,10009,10007</deadnpcid>        <times>1</times>        <deadreason>0,1,2</deadreason>    </info>    <info id="19003">        <deadnpcid>10007</deadnpcid>        <times>1</times>        <deadreason>0,1,2</deadreason>    </info></killhero>

ReadGuideKillHeroTaskConfig.cs

using System;using UnityEngine;using System.Xml;using System.Collections.Generic;//新手教程相关//对应配置文件:Assets/Resources/Config/killhero.xmlpublic class ReadGuideKillHeroTaskConfig{    XmlDocument xmlDoc = null;    //构造函数    public ReadGuideKillHeroTaskConfig(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 ("killhero").ChildNodes;        for (int i = 0; i < infoNodeList.Count; i++)        {            if ((infoNodeList[i] as XmlElement).GetAttributeNode("id") == null)            {                continue;            }            string typeName = (infoNodeList [i] as XmlElement).GetAttributeNode ("id").InnerText;            GuideKillHeroInfo info = new GuideKillHeroInfo ();            info.TaskId = Convert.ToInt32 (typeName);            foreach (XmlElement xEle in infoNodeList[i].ChildNodes)            {                switch (xEle.Name)                {                case "deadnpcid":                    info.mDeadnpcid = GameMethod.ResolveToIntList (xEle.InnerText);                    break;                case "times":                    info.mTimes = Convert.ToInt32 (xEle.InnerText);                    break;                }            }            ConfigReader.guideKillHeroXmlInfoDict.Add (info.TaskId, info);        }    }}/*XML文件格式:<info id="19002">    <deadnpcid>10008,10009,10007</deadnpcid>    <times>1</times>    <deadreason>0,1,2</deadreason></info>*/public class GuideKillHeroInfo{    public int TaskId;    public List<int> mDeadnpcid;    public int mTimes;}