unity 加载xml文件

前端之家收集整理的这篇文章主要介绍了unity 加载xml文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

一、xml文件内容

1、<?xml version="1.0" encoding="utf-8"?>
<ROOT>
<toy id="0" colorid="0" rawdataname="tuoyuan" />
<toy id="4" colorid="4" rawdataname="changfangxing" />
</ROOT>

二、加载方式

1、

XmlDocument xmldoc = new XmlDocument();
TextAsset toydata = (TextAsset)Resources.Load("XML/mytoy");
xmldoc.LoadXml(toydata.text.ToString().Trim());

//读取方式一 XmlNode root = xmldoc.SelectSingleNode("ROOT"); if (root != null) { XmlNodeList nodelist = root.ChildNodes; foreach (XmlNode node in nodelist) { XmlElement xmlelement = (XmlElement)node; int id = int.Parse(xmlelement.GetAttribute("id")); int colorid = int.Parse(xmlelement.GetAttribute("colorid")); string rawdataname = xmlelement.GetAttribute("rawdataname"); } }

原文链接:https://www.f2er.com/xml/298988.html

猜你在找的XML相关文章