ReadXMLWaiXiang.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. StartCoroutine(LoadDll2.DownLoadAssets((AssetBundle ab) => {
  20. GameObject obj = ab.LoadAsset<GameObject>("excel_buttom");
  21. ReadMyXML();
  22. inspectListObj = obj;
  23. LoadInspectList();
  24. }));
  25. }
  26. public virtual void Start()
  27. {
  28. }
  29. public virtual void ReadMyXML()
  30. {
  31. //创建一个字典以存储敌人列表
  32. m_enemylist = new ArrayList();
  33. //加载Xml文档
  34. XmlDocument mDocument = new XmlDocument();
  35. mDocument.LoadXml(xmldata.text);
  36. XmlElement mRoot = mDocument.DocumentElement;
  37. //解析Xml文档
  38. XmlNodeList mNodes = mRoot.SelectNodes("/BaseList/View");
  39. foreach (XmlNode mNode in mNodes)
  40. {
  41. SpawnData mData = new SpawnData();
  42. mData.id = int.Parse(mNode.Attributes[0].Value);
  43. mData.subtasks = mNode.Attributes[1].Value;
  44. mData.taskStatus = int.Parse(mNode.Attributes[2].Value);
  45. mData.pos = mNode.Attributes[3].Value;
  46. mData.content = mNode.Attributes[4].Value;
  47. mData.mainSubtasks = mNode.Attributes[5].Value;
  48. mData.endResultViewPos = mNode.Attributes[6].Value;
  49. mData.tag = int.Parse(mNode.Attributes[7].Value);
  50. mData.code = mNode.Attributes[8].Value;
  51. m_enemylist.Add(mData);
  52. }
  53. }
  54. //public virtual void Update()
  55. //{
  56. // if (m_index >= m_enemylist.Count)
  57. // return;
  58. // //LoadInspectList();
  59. //}
  60. private void LoadInspectList()
  61. {
  62. if (m_index >= m_enemylist.Count)
  63. return;
  64. for (int i = 0; i < m_enemylist.Count; i++)
  65. {
  66. SpawnData data = (SpawnData)m_enemylist[m_index];
  67. try
  68. {
  69. startPos = inspecyList.listParent.transform.Find(data.pos).gameObject.transform;
  70. }
  71. catch
  72. {
  73. Debug.Log("startpos =>" + data.pos);
  74. }
  75. GameObject obj = Instantiate(inspectListObj, new Vector3(startPos.position.x, startPos.position.y, startPos.position.z), Quaternion.Euler(0, startPos.eulerAngles.y, -90));
  76. if(obj)
  77. {
  78. obj.transform.parent = objParent.transform;
  79. // obj.transform.localScale = new Vector3(0.6086614f, 3.158592f, 8778199f);
  80. obj.name = "excel_buttom" + data.id.ToString();
  81. InspectList_Button inB = obj.GetComponent<InspectList_Button>();
  82. inB.text_num.text = data.id.ToString();
  83. inB.text_name.text = data.subtasks.ToString();
  84. inB.status = data.taskStatus;
  85. inB.content = data.content;
  86. inB.mainSubtasks = data.mainSubtasks;
  87. inB.endResultViewPos = data.endResultViewPos;
  88. inB.viewTag = data.tag;
  89. inB.code = data.code;
  90. inspectListPanel.taskList.Add(obj);
  91. m_index++;
  92. }
  93. }
  94. }
  95. public class SpawnData
  96. {
  97. //id
  98. public int id;
  99. //子任务
  100. public string subtasks;
  101. //子任务状态
  102. public int taskStatus;
  103. //子任务位置
  104. public string pos;
  105. //子任务的具体内容
  106. public string content;
  107. //子任务的标题
  108. public string mainSubtasks;
  109. //结算列表的view的位置
  110. public string endResultViewPos;
  111. //子任务属于 什么判断 1 扫码 2 语音
  112. public int tag;
  113. //子任务的根号
  114. public string code;
  115. }
  116. }