From c65b7024033505a6a78ac6794fbf2499de8eeb74 Mon Sep 17 00:00:00 2001 From: zhangxl <1062808664@qq.com> Date: Fri, 19 Jul 2024 16:19:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=8A=A8=E7=94=9F?= =?UTF-8?q?=E6=88=90=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GameScript/Editor/GenConfigCSEditor.cs | 108 ++++++++++++++++++ .../Editor/GenConfigCSEditor.cs.meta | 3 + 2 files changed, 111 insertions(+) create mode 100644 Assets/DemoGame/GameScript/Editor/GenConfigCSEditor.cs create mode 100644 Assets/DemoGame/GameScript/Editor/GenConfigCSEditor.cs.meta diff --git a/Assets/DemoGame/GameScript/Editor/GenConfigCSEditor.cs b/Assets/DemoGame/GameScript/Editor/GenConfigCSEditor.cs new file mode 100644 index 0000000..052d8b2 --- /dev/null +++ b/Assets/DemoGame/GameScript/Editor/GenConfigCSEditor.cs @@ -0,0 +1,108 @@ +using System; +using System.Diagnostics; +using System.IO; +using System.Text; +//using cfg; +using SimpleJSON; +using UnityEditor; +using UnityEngine; +using ZC; +using Debug = UnityEngine.Debug; + +namespace ZEditor +{ + /// + /// 配置文件工具(后面再完善把,暂时不想搞了) + /// + public class GenConfigCSEditor : Editor + { + [MenuItem("Tool/自动生成配置表和cs常量工具")] + public static void Gen() + { + Run(); + + string folderPath = @"Assets/DemoGame/GameRes/Config/JSON"; + +// // 获取文件夹下所有文件的完整路径 +// string[] files = Directory.GetFiles(folderPath, "*.*", SearchOption.AllDirectories); +// +// Tables tables; +// // 输出文件路径 +// foreach (string file in files) +// { +// if (file.Contains(".meta")) +// { +// continue; +// } +// +// tables = new cfg.Tables(JX); +// } + +// string gameConfDir = @"Assets/DemoGame/GameRes/Config/JSON"; // 替换为gen.bat中outputDataDir指向的目录 +// var tables = new cfg.Tables(file => JSON.Parse(File.ReadAllText($"{gameConfDir}/{file}.json"))); +// StringBuilder sb = new StringBuilder(); +// foreach (var item in tables.TbItem.DataMap) +// { +// string name = $"{item.Key}_{item.Value.Name}"; +// sb.AppendLine($"public const int {name} = {item.Key};"); +// } + } + + static void Run() + { + // 指定批处理文件的路径 + string pathToBatchFile = $"{Application.dataPath}".Replace("Assets", "Luban") + "/gen.bat"; + + Process process = new Process(); + + // 设置进程启动信息 + process.StartInfo.FileName = pathToBatchFile; + process.StartInfo.UseShellExecute = false; + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.RedirectStandardError = true; + process.StartInfo.CreateNoWindow = true; + + // 启动进程 + process.Start(); + + // 读取输出(如果需要) + string output = process.StandardOutput.ReadToEnd(); + string errors = process.StandardError.ReadToEnd(); + + // 等待进程结束 + process.WaitForExit(); + + // 可以将输出或错误信息打印到Unity的控制台 + UnityEngine.Debug.Log(output); + if (!string.IsNullOrEmpty(errors)) + { + UnityEngine.Debug.LogError(errors); + } + } + + private static JSONNode JX(string arg) + { + string path = String.Empty; + switch (arg) + { + case "item_tbitem": + path = AssetConst.Assets_DemoGame_GameRes_Config_JSON_item_tbitem_json; + break; + case "tbplayer": + path = AssetConst.Assets_DemoGame_GameRes_Config_JSON_tbplayer_json; + break; + default: + break; + } + + var textAsset = ResourcesLocalComponent.Instance.LoadAssetSync(path); + return JSON.Parse(textAsset.text); + } + +// [MenuItem("Tool/运行场景")] +// public static void Run() +// { +// EditorApplication.isPlaying = true; +// } + } +} \ No newline at end of file diff --git a/Assets/DemoGame/GameScript/Editor/GenConfigCSEditor.cs.meta b/Assets/DemoGame/GameScript/Editor/GenConfigCSEditor.cs.meta new file mode 100644 index 0000000..e300031 --- /dev/null +++ b/Assets/DemoGame/GameScript/Editor/GenConfigCSEditor.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 9f815f01838f40a4b9be377d51589289 +timeCreated: 1721372740 \ No newline at end of file