From cbd3ba86b80c938f3e11c34731dec52ae17fe6a6 Mon Sep 17 00:00:00 2001 From: zxl Date: Fri, 22 Nov 2024 16:43:16 +0800 Subject: [PATCH] =?UTF-8?q?add=EF=BC=9A=E6=B7=BB=E5=8A=A0=E6=B5=81?= =?UTF-8?q?=E7=A8=8B=E5=BF=AB=E9=80=9F=E5=88=9B=E5=BB=BA=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GameRes/ProcedureLogicTemplate.txt | 10 ++++ .../GameRes/ProcedureLogicTemplate.txt.meta | 3 ++ .../GameScript/Editor/GenProcedureEditor.cs | 54 +++++++++++++++++++ .../Editor/GenProcedureEditor.cs.meta | 3 ++ .../Hotfix/Procedure/ProcedureAttribute.cs | 2 +- .../Hotfix/Procedure/ProcedureBase.cs | 2 +- 6 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 Assets/DemoGame/GameRes/ProcedureLogicTemplate.txt create mode 100644 Assets/DemoGame/GameRes/ProcedureLogicTemplate.txt.meta create mode 100644 Assets/DemoGame/GameScript/Editor/GenProcedureEditor.cs create mode 100644 Assets/DemoGame/GameScript/Editor/GenProcedureEditor.cs.meta diff --git a/Assets/DemoGame/GameRes/ProcedureLogicTemplate.txt b/Assets/DemoGame/GameRes/ProcedureLogicTemplate.txt new file mode 100644 index 0000000..cd63e0d --- /dev/null +++ b/Assets/DemoGame/GameRes/ProcedureLogicTemplate.txt @@ -0,0 +1,10 @@ +using Cysharp.Threading.Tasks; +using UnityEngine; + +namespace ZC +{ + [Procedure(ProcedureType.#CLASSNAME#)] + class #CLASSNAME# : ProcedureBase + { + } +} \ No newline at end of file diff --git a/Assets/DemoGame/GameRes/ProcedureLogicTemplate.txt.meta b/Assets/DemoGame/GameRes/ProcedureLogicTemplate.txt.meta new file mode 100644 index 0000000..08414f5 --- /dev/null +++ b/Assets/DemoGame/GameRes/ProcedureLogicTemplate.txt.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 91e9b42addbc4e5ea673fb5d36a7a685 +timeCreated: 1732263928 \ No newline at end of file diff --git a/Assets/DemoGame/GameScript/Editor/GenProcedureEditor.cs b/Assets/DemoGame/GameScript/Editor/GenProcedureEditor.cs new file mode 100644 index 0000000..d576632 --- /dev/null +++ b/Assets/DemoGame/GameScript/Editor/GenProcedureEditor.cs @@ -0,0 +1,54 @@ +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().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; + } + } + } +} \ No newline at end of file diff --git a/Assets/DemoGame/GameScript/Editor/GenProcedureEditor.cs.meta b/Assets/DemoGame/GameScript/Editor/GenProcedureEditor.cs.meta new file mode 100644 index 0000000..69e04fd --- /dev/null +++ b/Assets/DemoGame/GameScript/Editor/GenProcedureEditor.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 6fb1eb88d4e040b7bb68dc16235c1e7b +timeCreated: 1732263264 \ No newline at end of file diff --git a/Assets/DemoGame/GameScript/Hotfix/Procedure/ProcedureAttribute.cs b/Assets/DemoGame/GameScript/Hotfix/Procedure/ProcedureAttribute.cs index f752a5b..b8d8d8c 100644 --- a/Assets/DemoGame/GameScript/Hotfix/Procedure/ProcedureAttribute.cs +++ b/Assets/DemoGame/GameScript/Hotfix/Procedure/ProcedureAttribute.cs @@ -3,7 +3,7 @@ namespace ZC { [AttributeUsage(AttributeTargets.Class)] - class ProcedureAttribute: Attribute + public class ProcedureAttribute: Attribute { public ProcedureType ProcedureType { get; set; } diff --git a/Assets/DemoGame/GameScript/Hotfix/Procedure/ProcedureBase.cs b/Assets/DemoGame/GameScript/Hotfix/Procedure/ProcedureBase.cs index 4a169dd..6a926f1 100644 --- a/Assets/DemoGame/GameScript/Hotfix/Procedure/ProcedureBase.cs +++ b/Assets/DemoGame/GameScript/Hotfix/Procedure/ProcedureBase.cs @@ -3,7 +3,7 @@ using UnityEngine; namespace ZC { - abstract class ProcedureBase : IProcedure + public abstract class ProcedureBase : IProcedure { private ProcedureType _procedureType;