Unity读取XML定制。

前端之家收集整理的这篇文章主要介绍了Unity读取XML定制。前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

XML取自Unity3D手机游戏开发。


using UnityEngine;
using System.Collections;
using System.Xml;
using System.IO;

public class loadXml : MonoBehavIoUr {


	public TextAsset test;

	void Start () {
		string textData = test.text;
		XmlDocument xmlDoc = new XmlDocument ();
		xmlDoc.Load (new StringReader (textData));
		XmlNodeList myNodeList = xmlDoc.SelectNodes ("ROOT");

		foreach (XmlNode node in myNodeList) {
			Debug.Log (node.SelectNodes("table").Count);
			XmlNodeList childNodes = node.SelectNodes("table");
			foreach(XmlNode node2 in childNodes){
				Debug.Log (node2.Attributes.GetNamedItem("wave").InnerText);
				Debug.Log (node2.Attributes.GetNamedItem("enemyname").InnerText);
				Debug.Log (node2.Attributes.GetNamedItem("level").InnerText);
				Debug.Log (node2.Attributes.GetNamedItem("wait").InnerText);
				Debug.Log("------------------------");
			}
		}
	}

	void Update () {
	
	}
}


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ROOT>
	<table wave="100" enemyname="ground" level="100" wait="300"/>
	<table wave="1" enemyname="ground" level="1" wait="3"/>
	<table wave="2" enemyname="air" level="2" wait="4"/>
	<table wave="2" enemyname="air" level="2" wait="4"/>
	<table wave="3" enemyname="ground" level="2" wait="3"/>
	<table wave="3" enemyname="air" level="3" wait="3"/>
	<table wave="4" enemyname="ground" level="3" wait="5"/>
	<table wave="4" enemyname="ground" level="3" wait="4"/>
	<table wave="5" enemyname="air" level="4" wait="4"/>
	<table wave="5" enemyname="air" level="4" wait="4"/>
	<table wave="6" enemyname="ground" level="4" wait="4"/>
	<table wave="6" enemyname="ground" level="4" wait="5"/>
	<table wave="7" enemyname="air" level="5" wait="4"/>
	<table wave="7" enemyname="ground" level="5" wait="3"/>
	<table wave="8" enemyname="air" level="5" wait="4"/>
	<table wave="8" enemyname="ground" level="5" wait="4"/>
	<table wave="9" enemyname="air" level="6" wait="4"/>
	<table wave="9" enemyname="air" level="6" wait="5"/>
	<table wave="10" enemyname="ground" level="7" wait="4"/>
	<table wave="10" enemyname="air" level="7" wait="4"/>
</ROOT>
原文链接:https://www.f2er.com/xml/296176.html

猜你在找的XML相关文章