From 5b8daa5c138a4be9504b8c97a9ae7b7667362d51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E5=8D=B4?= <479813005@qq.com> Date: Thu, 8 Feb 2024 10:59:19 +0800 Subject: [PATCH] =?UTF-8?q?NewButton=E7=9A=84Enabled=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=AE=BE=E7=BD=AE=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NewClass/Attribute/NewButtonAttribute.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Megumin.UnityPackage/Packages/megumin.explosion4unity/Runtime/Scripts/NewClass/Attribute/NewButtonAttribute.cs b/Megumin.UnityPackage/Packages/megumin.explosion4unity/Runtime/Scripts/NewClass/Attribute/NewButtonAttribute.cs index 5312c34..af6b574 100644 --- a/Megumin.UnityPackage/Packages/megumin.explosion4unity/Runtime/Scripts/NewClass/Attribute/NewButtonAttribute.cs +++ b/Megumin.UnityPackage/Packages/megumin.explosion4unity/Runtime/Scripts/NewClass/Attribute/NewButtonAttribute.cs @@ -31,6 +31,11 @@ public class NewButtonAttribute : PropertyAttribute /// public bool CanExpand { get; set; } = true; + /// + /// 指定一个bool值属性作为开关。并将Toggle绘制在外侧顶部。 + /// + public string EnabledPropertyPath { get; set; } = "Enabled"; + public NewButtonAttribute() { @@ -306,7 +311,13 @@ protected void DrawReference(SerializedProperty property, GUIContent label, Rect #region 绘制额外的开启关闭Toggle //当序列化对象允许设置开启关闭时,将开启关闭开关绘制在外层 - SerializedProperty toggle = property.FindPropertyRelative("Enabled"); + var enabledPath = "Enabled"; + if (attribute is NewButtonAttribute newButtonAttribute) + { + enabledPath = newButtonAttribute.EnabledPropertyPath; + } + + SerializedProperty toggle = property.FindPropertyRelative(enabledPath); if (toggle != null) { var toggleRect = textPosition;