Class EnableIfDrawer
Custom PropertyDrawer for the EnableIfAttribute.
Inherited Members
Namespace: Scylla.Core.Editor.Attributes
Assembly: ScyllaCore.Editor.dll
Syntax
[CustomPropertyDrawer(typeof(EnableIfAttribute))]
public sealed class EnableIfDrawer : ConditionalDrawerBase
Remarks
Makes the decorated property field editable only when the condition defined on the
attribute evaluates to true. When the condition is false, the field is
always visible but grayed out and non-interactive.
This is the inverse of DisableIfDrawer. Condition evaluation is delegated to EvaluateCondition(SerializedProperty), which supports boolean truthiness checks as well as explicit value comparisons via CompareOperator.
Methods
CreatePropertyGUI(SerializedProperty)
Creates custom GUI with UI Toolkit for the property.
Declaration
public override VisualElement CreatePropertyGUI(SerializedProperty property)
Parameters
| Type | Name | Description |
|---|---|---|
| SerializedProperty | property | The SerializedProperty to make the custom GUI for. |
Returns
| Type | Description |
|---|---|
| VisualElement | The element containing the custom GUI. |
Overrides
GetPropertyHeight(SerializedProperty, GUIContent)
Returns the full height of the property field regardless of the enabled state, since a disabled field still occupies the same vertical space as an enabled one.
Declaration
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
Parameters
| Type | Name | Description |
|---|---|---|
| SerializedProperty | property | The UnityEditor.SerializedProperty to calculate the height for. |
| GUIContent | label | The label of this property. |
Returns
| Type | Description |
|---|---|
| float | The height returned by GetPropertyHeight(SerializedProperty, GUIContent, bool) with children included. |
Overrides
OnGUI(Rect, SerializedProperty, GUIContent)
Draws the property field normally when the condition is true, or inside a
UnityEditor.EditorGUI.DisabledGroupScope (grayed out) when the condition is false.
Declaration
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
Parameters
| Type | Name | Description |
|---|---|---|
| Rect | position | Rectangle on the screen to use for the property GUI. |
| SerializedProperty | property | The UnityEditor.SerializedProperty to make the custom GUI for. |
| GUIContent | label | The label of this property. |