IndieGame/client/Assets/Ether/Editor/Templete/TempTools.cs
2024-10-28 03:42:42 +08:00

48 lines
1.6 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Ether
{
public static class TempTools
{
/// <summary>
/// 生成类
/// </summary>
public static void GenerateClassFile(string className, string baseClassName, string content, string generatePath)
{
string tempClassStr = FileTools.ReadFile(PathTools.TempClassPath);
tempClassStr = tempClassStr.Replace("$ClassName$", className);
tempClassStr = tempClassStr.Replace("$BaseClassName$", baseClassName);
tempClassStr = tempClassStr.Replace("$Content$", content);
FileTools.WriteFile(generatePath, tempClassStr);
}
public static void GenerateEnumFile(string enumName, Dictionary<string, string> enumDic, string generatePath)
{
string tempEnumStr = FileTools.ReadFile(PathTools.TempEnumPath);
tempEnumStr = tempEnumStr.Replace("$EnumName$", enumName);
string tempStr = "";
foreach (var enumPair in enumDic)
{
if (!string.IsNullOrEmpty(enumPair.Value))
{
tempStr += $"\t\t[InspectorName(\"{enumPair.Value}\")]\n";
}
if (!string.IsNullOrEmpty(enumPair.Key))
{
tempStr += $"\t\t{enumPair.Key},\n";
}
}
tempEnumStr = tempEnumStr.Replace("$Content$", tempStr);
FileTools.WriteFile(generatePath, tempEnumStr);
}
}
}