123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- using System.Collections.Generic;
- using Sirenix.OdinInspector;
- using Sirenix.OdinInspector.Editor;
- using UnityEditor;
- using System.IO;
- using System.Text.RegularExpressions;
- using System.Diagnostics;
- namespace ChivaXR.Op
- {
- public class OperationTableWindow : OdinEditorWindow
- {
- [MenuItem("ChivaTool/流程表格生成器")]
- private static void OpenWindow()
- {
- GetWindow<OperationTableWindow>().Show();
- }
- [TabGroup("生成新表格")]
- [HideLabel]
- [LabelText("表格名称")]
- [OnValueChanged("OperationTableNameChange")]
- public string operationTableName;
- [TabGroup("生成新表格")]
- [FolderPath]
- [HideLabel]
- [LabelText("表格生成路径")]
- public string savePath;
- [TabGroup("生成新表格")]
- [HideLabel]
- [LabelText("是否保存原数据")]
- public bool isSaveOldData;
- [TabGroup("生成新表格")]
- [Button("生成表格", ButtonSizes.Medium)]
- [GUIColor(0.7f, 1, 0.7f)]
- public void CreateOpreationTables()
- {
- string tmpFileFath = savePath + "/" + operationTableName;
- //从场景中获取到的流程数据
- List<OperationStepDataInfo> currentSceneOperation = GetCurrentSceneOperationData();
- if (File.Exists(tmpFileFath) && isSaveOldData)
- {
- //从表格中读取到的表格数据
- List<OperationStepDataInfo> operationsFromTable = ExcelHelper.ReadInfoFromExcel<OperationStepDataInfo>(filePath,1);
- foreach (var item in currentSceneOperation)
- {
- OperationStepDataInfo tmpInfo = operationsFromTable.Find(op => op.guid == item.guid);
- if (tmpInfo != null)
- {
- item.stepMark = tmpInfo.stepMark;
- item.stepName = tmpInfo.stepName;
- item.audioClipName = tmpInfo.audioClipName;
- }
- }
- }
- ExcelHelper.WriteInfoToExcel(tmpFileFath, currentSceneOperation);
- //刷新
- AssetDatabase.Refresh();
- }
- [TabGroup("表格数据修改")]
- [Title("表格保存路径")]
- [FilePath(Extensions = ".xlsx")]
- [OnValueChanged("ReadOprationTableBtnClick")]
- public string filePath;
- [TabGroup("表格数据修改")]
- [Button("读取表格")]
- [GUIColor(0.7f, 1, 0.7f)]
- public void ReadOprationTableBtnClick()
- {
- infos = ExcelHelper.ReadInfoFromExcel<OperationStepDataInfo>(filePath,1);
- }
- [TabGroup("表格数据修改")]
- [Button("保存修改")]
- [GUIColor(0.7f, 1, 0.7f)]
- public void SaveOperationTableModify()
- {
- ExcelHelper.WriteInfoToExcel(filePath,infos);
- }
- [TabGroup("表格数据修改")]
- [Button("打开表格")]
- [GUIColor(0.7f, 1, 0.7f)]
- public void OpenOperationTable()
- {
- string tmpPath = Path.GetFullPath(filePath);
- Process.Start(tmpPath);
- }
- [TabGroup("表格数据修改")]
- [Title("表格数据预览")]
- [GUIColor(0.7f, 1, 0.7f)]
- [TableList(IsReadOnly = true)]
- public List<OperationStepDataInfo> infos;
- public void ReadOperationFromTable()
- {
- }
- /// <summary>
- /// 获取当前场景的流程信息
- /// </summary>
- /// <returns></returns>
- private List<OperationStepDataInfo> GetCurrentSceneOperationData()
- {
- List<OperationStepDataInfo> operationInfos = new List<OperationStepDataInfo>();
- #region 旧代码
- // for (int i = 0; i < ProcessManagement.Instance.processes.Count; i++)
- // {
- // OperationStepDataInfo operationInfo = new OperationStepDataInfo();
- //
- // ProcessElement tmpProcessElement = ProcessManagement.Instance.processes[i];
- //
- // PB_OpData tmpPb_OpData = (PB_OpData)tmpProcessElement.processBase;
- //
- // string tmpOperationDataName = tmpPb_OpData.opData.operationDataName;
- //
- // OpDataContainer tmpOpDataContainer = OperationManager.Instance.operationDataContainers.Find(t => tmpOperationDataName == t.OpDataName);
- //
- // string tmpOpDataId = Regex.Match(tmpOpDataContainer.OpDataName, @"^\d+").Value;
- // //ID为ProcessElement的ID
- // operationInfo.id = tmpProcessElement.stepID.ToString();
- // //OpData为OpDataContainer的OpDataName
- // operationInfo.stepMark = tmpOpDataContainer.OpDataName;
- // //guid为OpDataContainer的guid(guid值为唯一值,将作为表格比对的唯一值)
- // operationInfo.guid = tmpOpDataContainer.guid;
- //
- // List<string> choseToolNames = null;
- //
- // if (tmpOpDataContainer.opData.gameObject.GetComponent<OpTrigger_ToolPack>() != null)
- // {
- // choseToolNames = tmpOpDataContainer.opData.gameObject.GetComponent<OpTrigger_ToolPack>().choseToolNames;
- // }
- //
- // if (choseToolNames == null || choseToolNames.Count == 0) operationInfo.toolName = "";
- // else operationInfo.toolName = choseToolNames[0];
- //
- // operationInfos.Add(operationInfo);
- // }
- #endregion
-
- for (int i = 0; i < ProcessManagement.Instance.processes.Count; i++)
- {
- ProcessElement tmpProcessElement = ProcessManagement.Instance.processes[i];
- if (tmpProcessElement.transform.GetComponent<PB_OpData>() != null)
- {
- #region PB_OpData
- OperationStepDataInfo operationInfo = new OperationStepDataInfo();
- //ProcessElement tmpProcessElement = ProcessManagement.Instance.processes[i];
- PB_OpData tmpPb_OpData = (PB_OpData)tmpProcessElement.processBase;
- string tmpOperationDataName = tmpPb_OpData.opData.operationDataName;
- OpDataContainer tmpOpDataContainer = OperationManager.Instance.operationDataContainers.Find(t => tmpOperationDataName == t.OpDataName);
- string tmpOpDataId = Regex.Match(tmpOpDataContainer.OpDataName, @"^\d+").Value;
- //ID为ProcessElement的ID
- operationInfo.id = tmpProcessElement.stepID.ToString();
- //OpData为OpDataContainer的OpDataName
- operationInfo.stepMark = tmpOpDataContainer.OpDataName;
- //guid为OpDataContainer的guid(guid值为唯一值,将作为表格比对的唯一值)
- operationInfo.guid = tmpOpDataContainer.guid;
- List<string> choseToolNames = null;
- if (tmpOpDataContainer.opData.gameObject.GetComponent<OpTrigger_ToolPack>() != null)
- {
- choseToolNames = tmpOpDataContainer.opData.gameObject.GetComponent<OpTrigger_ToolPack>().choseToolNames;
- }
- if (choseToolNames == null || choseToolNames.Count == 0) operationInfo.toolName = "";
- else operationInfo.toolName = choseToolNames[0];
- operationInfos.Add(operationInfo);
- #endregion
- }
- else if (tmpProcessElement.transform.GetComponent<PB_OpDataGroup>() != null)
- {
- #region
- OperationStepDataInfo operationInfo = new OperationStepDataInfo();
-
- PB_OpDataGroup tmpPb_OpData = (PB_OpDataGroup)tmpProcessElement.processBase;
- string tmpOperationDataName = tmpPb_OpData.groupDescribe;
-
- //ID为ProcessElement的ID
- operationInfo.id = tmpProcessElement.stepID.ToString();
- //OpData为OpDataContainer的OpDataName
- operationInfo.stepMark = tmpOperationDataName;
- //guid为OpDataContainer的guid(guid值为唯一值,将作为表格比对的唯一值)
- //operationInfo.guid = tmpOpDataContainer.guid;
- List<string> choseToolNames = null;
- if (choseToolNames == null || choseToolNames.Count == 0) operationInfo.toolName = "";
- else operationInfo.toolName = choseToolNames[0];
- operationInfos.Add(operationInfo);
- #endregion
- }
- }
- return operationInfos;
- }
- private void OperationTableNameChange(string name)
- {
- if (name.Contains(".xlsx")) return;
- operationTableName = operationTableName + ".xlsx";
- }
- }
- }
|