diff --git a/Assets/DemoGame/GameScript/Editor/GenAssetConstEditor.cs b/Assets/DemoGame/GameScript/Editor/GenAssetConstEditor.cs index 6452b07..cf38396 100644 --- a/Assets/DemoGame/GameScript/Editor/GenAssetConstEditor.cs +++ b/Assets/DemoGame/GameScript/Editor/GenAssetConstEditor.cs @@ -8,38 +8,56 @@ using UnityEngine; namespace ZEditor { - public class GenAssetConstEditor : OdinEditorWindow + public class GenAssetConstEditor : Editor { +// [MenuItem("Tool/自动生成资源常量代码")] +// static void Open() +// { +// GetWindow().Show(); +// } + + public static string csName = "AssetConst"; + public static string loaderCsName = "LoaderAssetConst"; + [FolderPath] public static string folderPath = "Assets/DemoGame/GameScript/Hotfix/Const"; + [FolderPath] public static string loaderFolderPath = "Assets/DemoGame/GameScript/Loader/Const"; + [FolderPath] public static string resPath = "Assets/DemoGame/GameRes"; + [Sirenix.OdinInspector.FilePath] public static string template = "Assets/DemoGame/GameRes/AssetsConstTemplate.txt"; + [MenuItem("Tool/自动生成资源常量代码")] - static void Open() + static void GG() { - GetWindow().Show(); + Gen(); } - public string csName = "AssetConst"; - [FolderPath] public string folderPath = "Assets/DemoGame/GameScript/Hotfix/Const"; - [FolderPath] public string resPath = "Assets/DemoGame/GameRes"; - [Sirenix.OdinInspector.FilePath] public string template = "Assets/DemoGame/GameRes/AssetsConstTemplate.txt"; - [Button] - public void Gen() + public static void Gen() { - string path = $"{this.folderPath}/{this.csName}.cs"; + string path = $"{folderPath}/{csName}.cs"; + string loaderPath = $"{loaderFolderPath}/{loaderCsName}.cs"; StringBuilder sb = new StringBuilder(); - this.Bridging(ref sb, this.resPath); + Bridging(ref sb, resPath); - var readAllText = File.ReadAllText(this.template); - var content = readAllText.Replace("#CONSTCONTENT#", sb.ToString()).Replace("\\", "/"); + var readAllText = File.ReadAllText(template); + var content = readAllText.Replace("#CONSTCONTENT#", sb.ToString()).Replace("\\", "/").Replace("#CLASSNAME#", "AssetConst"); + var loaderContent = readAllText.Replace("#CONSTCONTENT#", sb.ToString()).Replace("\\", "/").Replace("#CLASSNAME#", "LoaderAssetConst"); if (!File.Exists(path)) { File.Create(path).Dispose(); } + if (!File.Exists(loaderPath)) + { + File.Create(loaderPath).Dispose(); + } + File.WriteAllText(path, content); + File.WriteAllText(loaderPath, loaderContent); + + Debug.Log("生成完成!"); } - void Bridging(ref StringBuilder sb, string path) + static void Bridging(ref StringBuilder sb, string path) { DirectoryInfo info = new DirectoryInfo(path); var fileInfos = info.GetFiles(); @@ -59,7 +77,7 @@ namespace ZEditor foreach (var directoryInfo in directoryInfos) { - this.Bridging(ref sb, directoryInfo.FullName); + Bridging(ref sb, directoryInfo.FullName); } } }