加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

从xml加载ui

发布时间:2020-12-16 05:53:01 所属栏目:百科 来源:网络整理
导读:举例加载Text xml文件 ?xmlversion="1.0"encoding="UTF-8"standalone="yes"?ROOTtabletype="text"txt="helloworld"/tabletype="button"callback="OnClicked"//ROOT usingUnityEngine;usingSystem.Collections;usingSystem.Xml;usingUnityEngine.UI;publiccla

举例加载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(){

}
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读