从xml加载ui

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

举例加载Text

xml文件

<?xmlversion="1.0"encoding="UTF-8"standalone="yes"?>
<ROOT>
<tabletype="text"txt="helloworld"/>
<tabletype="button"callback="OnClicked"/>
</ROOT>
usingUnityEngine;
usingSystem.Collections;
usingSystem.Xml;
usingUnityEngine.UI;
publicclassXMLLoader:MonoBehavIoUr{
publicGameObjectprefab_text;

//Usethisforinitialization
voidStart(){
vardoc=newXmlDocument();
doc.Load("../ui.xml");
varroot=doc.DocumentElement;
varnodes=root.GetElementsByTagName("table");
foreach(XmlNodenodeinnodes)
{
switch(((XmlElement)node).GetAttribute("type"))
{
case"text":
{
UnityEngine.UI.Texttxt=((GameObject)(Instantiate(prefab_text,transform.position,transform.rotation))).GetComponent<Text>();
txt.text=((XmlElement)node).GetAttribute("txt");
txt.GetComponent<Transform>().parent=gameObject.transform;
//=((XmlElement)node).GetAttribute("txt");
}
break;
}
}
}

//Updateiscalledonceperframe
voidUpdate(){

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

猜你在找的XML相关文章