parent
11469300ce
commit
ea2dad7d64
|
@ -8,38 +8,56 @@ using UnityEngine;
|
||||||
|
|
||||||
namespace ZEditor
|
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/自动生成资源常量代码")]
|
[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]
|
[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();
|
StringBuilder sb = new StringBuilder();
|
||||||
this.Bridging(ref sb, this.resPath);
|
Bridging(ref sb, resPath);
|
||||||
|
|
||||||
var readAllText = File.ReadAllText(this.template);
|
var readAllText = File.ReadAllText(template);
|
||||||
var content = readAllText.Replace("#CONSTCONTENT#", sb.ToString()).Replace("\\", "/");
|
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))
|
if (!File.Exists(path))
|
||||||
{
|
{
|
||||||
File.Create(path).Dispose();
|
File.Create(path).Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!File.Exists(loaderPath))
|
||||||
|
{
|
||||||
|
File.Create(loaderPath).Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
File.WriteAllText(path, content);
|
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);
|
DirectoryInfo info = new DirectoryInfo(path);
|
||||||
var fileInfos = info.GetFiles();
|
var fileInfos = info.GetFiles();
|
||||||
|
@ -59,7 +77,7 @@ namespace ZEditor
|
||||||
|
|
||||||
foreach (var directoryInfo in directoryInfos)
|
foreach (var directoryInfo in directoryInfos)
|
||||||
{
|
{
|
||||||
this.Bridging(ref sb, directoryInfo.FullName);
|
Bridging(ref sb, directoryInfo.FullName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue