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

机构:杭州玛雅动漫 时间:2016-02-02 点击:843

  一个简单读取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 "";

  }

  了解更多关于游戏设计方面的知识,请访问杭州游戏设计培训学校

返回顶部