Update GenAssetConstEditor.cs

此生成内容不需要窗口,所以去掉odin内容
pull/1/head
zhangxl 2024-07-19 10:49:20 +08:00
parent 11469300ce
commit ea2dad7d64
1 changed files with 33 additions and 15 deletions

View File

@ -8,38 +8,56 @@ using UnityEngine;
namespace ZEditor
{
public class GenAssetConstEditor : OdinEditorWindow
public class GenAssetConstEditor : Editor
{
// [MenuItem("Tool/自动生成资源常量代码")]
// static void Open()
// {
// GetWindow<GenAssetConstEditor>().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<GenAssetConstEditor>().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);
}
}
}