Class RequiredDrawer
Custom PropertyDrawer for the RequiredAttribute.
Inherited Members
Namespace: Scylla.Core.Editor.Attributes
Assembly: ScyllaCore.Editor.dll
Syntax
[CustomPropertyDrawer(typeof(RequiredAttribute))]
public sealed class RequiredDrawer : PropertyDrawer
Remarks
When the decorated field is null or empty, renders a yellow warning help box above the
normal property field to alert designers that a required value has not been assigned.
The warning message is taken from ErrorMessage when
provided; otherwise a default message of the form "{DisplayName} is required"
is generated automatically.
"Empty" is interpreted according to the property type:
-
UnityEditor.SerializedPropertyType.ObjectReference and
UnityEditor.SerializedPropertyType.ExposedReference -
nullor destroyed Unity object. - UnityEditor.SerializedPropertyType.String - null or empty string.
-
UnityEditor.SerializedPropertyType.ManagedReference -
nullmanaged reference. - Arrays - zero-element arrays.
All other property types are considered non-empty and never show the warning.
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 total height required to draw this property, including the warning box when the field value is empty.
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 standard property field height, plus |
Overrides
OnGUI(Rect, SerializedProperty, GUIContent)
Draws an optional warning box followed by the property field.
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 combined GUI output. When the field is empty,
the warning box occupies the top |
| SerializedProperty | property | The UnityEditor.SerializedProperty to make the custom GUI for. |
| GUIContent | label | The label of this property. |