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

54 lines
1.5 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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;
}
}
}
}