目录为:Assets/Scripts/ConfigReader/目录下
ReadGuideObjShowTaskConfig.cs
新手教程相关
对应配置文件为:
Assets/Resources/Config/gameobjectshow.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<gameobjctshow xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<info id="1001">
<pathtype>1</pathtype>
<path>VirtualPanel</path>
<startshow>1</startshow>
<endshow>1</endshow>
</info>
</gameobjctshow>
ReadGuideObjShowTaskConfig.cs
using System;
using UnityEngine;
using System.Xml;
using System.Collections.Generic;
//新手教程相关
//对应的要读取的配置文件:Assets/Resources/Config/gameobjectshow.xml
public class ReadGuideObjShowTaskConfig
{
XmlDocument xmlDoc = null;
//构造函数
public ReadGuideObjShowTaskConfig(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 ("gameobjectshow").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;
//在Guide那部分定义
CGameObjectShowTask showInfo = new CGameObjectShowTask ();
showInfo.TaskId = Convert.ToInt32 (typeName);
showInfo.TaskType = GuideTaskType.ObjShowTask;
foreach (XmlElement xEle in infoNodeList[i].ChildNodes)
{
switch (xEle.Name)
{
case "pathtype":
showInfo.PathType = (UIPathType)Convert.ToInt32 (xEle.InnerText);
break;
case "path":
showInfo.Path = Convert.ToString (xEle.InnerText);
break;
case "startshow":
showInfo.StartShow = Convert.ToInt32 (xEle.InnerText);
break;
case "endshow":
showInfo.EndShow = Convert.ToInt32 (xEle.InnerText);
break;
}
}
CTaskBase.objShowTaskDic.Add (showInfo.TaskId, showInfo);
}
}
}