Skip to content

Commit

Permalink
NewButton的Enabled标签支持设置自定义路径
Browse files Browse the repository at this point in the history
  • Loading branch information
KumoKyaku committed Feb 8, 2024
1 parent c9dcfe5 commit 5b8daa5
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public class NewButtonAttribute : PropertyAttribute
/// </summary>
public bool CanExpand { get; set; } = true;

/// <summary>
/// 指定一个bool值属性作为开关。并将Toggle绘制在外侧顶部。
/// </summary>
public string EnabledPropertyPath { get; set; } = "Enabled";

public NewButtonAttribute()
{

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 5b8daa5

Please sign in to comment.