Class SortingLayerFieldDrawer
Custom PropertyDrawer for the SortingLayerFieldAttribute.
Inherited Members
Namespace: Scylla.Core.Editor.Attributes
Assembly: ScyllaCore.Editor.dll
Syntax
[CustomPropertyDrawer(typeof(SortingLayerFieldAttribute))]
public sealed class SortingLayerFieldDrawer : PropertyDrawer
Remarks
Replaces the default integer field with a popup dropdown that lists all defined Unity
sorting layers by name. The stored integer value is the sorting layer's unique ID (not
its index), which is directly compatible with SpriteRenderer.sortingLayerID and
similar Unity APIs.
The decorated field must be of type int; applying the attribute to any other
type renders an error help box.
Sorting layer names and IDs are cached statically and only rebuilt when the set of sorting layers changes (detected by comparing layer count and IDs), minimizing allocations during Inspector repaints.
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
OnGUI(Rect, SerializedProperty, GUIContent)
Draws a sorting layer selection popup that maps the stored integer ID to a human-readable layer name.
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 draw. Must be of type UnityEditor.SerializedPropertyType.Integer; otherwise an error help box is rendered and no value is written. |
| GUIContent | label | The label to display to the left of the dropdown. |
Overrides
Remarks
When the property's current integer value does not match any known sorting layer ID, the dropdown defaults to the first layer in the list. Changes are only written back when UnityEditor.EditorGUI.EndChangeCheck() detects a user interaction.