ConfigReader(十二)—— ReadGuideClickButtonTaskConfig

来源:互联网 发布:笔记本电脑必备软件 编辑:程序博客网 时间:2024/06/08 12:19

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

这里读取的还是新手指导相关的。

要读取的配置文件:
Assets/Resources/Config/ClickButton.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ClickButton xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">    <info id="2001">        <path>UIMainWindow(Clone)/LockPhoto/Adjust/Head</path>        <Effects>effect/ui_effect/tips_absorb_ring</Effects>    </info></ClickButton>

ReadGuideClickButtonTaskConfig.cs

using System;using UnityEngine;using System.Xml;using System.Collections.Generic;//新手指导相关//对应config文件路径为:Assets/Resources/Config/ClickButton.xmlpublic class ReadGuideClickButtonTaskConfig{    XmlDocument xmlDoc = null;    //构造函数    public ReadGuideClickButtonTaskConfig(string xmlFilePath)    {        ResourceUnit xnlfileUnit = ResourcesManager.Instance.loadImmediate (xmlFilePath);        TextAsset xmlfile = xnlfileUnit.Asset as TextAsset;        if (!xmlfile)        {            Debug.LogError(" error infos: 没有找到指定的xml文件:" + xmlFilePath);        }        xmlDoc = new XmlDocument ();        xmlDoc.LoadXml (xmlfile.text);        XmlNodeList infoNodeList = xmlDoc.SelectSingleNode ("ClickButton").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;            GuideButtonClickInfo info = new GuideButtonClickInfo ();            info.mTaskId = Convert.ToInt32 (typeName);            foreach (XmlElement xEle in infoNodeList[i].ChildNodes)            {                switch (xEle.Name)                {                case "path":                    info.mPath = xEle.InnerText;                    break;                case "Effects":                    info.mEffects = xEle.InnerText;                    break;                }            }            ConfigReader.guideButtonClickXmlDict.Add (info.mTaskId, info);        }    }}/*对应的xml格式:<info id="2001">    <path>UIMainWindow(Clone)/LockPhoto/Adjust/Head</path>    <Effects>effect/ui_effect/tips_absorb_ring</Effects></info>*/public class GuideButtonClickInfo{    //这里代码风格和前面的不太统一    public int mTaskId;    public int mPath;    public string mEffects;}
原创粉丝点击