从xml加载ui
发布时间:2020-12-16 08:40:17 所属栏目:百科 来源:网络整理
导读:举例加载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(){ } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |