From 9c1b8182288a8c9d5386518d4cc28b72ecfe78da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E5=8D=B4?= <479813005@qq.com> Date: Sat, 27 Jan 2024 13:28:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=89=B9=E6=80=A7=E6=A0=87?= =?UTF-8?q?=E8=AE=B0=E7=9A=84=E6=96=B9=E6=B3=95=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Attribute/EditorButtonAttribute.cs | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/Megumin.UnityPackage/Packages/megumin.explosion4unity/Runtime/Scripts/NewClass/Attribute/EditorButtonAttribute.cs b/Megumin.UnityPackage/Packages/megumin.explosion4unity/Runtime/Scripts/NewClass/Attribute/EditorButtonAttribute.cs index 2580cb3..6494cde 100644 --- a/Megumin.UnityPackage/Packages/megumin.explosion4unity/Runtime/Scripts/NewClass/Attribute/EditorButtonAttribute.cs +++ b/Megumin.UnityPackage/Packages/megumin.explosion4unity/Runtime/Scripts/NewClass/Attribute/EditorButtonAttribute.cs @@ -471,16 +471,18 @@ public static string MethodParameterDisplayName(ParameterInfo parameterInfo, boo return parameterTypeDisplayName + " " + parameterInfo.Name; } - public static string MethodDisplayName(MethodInfo method) + public static string MethodDisplayName(MethodInfo method, Attribute drawAttribute) { string editorButtonName = ""; bool useTypeFullName = false; - if (Attribute.IsDefined(method, typeof(ButtonAttribute))) + if (drawAttribute is ButtonAttribute buttonAttribute) { - ButtonAttribute tmp = - (ButtonAttribute)Attribute.GetCustomAttribute(method, typeof(ButtonAttribute)); - editorButtonName = tmp.ButtonName; - useTypeFullName = tmp.UseTypeFullName; + editorButtonName = buttonAttribute.ButtonName; + useTypeFullName = buttonAttribute.UseTypeFullName; + } + else if (drawAttribute is ContextMenu contextMenu) + { + editorButtonName = contextMenu.menuItem; } if (string.IsNullOrEmpty(editorButtonName)) @@ -523,18 +525,19 @@ public static string MethodUID(MethodInfo method) return sb.ToString(); } + [Obsolete("", true)] public static void DrawButtonforMethod(Object target, MethodInfo methodInfo, EditorButtonState state, bool onlyPlaying) { - DrawButtonforMethod(target, methodInfo, state, onlyPlaying ? 1 : 0); + DrawButtonforMethod(target, methodInfo, null, state, onlyPlaying ? 1 : 0); } public static void DrawButtonforMethod(Object target, DrawMethod drawMethod) { - DrawButtonforMethod(target, drawMethod.Method, drawMethod.State, drawMethod.EnableMode, drawMethod); + DrawButtonforMethod(target, drawMethod.Method, drawMethod.Attribute, drawMethod.State, drawMethod.EnableMode, drawMethod); } /// @@ -550,6 +553,7 @@ public static void DrawButtonforMethod(Object target, /// public static void DrawButtonforMethod(Object target, MethodInfo methodInfo, + Attribute drawAttribute, EditorButtonState state, int enableMode = 0, DrawMethod drawMethod = null) @@ -586,7 +590,7 @@ public static void DrawButtonforMethod(Object target, EditorGUI.BeginDisabledGroup(!enable); //绘制按钮 - string buttonName = MethodDisplayName(methodInfo); + string buttonName = MethodDisplayName(methodInfo, drawAttribute); GUIContent button = new GUIContent(buttonName); button.tooltip = drawMethod?.Tooltip?.tooltip; bool clicked = GUILayout.Button(button, GUILayout.ExpandWidth(true));