ReadXMLWaiXiang.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System.Xml;
  5. public class ReadXMLWaiXiang : MonoBehaviour
  6. {
  7. public GameObject inspectListObj;
  8. // 保存所有的从XML读取的数据
  9. public ArrayList m_enemylist;
  10. // 存储敌人出场顺序的XML
  11. public TextAsset xmldata;
  12. public InspectList inspecyList;
  13. public InspectListPanel inspectListPanel;
  14. protected int m_index = 0;
  15. protected Transform startPos;
  16. public GameObject objParent;
  17. void Awake()
  18. {
  19. // 读取XML
  20. ReadMyXML();
  21. inspectListObj = Resources.Load("excel_buttom") as GameObject;
  22. LoadInspectList();
  23. }
  24. public virtual void Start()
  25. {
  26. }
  27. public virtual void ReadMyXML()
  28. {
  29. //创建一个字典以存储敌人列表
  30. m_enemylist = new ArrayList();
  31. //加载Xml文档
  32. XmlDocument mDocument = new XmlDocument();
  33. mDocument.LoadXml(xmldata.text);
  34. XmlElement mRoot = mDocument.DocumentElement;
  35. //解析Xml文档
  36. XmlNodeList mNodes = mRoot.SelectNodes("/BaseList/View");
  37. foreach (XmlNode mNode in mNodes)
  38. {
  39. SpawnData mData = new SpawnData();
  40. mData.id = int.Parse(mNode.Attributes[0].Value);
  41. mData.subtasks = mNode.Attributes[1].Value;
  42. mData.taskStatus = int.Parse(mNode.Attributes[2].Value);
  43. mData.pos = mNode.Attributes[3].Value;
  44. mData.content = mNode.Attributes[4].Value;
  45. mData.mainSubtasks = mNode.Attributes[5].Value;
  46. mData.endResultViewPos = mNode.Attributes[6].Value;
  47. mData.tag = int.Parse(mNode.Attributes[7].Value);
  48. mData.code = mNode.Attributes[8].Value;
  49. m_enemylist.Add(mData);
  50. }
  51. }
  52. //public virtual void Update()
  53. //{
  54. // if (m_index >= m_enemylist.Count)
  55. // return;
  56. // //LoadInspectList();
  57. //}
  58. private void LoadInspectList()
  59. {
  60. if (m_index >= m_enemylist.Count)
  61. return;
  62. for (int i = 0; i < m_enemylist.Count; i++)
  63. {
  64. SpawnData data = (SpawnData)m_enemylist[m_index];
  65. startPos = inspecyList.listParent.transform.Find(data.pos).gameObject.transform;
  66. GameObject obj = Instantiate(inspectListObj, new Vector3(startPos.position.x, startPos.position.y, startPos.position.z), Quaternion.Euler(0, startPos.eulerAngles.y, -90));
  67. obj.transform.parent = objParent.transform;
  68. // obj.transform.localScale = new Vector3(0.6086614f, 3.158592f, 8778199f);
  69. obj.name = "excel_buttom" + data.id.ToString();
  70. InspectList_Button inB = obj.GetComponent<InspectList_Button>();
  71. inB.text_num.text = data.id.ToString();
  72. inB.text_name.text = data.subtasks.ToString();
  73. inB.status = data.taskStatus;
  74. inB.content = data.content;
  75. inB.mainSubtasks = data.mainSubtasks;
  76. inB.endResultViewPos = data.endResultViewPos;
  77. inB.viewTag = data.tag;
  78. inB.code = data.code;
  79. inspectListPanel.taskList.Add(obj);
  80. m_index++;
  81. }
  82. }
  83. public class SpawnData
  84. {
  85. //id
  86. public int id;
  87. //子任务
  88. public string subtasks;
  89. //子任务状态
  90. public int taskStatus;
  91. //子任务位置
  92. public string pos;
  93. //子任务的具体内容
  94. public string content;
  95. //子任务的标题
  96. public string mainSubtasks;
  97. //结算列表的view的位置
  98. public string endResultViewPos;
  99. //子任务属于 什么判断 1 扫码 2 语音
  100. public int tag;
  101. //子任务的根号
  102. public string code;
  103. }
  104. }