using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Xml; public class ReadXMLWaiXiang : MonoBehaviour { public GameObject inspectListObj; // 保存所有的从XML读取的数据 public ArrayList m_enemylist; // 存储敌人出场顺序的XML public TextAsset xmldata; public InspectList inspecyList; public InspectListPanel inspectListPanel; protected int m_index = 0; protected Transform startPos; public GameObject objParent; void Awake() { // 读取XML ReadMyXML(); inspectListObj = Resources.Load("excel_buttom") as GameObject; LoadInspectList(); } public virtual void Start() { } public virtual void ReadMyXML() { //创建一个字典以存储敌人列表 m_enemylist = new ArrayList(); //加载Xml文档 XmlDocument mDocument = new XmlDocument(); mDocument.LoadXml(xmldata.text); XmlElement mRoot = mDocument.DocumentElement; //解析Xml文档 XmlNodeList mNodes = mRoot.SelectNodes("/BaseList/View"); foreach (XmlNode mNode in mNodes) { SpawnData mData = new SpawnData(); mData.id = int.Parse(mNode.Attributes[0].Value); mData.subtasks = mNode.Attributes[1].Value; mData.taskStatus = int.Parse(mNode.Attributes[2].Value); mData.pos = mNode.Attributes[3].Value; mData.content = mNode.Attributes[4].Value; mData.mainSubtasks = mNode.Attributes[5].Value; mData.endResultViewPos = mNode.Attributes[6].Value; mData.tag = int.Parse(mNode.Attributes[7].Value); mData.code = mNode.Attributes[8].Value; m_enemylist.Add(mData); } } //public virtual void Update() //{ // if (m_index >= m_enemylist.Count) // return; // //LoadInspectList(); //} private void LoadInspectList() { if (m_index >= m_enemylist.Count) return; for (int i = 0; i < m_enemylist.Count; i++) { SpawnData data = (SpawnData)m_enemylist[m_index]; startPos = inspecyList.listParent.transform.Find(data.pos).gameObject.transform; GameObject obj = Instantiate(inspectListObj, new Vector3(startPos.position.x, startPos.position.y, startPos.position.z), Quaternion.Euler(0, startPos.eulerAngles.y, -90)); obj.transform.parent = objParent.transform; // obj.transform.localScale = new Vector3(0.6086614f, 3.158592f, 8778199f); obj.name = "excel_buttom" + data.id.ToString(); InspectList_Button inB = obj.GetComponent(); inB.text_num.text = data.id.ToString(); inB.text_name.text = data.subtasks.ToString(); inB.status = data.taskStatus; inB.content = data.content; inB.mainSubtasks = data.mainSubtasks; inB.endResultViewPos = data.endResultViewPos; inB.viewTag = data.tag; inB.code = data.code; inspectListPanel.taskList.Add(obj); m_index++; } } public class SpawnData { //id public int id; //子任务 public string subtasks; //子任务状态 public int taskStatus; //子任务位置 public string pos; //子任务的具体内容 public string content; //子任务的标题 public string mainSubtasks; //结算列表的view的位置 public string endResultViewPos; //子任务属于 什么判断 1 扫码 2 语音 public int tag; //子任务的根号 public string code; } }