OperationTableWindow.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. using System.Collections.Generic;
  2. using Sirenix.OdinInspector;
  3. using Sirenix.OdinInspector.Editor;
  4. using UnityEditor;
  5. using System.IO;
  6. using System.Text.RegularExpressions;
  7. using System.Diagnostics;
  8. namespace ChivaXR.Op
  9. {
  10. public class OperationTableWindow : OdinEditorWindow
  11. {
  12. [MenuItem("ChivaTool/流程表格生成器")]
  13. private static void OpenWindow()
  14. {
  15. GetWindow<OperationTableWindow>().Show();
  16. }
  17. [TabGroup("生成新表格")]
  18. [HideLabel]
  19. [LabelText("表格名称")]
  20. [OnValueChanged("OperationTableNameChange")]
  21. public string operationTableName;
  22. [TabGroup("生成新表格")]
  23. [FolderPath]
  24. [HideLabel]
  25. [LabelText("表格生成路径")]
  26. public string savePath;
  27. [TabGroup("生成新表格")]
  28. [HideLabel]
  29. [LabelText("是否保存原数据")]
  30. public bool isSaveOldData;
  31. [TabGroup("生成新表格")]
  32. [Button("生成表格", ButtonSizes.Medium)]
  33. [GUIColor(0.7f, 1, 0.7f)]
  34. public void CreateOpreationTables()
  35. {
  36. string tmpFileFath = savePath + "/" + operationTableName;
  37. //从场景中获取到的流程数据
  38. List<OperationStepDataInfo> currentSceneOperation = GetCurrentSceneOperationData();
  39. if (File.Exists(tmpFileFath) && isSaveOldData)
  40. {
  41. //从表格中读取到的表格数据
  42. List<OperationStepDataInfo> operationsFromTable = ExcelHelper.ReadInfoFromExcel<OperationStepDataInfo>(filePath,1);
  43. foreach (var item in currentSceneOperation)
  44. {
  45. OperationStepDataInfo tmpInfo = operationsFromTable.Find(op => op.guid == item.guid);
  46. if (tmpInfo != null)
  47. {
  48. item.stepMark = tmpInfo.stepMark;
  49. item.stepName = tmpInfo.stepName;
  50. item.audioClipName = tmpInfo.audioClipName;
  51. }
  52. }
  53. }
  54. ExcelHelper.WriteInfoToExcel(tmpFileFath, currentSceneOperation);
  55. //刷新
  56. AssetDatabase.Refresh();
  57. }
  58. [TabGroup("表格数据修改")]
  59. [Title("表格保存路径")]
  60. [FilePath(Extensions = ".xlsx")]
  61. [OnValueChanged("ReadOprationTableBtnClick")]
  62. public string filePath;
  63. [TabGroup("表格数据修改")]
  64. [Button("读取表格")]
  65. [GUIColor(0.7f, 1, 0.7f)]
  66. public void ReadOprationTableBtnClick()
  67. {
  68. infos = ExcelHelper.ReadInfoFromExcel<OperationStepDataInfo>(filePath,1);
  69. }
  70. [TabGroup("表格数据修改")]
  71. [Button("保存修改")]
  72. [GUIColor(0.7f, 1, 0.7f)]
  73. public void SaveOperationTableModify()
  74. {
  75. ExcelHelper.WriteInfoToExcel(filePath,infos);
  76. }
  77. [TabGroup("表格数据修改")]
  78. [Button("打开表格")]
  79. [GUIColor(0.7f, 1, 0.7f)]
  80. public void OpenOperationTable()
  81. {
  82. string tmpPath = Path.GetFullPath(filePath);
  83. Process.Start(tmpPath);
  84. }
  85. [TabGroup("表格数据修改")]
  86. [Title("表格数据预览")]
  87. [GUIColor(0.7f, 1, 0.7f)]
  88. [TableList(IsReadOnly = true)]
  89. public List<OperationStepDataInfo> infos;
  90. public void ReadOperationFromTable()
  91. {
  92. }
  93. /// <summary>
  94. /// 获取当前场景的流程信息
  95. /// </summary>
  96. /// <returns></returns>
  97. private List<OperationStepDataInfo> GetCurrentSceneOperationData()
  98. {
  99. List<OperationStepDataInfo> operationInfos = new List<OperationStepDataInfo>();
  100. #region 旧代码
  101. // for (int i = 0; i < ProcessManagement.Instance.processes.Count; i++)
  102. // {
  103. // OperationStepDataInfo operationInfo = new OperationStepDataInfo();
  104. //
  105. // ProcessElement tmpProcessElement = ProcessManagement.Instance.processes[i];
  106. //
  107. // PB_OpData tmpPb_OpData = (PB_OpData)tmpProcessElement.processBase;
  108. //
  109. // string tmpOperationDataName = tmpPb_OpData.opData.operationDataName;
  110. //
  111. // OpDataContainer tmpOpDataContainer = OperationManager.Instance.operationDataContainers.Find(t => tmpOperationDataName == t.OpDataName);
  112. //
  113. // string tmpOpDataId = Regex.Match(tmpOpDataContainer.OpDataName, @"^\d+").Value;
  114. // //ID为ProcessElement的ID
  115. // operationInfo.id = tmpProcessElement.stepID.ToString();
  116. // //OpData为OpDataContainer的OpDataName
  117. // operationInfo.stepMark = tmpOpDataContainer.OpDataName;
  118. // //guid为OpDataContainer的guid(guid值为唯一值,将作为表格比对的唯一值)
  119. // operationInfo.guid = tmpOpDataContainer.guid;
  120. //
  121. // List<string> choseToolNames = null;
  122. //
  123. // if (tmpOpDataContainer.opData.gameObject.GetComponent<OpTrigger_ToolPack>() != null)
  124. // {
  125. // choseToolNames = tmpOpDataContainer.opData.gameObject.GetComponent<OpTrigger_ToolPack>().choseToolNames;
  126. // }
  127. //
  128. // if (choseToolNames == null || choseToolNames.Count == 0) operationInfo.toolName = "";
  129. // else operationInfo.toolName = choseToolNames[0];
  130. //
  131. // operationInfos.Add(operationInfo);
  132. // }
  133. #endregion
  134. for (int i = 0; i < ProcessManagement.Instance.processes.Count; i++)
  135. {
  136. ProcessElement tmpProcessElement = ProcessManagement.Instance.processes[i];
  137. if (tmpProcessElement.transform.GetComponent<PB_OpData>() != null)
  138. {
  139. #region PB_OpData
  140. OperationStepDataInfo operationInfo = new OperationStepDataInfo();
  141. //ProcessElement tmpProcessElement = ProcessManagement.Instance.processes[i];
  142. PB_OpData tmpPb_OpData = (PB_OpData)tmpProcessElement.processBase;
  143. string tmpOperationDataName = tmpPb_OpData.opData.operationDataName;
  144. OpDataContainer tmpOpDataContainer = OperationManager.Instance.operationDataContainers.Find(t => tmpOperationDataName == t.OpDataName);
  145. string tmpOpDataId = Regex.Match(tmpOpDataContainer.OpDataName, @"^\d+").Value;
  146. //ID为ProcessElement的ID
  147. operationInfo.id = tmpProcessElement.stepID.ToString();
  148. //OpData为OpDataContainer的OpDataName
  149. operationInfo.stepMark = tmpOpDataContainer.OpDataName;
  150. //guid为OpDataContainer的guid(guid值为唯一值,将作为表格比对的唯一值)
  151. operationInfo.guid = tmpOpDataContainer.guid;
  152. List<string> choseToolNames = null;
  153. if (tmpOpDataContainer.opData.gameObject.GetComponent<OpTrigger_ToolPack>() != null)
  154. {
  155. choseToolNames = tmpOpDataContainer.opData.gameObject.GetComponent<OpTrigger_ToolPack>().choseToolNames;
  156. }
  157. if (choseToolNames == null || choseToolNames.Count == 0) operationInfo.toolName = "";
  158. else operationInfo.toolName = choseToolNames[0];
  159. operationInfos.Add(operationInfo);
  160. #endregion
  161. }
  162. else if (tmpProcessElement.transform.GetComponent<PB_OpDataGroup>() != null)
  163. {
  164. #region
  165. OperationStepDataInfo operationInfo = new OperationStepDataInfo();
  166. PB_OpDataGroup tmpPb_OpData = (PB_OpDataGroup)tmpProcessElement.processBase;
  167. string tmpOperationDataName = tmpPb_OpData.groupDescribe;
  168. //ID为ProcessElement的ID
  169. operationInfo.id = tmpProcessElement.stepID.ToString();
  170. //OpData为OpDataContainer的OpDataName
  171. operationInfo.stepMark = tmpOperationDataName;
  172. //guid为OpDataContainer的guid(guid值为唯一值,将作为表格比对的唯一值)
  173. //operationInfo.guid = tmpOpDataContainer.guid;
  174. List<string> choseToolNames = null;
  175. if (choseToolNames == null || choseToolNames.Count == 0) operationInfo.toolName = "";
  176. else operationInfo.toolName = choseToolNames[0];
  177. operationInfos.Add(operationInfo);
  178. #endregion
  179. }
  180. }
  181. return operationInfos;
  182. }
  183. private void OperationTableNameChange(string name)
  184. {
  185. if (name.Contains(".xlsx")) return;
  186. operationTableName = operationTableName + ".xlsx";
  187. }
  188. }
  189. }