实现unity下加载xml文件。
a. 准备1个文本格式为utf-8的xml文件,以及读取文件的LoadXMLFile.cs脚本;
b. LoadXMLFile脚本代码如下:
usingUnityEngine;
using System.Collections;
usingSystem.IO;
usingSystem.Xml;
publicclass LoadXMLFile : MonoBehaviour {
//存放xml中需要获取的内容
private string[] _xmlStr;
void Start()
{
LoadXML();
//将xml中需要显示的内容显示出来
if(_xmlStr != null && _xmlStr.Length> 0)
{
foreach(string str in _xmlStr)
{
Debug.Log(str);
}
}
}
private void LoadXML()
{
//设置文件位置,根据自己的需要进行设置
string filePath = Application.dataPath+ "/LoadFileStudy/Resources/studyXML.xml";
try
{
XmlDocument xmlDoc = newXmlDocument();
xmlDoc.Load(filePath);
XmlNodeList node =xmlDoc.SelectSin