目录为:Assets/Scripts/ConfigReader/目录下
ReadGuideFlashTaskConfig.cs
要读取的配置文件:
Assets/Resources/Config/Animine
部分如下:
<info id="1002">
<localpath>TopLeftPanel/Hand</localpath>
<pathtype>2</pathtype>
<startpos>60;-215;0</startpos>
<begin>60;-215;0</begin>
<objective>60;-195;0</objective>
<frequency>0.5</frequency>
<form>2</form>
<style>2</style>
<animation>0</animation>
<finish>1</finish>
</info>
ReadGuideFlashTaskConfig.cs
using System;
using UnityEngine;
using System.Xml;
using System.Collections.Generic;
//新手教程相关
//对应的配置文件:Assets/Resources/Config/Animine.xml
public class ReadGuideFlashTaskConfig
{
XmlDocument xmlDoc = null;
//构造函数
public ReadGuideFlashTaskConfig(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 ("Animine").ChildNodes;
for (int i = 0; i < infoNodeList.Count; i++)
{
if ((infoNodeList[i] as XmlElement).GetAttributeNode("id").InnerText == null)
{
continue;
}
string typeName = (infoNodeList [i] as XmlElement).GetAttributeNode ("id").InnerText;
//在Guide那部分定义的
CFlashTask flashInfo = new CFlashTask ();
flashInfo.TaskId = Convert.ToInt32 (typeName);
flashInfo.TaskType = GuideTaskType.ObjFlashTask;
foreach(XmlElement xEle in infoNodeList[i].ChildNodes)
{
switch (xEle.Name)
{
case "localPath":
flashInfo.UiPath = Convert.ToString (xEle.InnerText);
break;
case "pathtype":
flashInfo.PathType = (UIPathType)Convert.ToInt32 (xEle.InnerText);
break;
case "startpos":
flashInfo.StartPos = GameMethod.ResolveToVector3 (Convert.ToString (xEle.InnerText), ';');
break;
case "begin":
flashInfo.StartEffect = Convert.ToString (xEle.InnerText);
break;
case "objective":
flashInfo.TargetEffect = Convert.ToString (xEle.InnerText);
break;
case "frequency":
flashInfo.During = Convert.ToSingle (xEle.InnerText);
break;
case "form":
flashInfo.EffectType = (UITweener.Method)Convert.ToInt32 (xEle.InnerText);
break;
case "style":
flashInfo.Style = (UITweener.Style)Convert.ToInt32 (xEle.InnerText);
break;
case "animation":
flashInfo.Type = (FlashType)Convert.ToInt32 (xEle.InnerText);
break;
case "finish":
flashInfo.OverReset = Convert.ToInt32 (xEle.InnerText);
break;
//这个节点,xml里面好像没有
case "DefaultLocation":
flashInfo.PrefabPath = Convert.ToString (xEle.InnerText);
break;
}
}
CTaskBase.flashTaskDic.Add (flashInfo.TaskId, flashInfo);
}
}
}
/*
虽然CFlashTask没在这里定义,但还是把格式说明放在这里
XML格式:
<info id="1001">
<localpath>BottomLeftPanel/Hand</localpath>
<pathtype>2</pathtype>
<startpos>135;235;0</startpos>
<begin>135;235;0</begin>
<objective>135;275;0</objective>
<frequency>0.5</frequency>
<form>2</form>
<style>2</style>
<animation>0</animation>
<finish>1</finish>
</info>
*/