HAARFTE/Assets/DemoGame/GameScript/Editor/GenProcedureEditor.cs

54 lines
1.5 KiB
C#
Raw Permalink Normal View History

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Sirenix.OdinInspector;
using Sirenix.OdinInspector.Editor;
using TMPro;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
using ZC;
namespace ZEditor
{
public class GenProcedureEditor : OdinEditorWindow
{
public string logicFolderPath = $"{Application.dataPath}/DemoGame/GameScript/Hotfix/Procedure/Logic";
public string templatePath = $"{Application.dataPath}/DemoGame/GameRes/ProcedureLogicTemplate.txt";
public string className;
[MenuItem("Tool/ProcedureTool")]
public static void OpenWin()
{
GetWindow<GenProcedureEditor>().Show();
}
[Button("创建")]
void Gen()
{
if (string.IsNullOrEmpty(className))
{
Debug.LogError($"{className} is null !!! ");
return;
}
var tmpName = $"{this.className}Procedure";
string filePath = $"{logicFolderPath}/{tmpName}.cs";
string allText;
if (!File.Exists(filePath))
{
File.Create(filePath).Dispose();
allText = File.ReadAllText(templatePath);
allText = allText.Replace("#CLASSNAME#", tmpName);
File.WriteAllText(filePath, allText);
}
else
{
Debug.LogError($"重复!已存在{tmpName}.cs文件");
return;
}
}
}
}