目录为:Assets/Scripts/ConfigReader/目录下
ReadGuideCameraTaskConfig.cs
这里是摄像机移动相关的
要读取的XML文件:
Assets/Resources/Config/Vidicon.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Vidicon xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<info id="11001">
<begin>24500,8200,8000</begin>
<end>11500,8200,8000</end>
<aspect>23000,6100,9500</aspect>
<time>4</time>
<Nexttime>4</Nexttime>
<goon>11002</goon>
</info>
<info id="11002">
<begin>11500,8000,8000</begin>
<end>3500,8200,8000</end>
<aspect>10000,6100,9500</aspect>
<time>4</time>
<Nexttime>3</Nexttime>
</info>
</Vidicon>
ReadGuideCameraTaskConfig.cs
using System;
using UnityEngine;
using System.Xml;
using System.Collections.Generic;
//摄像机移动相关
//对应的配置文件的路径:Assets/Resources/Config/Vidicon.xml
public class ReadGuideCameraTaskConfig
{
XmlDocument xmlDoc = null;
//构造函数
public ReadGuideCameraTaskConfig(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 ("Vidicon").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;
CameraMoveInfo info = new CameraMoveInfo ();
info.mTaskId = Convert.ToInt32 (typeName);
foreach(XmlElement xEle in infoNodeList[i].ChildNodes)
{
switch (xEle.Name)
{
case "begin":
info.mStartPos = GameMethod.ResolveToVector3AsServer (xEle.InnerText);
break;
case "end":
info.mEndPos = GameMethod.ResolveToVector3AsServer (xEle.InnerText);
break;
case "aspect":
info.mAspect = GameMethod.ResolveToVector3AsServer (xEle.InnerText);
break;
case "time":
info.mDurTime = Convert.ToSingle (xEle.InnerText);
break;
case "Nexttime":
info.mNextTime = Convert.ToSingle (xEle.InnerText);
break;
case "goon":
info.mGoon = Convert.ToSingle (xEle.InnerText);
break;
}
}
ConfigReader.guideCameraMoveXmlInfoDict.Add (info.mTaskId, info);
}
}
}
/*
要读取的xml格式:
<info id="11001">
<begin>24500,8200,8000</begin>
<end>11500,8200,8000</end>
<aspect>23000,6100,9500</aspect>
<time>4</time>
<Nexttime>4</Nexttime>
<goon>11002</goon>
</info>
*/
public class CameraMoveInfo
{
public int mTaskId;
public Vector3 mStartPos;
public Vector3 mEndPos;
public Vector3 mAspect;
public float mDurTime;
public float mNextTime;
public int mGoon;
}