Unity3D读取XML内容代码

Unity3D读取XML内容代码

一个简单读取Unity3D中XML内容的代码:

public string showXml(string temp)
{
UnityEditor.AssetDatabase.Refresh();
string filepath = Application.dataPath + "/my.xml";
string tempText = "";
print("a");
print(File.Exists(filepath).ToString());
if (File.Exists(filepath))
{
print("b");
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filepath);//
若要读网络 前面改成IEnum线程这里改网络xml地址即可
XmlNodeList nodeList = xmlDoc.SelectSingleNode("main").ChildNodes;
//
foreach (XmlElement xe in nodeList)
{
// Debug.Log(xe.GetAttribute("name"));
// Debug.Log(xe.Name);
foreach (XmlElement x1 in xe.ChildNodes)
{
if (x1.Name == temp)
{
tempText= x1.InnerText;
// print(x1.InnerText);
}
}

} return tempText; print(tempText); } else { return "file not exists!"; } // return ""; }

相关文章

前言 本文记录unity3D开发环境的搭建 unity安装 unity有中文...
前言 有时候我们希望公告牌跟随镜头旋转永远平行面向屏幕,同...
前言 经过一段时间的学习与实际开发,unity3D也勉强算是强行...
前言 在unity中我们常用的获取鼠标点击的方法有: 1、在3D场...
前言 在之前的例子中,我们都没有用到unity的精髓,例如地形...
这篇文章将为大家详细讲解有关Unity3D中如何通过Animator动画...