前端之家收集整理的这篇文章主要介绍了
使用Unity3d官方提供得精简版xml解析脚本Mono.xml,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
xml得格式
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ROOT>
<table wave="1" enemyname="1" level="1" wait="1"/>
<table wave="1" enemyname="1" level="1" wait="1"/>
<table wave="2" enemyname="2" level="2" wait="2"/>
<table wave="2" enemyname="2" level="2" wait="2"/>
<table wave="3" enemyname="3" level="3" wait="3"/>
<table wave="3" enemyname="3" level="3" wait="3"/>
<table wave="4" enemyname="4" level="4" wait="4"/>
<table wave="4" enemyname="4" level="4" wait="4"/>
<table wave="5" enemyname="5" level="5" wait="5"/>
<table wave="5" enemyname="5" level="5" wait="5"/>
<table wave="6" enemyname="6" level="6" wait="6"/>
<table wave="6" enemyname="6" level="6" wait="6"/>
<table wave="7" enemyname="7" level="7" wait="7"/>
<table wave="8" enemyname="8" level="8" wait="8"/>
<table wave="9" enemyname="9" level="9" wait="9"/>
<table wave="10" enemyname="10" level="10" wait="10"/>
<table wave="10" enemyname="10" level="10" wait="10"/>
</ROOT>
using UnityEngine;
using System.Collections;
using Mono.Xml;
using System.IO;
public class ParseXml {
int coin;
int exp;
public void ReadXML()
{
SecurityParser SP = new SecurityParser();
SP.LoadXml(Resources.Load("enemy").ToString());
System.Security.SecurityElement SE = SP.ToXml();
foreach (System.Security.SecurityElement child in SE.Children)
{
foreach (System.Security.SecurityElement nodechild in child.Children)
{
//比对下是否使自己所需要得节点
if(child.Tag == "table")
{
//获得节点得属性
int wave = int.Parse(child.Attribute("wave"));
int level = int.Parse(child.Attribute("level"));
int wait = int.Parse(child.Attribute("wait"));
Debug.Log("wave:"+wave+" level:"+level+" wait:"+wait);
}
}
}
}
}
在unity3d目录下找到mono.xml.zip压缩包,得到3个c#脚本,找不到得可以到我得csdn上传资源里面下载,鄙视那些分享这种脚本也要分得人。。。
原文链接:https://www.f2er.com/xml/299553.html