【m】111
This commit is contained in:
132
Assets/00.ARMazTools/Editor/ResFileGet.cs
Normal file
132
Assets/00.ARMazTools/Editor/ResFileGet.cs
Normal file
@@ -0,0 +1,132 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Stary.Evo.Editor
|
||||
{
|
||||
public static class ResFileGet
|
||||
{
|
||||
public static void CreateContent(StringBuilder variable, string path, string tab)
|
||||
{
|
||||
tab += "\t\t";
|
||||
DirectoryInfo dir = new DirectoryInfo(path);
|
||||
DirectoryInfo[] first = dir.GetDirectories();
|
||||
FileInfo[] fil = dir.GetFiles();
|
||||
if (first.Length > 0)
|
||||
{
|
||||
foreach (FileInfo f in fil)
|
||||
{
|
||||
CreateFile(variable, f, tab);
|
||||
}
|
||||
|
||||
foreach (DirectoryInfo f in first)
|
||||
{
|
||||
CreateFolder(variable, f, tab);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (FileInfo f in fil)
|
||||
{
|
||||
CreateFile(variable, f, tab);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成脚本文件
|
||||
/// </summary>
|
||||
/// <param name="className">类名</param>
|
||||
/// <param name="content">字符串事件</param>
|
||||
public static void CreateClass(string className, string package, string outputPath,
|
||||
Action<StringBuilder> content = null)
|
||||
{
|
||||
string tdClassName = className;
|
||||
tdClassName = FilesUtils.ChineseToPinYin(tdClassName.Replace(".", "_"), false)
|
||||
.Replace(" ", "")
|
||||
.Replace("-", "_")
|
||||
.Replace(".", "_"); // 保留点号替换为下划线
|
||||
|
||||
package = FilesUtils.ChineseToPinYin(package.Replace(".", "_"), false)
|
||||
.Replace(" ", "")
|
||||
.Replace("-", "_")
|
||||
.Replace(".", "_"); // 保留点号替换为下划线
|
||||
StringBuilder variable = new StringBuilder();
|
||||
//variable.Append("using System;\n");
|
||||
variable.Append("namespace " + "R" + "\n");
|
||||
variable.Append("{\n");
|
||||
variable.Append("\tpublic class " + tdClassName + "\n");
|
||||
variable.Append("\t{\n");
|
||||
variable.Append("\t\tpublic class " + package + "\n");
|
||||
variable.Append("\t\t{\n");
|
||||
content?.Invoke(variable);
|
||||
|
||||
variable.Append("\t\t}\n");
|
||||
variable.Append("\t}\n");
|
||||
variable.Append("}");
|
||||
|
||||
if (!Directory.Exists(outputPath))
|
||||
{
|
||||
Directory.CreateDirectory(outputPath);
|
||||
}
|
||||
|
||||
outputPath = $"{outputPath}/{tdClassName}.cs";
|
||||
if (File.Exists(outputPath))
|
||||
{
|
||||
File.Delete(outputPath);
|
||||
}
|
||||
|
||||
FileHelper.WriteFile(outputPath, variable.ToString());
|
||||
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件夹生成
|
||||
/// </summary>
|
||||
/// <param name="folderName"></param>
|
||||
private static void CreateFolder(StringBuilder variable, DirectoryInfo folderName, string tab)
|
||||
{
|
||||
string classname = FilesUtils.ChineseToPinYin(folderName.Name, false);
|
||||
variable.Append(tab + " public static class " + classname + "\n");
|
||||
variable.Append(tab + "{\n");
|
||||
CreateContent(variable, folderName.FullName, tab);
|
||||
|
||||
variable.Append(tab + "}\n");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件生成
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
private static void CreateFile(StringBuilder variable, FileInfo fileName, string tab)
|
||||
{
|
||||
var fullname = System.IO.Path.GetExtension(fileName.FullName);
|
||||
if (fullname != ".meta" && fullname != ".hint"&& fullname != ".txt")
|
||||
{
|
||||
Debug.Log("FileInfo:" + fileName.Name);
|
||||
string filepath="";
|
||||
if (MarkAdressable.addressDic.ContainsKey(fileName.FullName))
|
||||
{
|
||||
filepath = MarkAdressable.addressDic[fileName.FullName];
|
||||
}
|
||||
if (string.IsNullOrEmpty(filepath))
|
||||
{
|
||||
Debug.LogError("未找到地址,请检查资源自动化标记逻辑:" + fileName.FullName);
|
||||
}
|
||||
|
||||
string name = FilesUtils.ChineseToPinYin(fileName.Name.Replace(".", "_"), false)
|
||||
.Replace(" ", "")
|
||||
.Replace("-", "_")
|
||||
.Replace(".", "_"); // 保留点号替换为下划线
|
||||
variable.Append(tab + "public const string " + name + " = \"" + filepath + "\";\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user