unity 读取xml 信息
来源:互联网 发布:淘宝代刷灰烬套装 编辑:程序博客网 时间:2024/05/16 05:34
1、首先在unity工程中Resources/XML目录下创建xml文件:xmls.xml;
如:
<?xml version ="1.0" encoding = "utf-8"?><root><parent name ="Lily"><child name ="L01">123</child><child name ="L02">apple</child><child name ="L03">大</child></parent></root>
2、定义我们需要的变量:
using System.Xml;
private XmlDocument xmldoc;private XmlNode root;private string url;
3、在Start()函数进行初始化:
初始化方法一:
url = Application.dataPath + "/Resources/XML/xmls.xml";xmldoc = new XmlDocument();xmldoc.Load(url);root = xmldoc.SelectSingleNode("root");
初始化方法二:
url = "XML/xmls";xmlAsset = Resources.Load<TextAsset>(url);xmldoc = new XmlDocument();xmldoc.LoadXml(xmlAsset.text);
初始化完成之后、来写我们需要的方法:
4、读取Lily:
void ReadLily(){XmlElement parent = (XmlElement)root.SelectSingleNode("parent");Debug.Log(parent.Name + "Name:" + parent.GetAttribute("name"));}
5、读取所有子节点的值:
void ReadAllChildName(){XmlNode parent = root.SelectSingleNode("parent");XmlNodeList childs = parent.SelectNodes("child");foreach (XmlNode temp in childs){XmlElement ele = (XmlElement)temp;Debug.Log(ele.Name + "Name:" + ele.GetAttribute("name") + " value:" + ele.InnerText);}}
这样就可以在完成初始化的时候进行调用;
结果:
0 0
- unity 读取xml 信息
- Unity 读取xml 文件
- Unity 读取xml 文件
- unity c#读取xml
- unity中xml读取
- Unity读取XML定制。
- unity的XML读取
- Unity 读取XML文件
- unity读取xml
- 读取XML文件信息
- dom4j读取XML信息
- java读取xml信息
- dom4j读取xml信息
- Unity读取xml(android)
- unity中读取xml文件
- Unity 中读取XML文件
- unity中WWW读取xml
- 【Unity&XML】读取XML文件内容
- ios开发中的问题1
- Combination Sum算法详解
- java修炼之道笔记(一)
- C语言中存储类型和Static关键字
- Git提交时发生unable to get local issuer certificate while accessing错误
- unity 读取xml 信息
- PHP 获取日期所在自然周和自然月的方法
- [转载]Python正则表达式操作指南
- java架构师之路:JAVA程序员必看的15本书的电子版下载地址
- 谷妹
- 欢迎使用CSDN-markdown编辑器
- 判断输入的内容是否包含emoj表情
- 黑马程序员---java中Timer类的介绍以及使用
- 两性测试:你对哪种男人甘愿为奴(图)