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 eb735c5 commit c9dcfe5
Showing 1 changed file with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,29 @@ protected void DrawReference(SerializedProperty property, GUIContent label, Rect
textPosition.xMax = propertyPosition.xMax;
textPosition.height = 18;

bool contentEnabled = true;
#region 绘制额外的开启关闭Toggle

//当序列化对象允许设置开启关闭时,将开启关闭开关绘制在外层
SerializedProperty toggle = property.FindPropertyRelative("Enabled");
if (toggle != null)
{
var toggleRect = textPosition;
toggleRect.width = 18;

EditorGUI.BeginProperty(toggleRect, GUIContent.none, toggle);
toggle.boolValue = GUI.Toggle(toggleRect, toggle.boolValue, GUIContent.none);
contentEnabled = toggle.boolValue;
EditorGUI.EndProperty();

textPosition.x += 20;
textPosition.width -= 20;
}

#endregion

//绘制当前类型按钮,点击选中类型脚本,双击打开类型脚本
using (new UnityEditor.EditorGUI.DisabledGroupScope(true))
using (new UnityEditor.EditorGUI.DisabledScope(!contentEnabled))
{
//绘制一个Disabled风格的Field,再在上面绘制一个button
//直接绘制button在里面没办法点击
Expand All @@ -315,13 +336,16 @@ protected void DrawReference(SerializedProperty property, GUIContent label, Rect
ClickTypeLable(targetType);
}

if (!property.isExpanded)
using (new EditorGUI.DisabledScope(!contentEnabled))
{
EditorGUI.PropertyField(propertyPosition, property, label, true);
}
else
{
EditorGUI.PropertyField(position, property, label, true);
if (!property.isExpanded)
{
EditorGUI.PropertyField(propertyPosition, property, label, true);
}
else
{
EditorGUI.PropertyField(position, property, label, true);
}
}
}
else
Expand Down

0 comments on commit c9dcfe5

Please sign in to comment.