ConfigReader(十七)—— ReadGuideManagerTaskConfig

来源:互联网 发布:json字符串转为map 编辑:程序博客网 时间:2024/06/16 14:27

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

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

最后两段:

<info id="90031">        <childtype>17</childtype>        <childid>17019</childid>        <endtype>2</endtype>        <endid>17019</endid>        <nexttaskid>90032</nexttaskid>        <tasktype>1004</tasktype>    </info>    <info id="90032">        <childtype>23</childtype>        <childid>23001</childid>        <endtype>2</endtype>        <endid>23001</endid>        <tasktype>1004</tasktype>        <moduleend>1</moduleend>    </info>

ReadGuideManagerTaskConfig.cs

using System;using UnityEngine;using System.Xml;using System.Collections.Generic;//新手指导相关,taskmanager//对应配置文件:Assets/Resources/Config/taskmanager.xmlpublic class ReadGuideManagerTaskConfig{    XmlDocument xmlDoc = null;    //构造函数    public ReadGuideManagerTaskConfig(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 ("taskmanager").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;            GuideMgrInfo mgrInfo = new GuideMgrInfo ();            mgrInfo.TaskId = Convert.ToInt32 (typeName);            foreach (XmlElement xEle in infoNodeList[i].ChildNodes)            {                switch (xEle.Name)                {                case "childtype":                    mgrInfo.ChildTaskType = GameMethod.ResolveToInitList (xEle.InnerText);                    break;                case "childid":                    mgrInfo.ChildTaskId = GameMethod.ResolveToIntList (xEle.InnerText);                    break;                case "endtype":                    mgrInfo.TaskEndType = (TaskCheckType)Convert.ToInt32 (xEle.InnerText);                    break;                case "endid":                    mgrInfo.EndTaskChildId = Convert.ToInt32 (xEle.InnerText);                    break;                case "nexttaskid":                    mgrInfo.NextTaskId = Convert.ToInt32 (xEle.InnerText);                    break;                case "close":                    mgrInfo.mToServerType = Convert.ToInt32 (xEle.InnerText);                    break;                case "tasktype":                    mgrInfo.mTaskType = Convert.ToInt32 (xEle.InnerText);                    break;                //这个node在taskmanager.xml中是最后一个node中才有                case "moduleend":                    mgrInfo.moduleend = Convert.ToInt32 (xEle.InnerText);                    break;                }            }            ConfigReader.guideTaskMgrInfoDict.Add (mgrInfo.TaskId, mgrInfo);        }    }}/*对应xml格式:<info id="90001">    <childtype>17</childtype>    <childid>17000</childid>    <endtype>2</endtype>    <endid>17000</endid>    <nexttaskid>90002</nexttaskid>    <tasktype>1001</tasktype></info>*/public class GuideMgrInfo{    public int TaskId;    public List<int> ChildTaskType;    public List<int> ChildTaskId;    public TaskCheckType TaskEndType;    public int EndTaskChildId;    public int NextTaskId;    public int mToServerType;    public int mTaskType;    public bool moduleend;}
阅读全文
0 0