UITreeMenuProxy.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System.IO;
  5. using System.Linq;
  6. public class UITreeMenuProxy : DataProxy
  7. {
  8. List<TreeNodeInfo> treeNodeInfos;
  9. public override void OnRegister()
  10. {
  11. InitData();
  12. }
  13. public void InitData()
  14. {
  15. //表格读取
  16. string path = Application.streamingAssetsPath + "/TableData/设备树.csv";
  17. treeNodeInfos = ReadOperationFromTable(path);
  18. }
  19. public List<TreeNodeInfo> GetUITreeData()
  20. {
  21. return treeNodeInfos;
  22. }
  23. public override void OnRemove()
  24. {
  25. }
  26. /// <summary>
  27. /// 从表格读取流程信息
  28. /// </summary>
  29. /// <param name="path"></param>
  30. /// <returns></returns>
  31. private List<TreeNodeInfo> ReadOperationFromTable(string path)
  32. {
  33. List<TreeNodeInfo> tmpInfos = new List<TreeNodeInfo>();
  34. using (StreamReader streamReader = new StreamReader(path, System.Text.Encoding.UTF8))
  35. {
  36. string tmpOperationInfo = streamReader.ReadToEnd().TrimEnd();
  37. if (tmpOperationInfo.Contains("\r")) tmpOperationInfo = tmpOperationInfo.Replace("\r", "");
  38. string[] tempOperationInfos = tmpOperationInfo.Split('\n');
  39. for (int i = 1; i < tempOperationInfos.Length; i++)
  40. {
  41. string operationInfo = tempOperationInfos[i];
  42. string[] operationInfoElements = operationInfo.Split(',');
  43. TreeNodeInfo tmpInfo = new TreeNodeInfo();
  44. for (int j = 0; j < operationInfoElements.Length; j++)
  45. {
  46. if (j == 0) tmpInfo.m_Id = int.Parse(operationInfoElements[0]);
  47. if (j == 1) tmpInfo.m_NodeName = operationInfoElements[1];
  48. if (j == 2) tmpInfo.m_NodeParentName = operationInfoElements[2];
  49. if (j == 3) tmpInfo.m_NodeLayer = int.Parse(operationInfoElements[3]);
  50. if (j == 4) tmpInfo.m_GroupName = operationInfoElements[4];
  51. }
  52. tmpInfos.Add(tmpInfo);
  53. }
  54. }
  55. return tmpInfos;
  56. }
  57. }