/* * @Author: 白哉 * @Description: * @Date: 2025年11月21日 星期五 16:11:31 * @Modify: */ using System.IO; using UnityEngine; using UnityEditor; using ExcelConfig; using Logic.Config; using Logic.CrashSight; public class ExcelEditorWIndow : EditorWindow { [MenuItem("Tools/导表工具")] public static void ShowWindow() { GetWindow("导表工具"); } private void OnGUI() { if (GUILayout.Button("清理")) { ClearFolder("../../ExcelExport/GenerateBytes"); ClearFolder("../../ExcelExport/GenerateCS"); ClearFolder("../../ExcelExport/GenerateCSPartial"); } if (GUILayout.Button("导CS")) { try { System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo.FileName = "cmd.exe"; process.StartInfo.WorkingDirectory = System.IO.Path.Combine(Application.dataPath, "../../ExcelExport"); process.StartInfo.Arguments = "/c dotnet run 1"; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.CreateNoWindow = true; process.Start(); string output = process.StandardOutput.ReadToEnd(); string error = process.StandardError.ReadToEnd(); process.WaitForExit(); if (!string.IsNullOrEmpty(output)) { Debug.Log($"导CS输出: {output}"); } if (!string.IsNullOrEmpty(error)) { Debug.LogError($"导CS错误: {error}"); } if (process.ExitCode == 0) { Debug.Log("导CS成功"); } else { Debug.LogError($"导CS失败,退出码: {process.ExitCode}"); } } catch (System.Exception ex) { Debug.LogError($"执行命令失败: {ex.Message}"); } } if (GUILayout.Button("导二进制")) { try { System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo.FileName = "cmd.exe"; process.StartInfo.WorkingDirectory = System.IO.Path.Combine(Application.dataPath, "../../ExcelExport"); process.StartInfo.Arguments = "/c dotnet run 2"; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.CreateNoWindow = true; process.Start(); string output = process.StandardOutput.ReadToEnd(); string error = process.StandardError.ReadToEnd(); process.WaitForExit(); if (!string.IsNullOrEmpty(output)) { Debug.Log($"导二进制输出: {output}"); } if (!string.IsNullOrEmpty(error)) { Debug.LogError($"导二进制错误: {error}"); } if (process.ExitCode == 0) { Debug.Log("导二进制成功"); } else { Debug.LogError($"导二进制失败,退出码: {process.ExitCode}"); } } catch (System.Exception ex) { Debug.LogError($"执行命令失败: {ex.Message}"); } } if (GUILayout.Button("移动文件")) { try { System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo.FileName = "cmd.exe"; process.StartInfo.WorkingDirectory = System.IO.Path.Combine(Application.dataPath, "../../ExcelExport"); process.StartInfo.Arguments = "/c dotnet run 3"; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.CreateNoWindow = true; process.Start(); string output = process.StandardOutput.ReadToEnd(); string error = process.StandardError.ReadToEnd(); process.WaitForExit(); if (!string.IsNullOrEmpty(output)) { Debug.Log($"移动文件输出: {output}"); } if (!string.IsNullOrEmpty(error)) { Debug.LogError($"移动文件错误: {error}"); } if (process.ExitCode == 0) { Debug.Log("移动文件成功"); } else { Debug.LogError($"移动文件失败,退出码: {process.ExitCode}"); } } catch (System.Exception ex) { Debug.LogError($"执行命令失败: {ex.Message}"); } } if(GUILayout.Button("转入 DataAsset")) { ConfigManager.Instance.InitExcelConfig(); string dataAssetPath = "DataAssets/GeoDataAssets"; GeoDataAssets geoDataAssets = Resources.Load(dataAssetPath); geoDataAssets.GeoItemList.Clear(); foreach (var i in GeoDescCategory.Dict.Keys) { if (!System.Enum.TryParse(GeoDescCategory.Dict[i].BigClass, out GeoBigClass bigClass)) { LogSystem.LogError($"ParseWrong {GeoDescCategory.Dict[i].BigClass}"); continue; } if (!System.Enum.TryParse(GeoDescCategory.Dict[i].SmallClass, out GeoSmallClass smallClass)) { LogSystem.LogError($"ParseWrong {GeoDescCategory.Dict[i].SmallClass}"); continue; } if (!System.Enum.TryParse(GeoDescCategory.Dict[i].CivEnum, out CivEnum civEnum)) { LogSystem.LogError($"ParseWrong {GeoDescCategory.Dict[i].CivEnum}"); continue; } var t = new GeoItem(); t.Id = (uint)GeoDescCategory.Dict[i].Id; t.GeoBigClass = bigClass; t.GeoSmallClass = smallClass; t.CivEnum = civEnum; t.GeoName = GeoDescCategory.Dict[i].GeoName; t.GeoDesc = GeoDescCategory.Dict[i].GeoDescStr; geoDataAssets.GeoItemList.Add(t); } EditorUtility.SetDirty(geoDataAssets); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); LogSystem.LogError($"GeoDescCategory.Dict.Count : {GeoDescCategory.Dict.Count}"); } } private static void ClearFolder(string relativeAssetsFolder) { if (string.IsNullOrWhiteSpace(relativeAssetsFolder)) { Debug.LogError("传入目录为空"); return; } var rel = relativeAssetsFolder.Trim().TrimStart('/', '\\'); var fullPath = Path.Combine(Application.dataPath, rel); if (!Directory.Exists(fullPath)) { Debug.LogWarning($"目录不存在: {fullPath}"); return; } // 删除文件 foreach (var file in Directory.GetFiles(fullPath, "*", SearchOption.TopDirectoryOnly)) { if (file.EndsWith(".meta")) continue; try { File.SetAttributes(file, FileAttributes.Normal); File.Delete(file); } catch (System.Exception ex) { Debug.LogError($"删除文件失败: {file} -> {ex.Message}"); } } Debug.Log($"已清理目录内容: {fullPath}"); } }