78 lines
2.4 KiB
C#
78 lines
2.4 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text;
|
|
using Sirenix.OdinInspector;
|
|
using Sirenix.OdinInspector.Editor;
|
|
using UnityEngine;
|
|
|
|
namespace Editor.GenResourcePathEditor
|
|
{
|
|
public class GenResourcePathEditor : OdinEditorWindow
|
|
{
|
|
[UnityEditor.MenuItem("Tool/ZC/GenResourcePathEditor")]
|
|
private static void OpenWindow()
|
|
{
|
|
GetWindow<GenResourcePathEditor>().Show();
|
|
}
|
|
|
|
[FolderPath] public List<string> assetFolderPaths;
|
|
|
|
[FolderPath] public string scriptGenFolderPath;
|
|
|
|
[Button("GenGen")]
|
|
public void Gen()
|
|
{
|
|
if (assetFolderPaths.Count == 0 || string.IsNullOrEmpty(this.scriptGenFolderPath))
|
|
{
|
|
Debug.LogError("the folder ??");
|
|
return;
|
|
}
|
|
|
|
List<string> pathList = new List<string>();
|
|
List<string> nameList = new List<string>();
|
|
foreach (var assetFolderPath in this.assetFolderPaths)
|
|
{
|
|
var files = Directory.GetFiles(assetFolderPath);
|
|
foreach (var s in files)
|
|
{
|
|
string assetPath = s.Replace("\\", "/"); // 确保路径格式正确
|
|
if (assetPath.Contains(".meta")) continue;
|
|
|
|
pathList.Add(assetPath);
|
|
var names = assetPath.Replace("/", "_").Split(".");
|
|
nameList.Add(names[0]);
|
|
}
|
|
}
|
|
|
|
GenScript(pathList, nameList);
|
|
}
|
|
|
|
private void GenScript(List<string> pathList, List<string> nameList)
|
|
{
|
|
var path = this.scriptGenFolderPath + "/AssetPathConst.cs";
|
|
|
|
using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate))
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
sb.AppendLine("public class AssetConstPath\n {");
|
|
|
|
for (var i = 0; i < pathList.Count; i++)
|
|
{
|
|
string s = @"public const string NAME = ""PATH"";";
|
|
var nameRe = s.Replace("NAME", nameList[i]).Replace("PATH", pathList[i]);
|
|
sb.AppendLine(nameRe);
|
|
Debug.Log(nameRe);
|
|
}
|
|
|
|
sb.AppendLine("}");
|
|
|
|
string context = sb.ToString();
|
|
var bytes = Encoding.UTF8.GetBytes(context);
|
|
fs.Write(bytes);
|
|
|
|
fs.Dispose();
|
|
}
|
|
}
|
|
}
|
|
} |