標籤:using als initial ini 安裝路徑 source for ram cal
1.解壓壓縮包,把檔案夾拖到指令檔夾下
Mono是第三方基金會開發的開源的東西,通過Mono基礎上開發的程式可以在各個系統下運行。開發語言是C#。
用外掛程式解析比較高效,平台運行穩定。使用簡單。
Unity安裝路徑中可以找到Mono壓縮包
2.建立指令碼XmlTest
using UnityEngine;
using System.Collections;
using Mono.Xml;
using System.Security;
public class XmlTest : MonoBehaviour {
//測試xml是否可用
// Use this for initialization
void Start () {
//載入外部xml文檔
string strXml = Resources.Load("Enemy").ToString();
//解析xml,產生SecurityParser對象,然後解析字串為xml格式
SecurityParser parse = new SecurityParser();
//傳入要解析的字串
parse.LoadXml(strXml);
//擷取載入xml的根節點
SecurityElement se = parse.ToXml();
//遍曆se子節點,se代表root,子節點代表table
foreach (SecurityElement element in se.Children)
{
//先判定節點是否為table
if (element.Tag.Equals("table"))
{
//輸出所有wave屬性值
Debug.Log(element.Attribute("wave").ToString());
Debug.Log(element.Attribute("level").ToString());
}
}
}
// Update is called once per frame
void Update () {
}
}
3.在Scene中建立Manager空物體,把指令碼掛在上面,運行。
看控制台輸出,如果輸出為xml檔案中變數的值則解析成功。
Unity中用Mono外掛程式解析xml檔案