using UnityEngine;
using System.Xml;
using System.Collections;
using System.IO;
public class XmlLoad
{
/// <summary>
/// XML 文档实例化
/// </summary>
private XmlDocument xmlDoc=new XmlDocument();
private string data = "";
private TextAsset asset;
public int zombiesHp = 0;
public float zombiesSpeed = 0f;
/// <summary>
/// 加载
/// </summary>
public void ShowData(string jsName)
{
asset = (TextAsset)Resources.Load("test", typeof(TextAsset));
data = asset.text;
xmlDoc.LoadXml(data);
XmlElement root = xmlDoc.DocumentElement; // 得到根节点
foreach (XmlNode node in root.ChildNodes)
{
XmlElement xe = (XmlElement)node;
if (node.Name == jsName)
{
zombiesHp =int.Parse(xe.GetAttribute("hp"));
zombiesSpeed = int.Parse(xe.GetAttribute("speed"));
}
}
}
}
XML
<?xml version="1.0"?>
<root>
<js01 hp="10" speed="50" damage="0.2">
</js01>
<js02 hp="15" speed="2" damage="0.2">
</js02>
<js03 hp="20" speed="3" damage="0.2">
</js03>
</root>
移动平台操控读取XML!
最新推荐文章于 2021-05-26 02:41:37 发布