DeviceOfPartDataProxy.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using QFramework;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using UnityEngine;
  5. using static RestoreObjectPathHelper;
  6. public class DeviceOfPartDataProxy : DataProxy
  7. {
  8. public string m_TableName;
  9. public List<PartDataInfo> m_PartInfos;
  10. public List<CustomPartData> m_CustomInfos;
  11. public List<GameObject> objects = new List<GameObject>();
  12. public override void OnRegister()
  13. {
  14. }
  15. public PartDataInfo GetPartInfoByPartName(string partName)
  16. {
  17. return m_PartInfos.Find(t => t.partName == partName);
  18. }
  19. /// <summary>
  20. /// 从Excel文件读取流程信息
  21. /// </summary>
  22. /// <param name="tableName">表名</param>
  23. /// <param name="headCount">表头</param>
  24. /// <returns></returns>
  25. public List<PartDataInfo> ReadStepMsgInfoFromTable(string tableName)
  26. {
  27. m_TableName = tableName + GlobalConfig.excelSuffix;
  28. m_PartInfos = new List<PartDataInfo>();
  29. string tmpPath = System.IO.Path.Combine(GlobalConfig.partTablePath, m_TableName);
  30. if (File.Exists(tmpPath))
  31. {
  32. m_PartInfos = ExcelHelper.ReadInfoFromExcel<PartDataInfo>(tmpPath, 1);
  33. }
  34. return m_PartInfos;
  35. }
  36. public List<CustomPartData> ReadCustomInfoFromTable(string tableName)
  37. {
  38. m_TableName = tableName + GlobalConfig.excelSuffix;
  39. m_CustomInfos = new List<CustomPartData>();
  40. string tmpPath = System.IO.Path.Combine(GlobalConfig.partEditTablePath, m_TableName);
  41. if (File.Exists(tmpPath))
  42. {
  43. m_CustomInfos = ExcelHelper.ReadInfoFromExcel<CustomPartData>(tmpPath, 1);
  44. }
  45. return m_CustomInfos;
  46. }
  47. public CustomPartData GetCustomByEditPartName(string partName)
  48. {
  49. return m_CustomInfos.Find(t => t.editName == partName);
  50. }
  51. public CustomPartData GetCustomByPartName(string partName)
  52. {
  53. return m_CustomInfos.Find(t => t.partName == partName);
  54. }
  55. public CustomPartData GetCustomByIdName(string id)
  56. {
  57. return m_CustomInfos.Find(t => t.id == id);
  58. }
  59. public void CoverTableInfos()
  60. {
  61. for (int i = 0; i < m_CustomInfos.Count; i++)
  62. {
  63. PartDataInfo tmpInfo = GetPartInfoByPartName(m_CustomInfos[i].partName);
  64. if(tmpInfo != null)
  65. {
  66. if (!string.IsNullOrEmpty(m_CustomInfos[i].editName))
  67. tmpInfo.partName = m_CustomInfos[i].editName;
  68. tmpInfo.audioClipName = m_CustomInfos[i].audioClipName;
  69. }
  70. }
  71. }
  72. public void endTableEditInfos(bool first = false)
  73. {
  74. List<RestoreData> datas = new List<RestoreData>();
  75. for (int i = 0; i < m_CustomInfos.Count; i++)
  76. {
  77. int j = i;
  78. GameObject tmpObj = GameObject.Find(m_CustomInfos[j].AbsolutePath);
  79. objects.Add(tmpObj);
  80. datas.Add(new RestoreData(tmpObj.transform, m_CustomInfos[j].EditPath));
  81. }
  82. PartMark[] allObjs = DeviceController.instance.GetComponentsInChildren<PartMark>(true);
  83. new RestoreObjectPathHelper().RestoreHierarchy(datas, allObjs);
  84. for (int i = 0; i < m_CustomInfos.Count; i++)
  85. {
  86. objects[i].name = m_CustomInfos[i].editName;
  87. }
  88. foreach(PartMark tmpPark in allObjs) { tmpPark.InitData(); }
  89. }
  90. public void returnBackTable()
  91. {
  92. for (int i = 0; i < objects.Count; i++)
  93. {
  94. PartDataInfo tmpInfo = GetPartInfoByPartName(m_CustomInfos[i].partName);
  95. if (tmpInfo != null )
  96. {
  97. objects[i].name = tmpInfo.partName;
  98. }
  99. }
  100. m_CustomInfos.Clear();
  101. }
  102. }