Class FoldoutDrawer
Custom PropertyDrawer for the FoldoutAttribute.
Inherited Members
Namespace: Scylla.Core.Editor.Attributes
Assembly: ScyllaCore.Editor.dll
Syntax
[CustomPropertyDrawer(typeof(FoldoutAttribute))]
public sealed class FoldoutDrawer : PropertyDrawer
Remarks
Creates collapsible foldout sections in the Inspector. Each field decorated with
FoldoutAttribute using the same GroupName on the same serialized
object shares a single expand/collapse toggle, so all fields in a group fold together.
The drawer draws a bold foldout header (using UnityEditor.EditorStyles.foldoutHeader)
followed by the property field indented by INDENT_WIDTH pixels when expanded.
Hierarchical group names (e.g., "Combat/Offense") display only the last
path segment as the visible label.
Foldout state is stored in a static dictionary keyed by object instance ID and group
name, so state persists across Inspector repaints but resets on domain reload.
The cache is bounded by MAX_FOLDOUT_CACHE_SIZE to prevent unbounded growth
from destroyed objects.
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 the foldout header and, when expanded, the property field below it.
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 of the foldout header ( |
Overrides
OnGUI(Rect, SerializedProperty, GUIContent)
Draws a collapsible foldout header followed by the property field when the group is expanded.
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 entire property GUI, encompassing both the foldout header and, when expanded, the indented property field drawn below it. |
| SerializedProperty | property | The UnityEditor.SerializedProperty to make the custom GUI for. |
| GUIContent | label | The label of this property, displayed alongside the property field when expanded. |
Overrides
Remarks
The foldout header always occupies FOLDOUT_HEIGHT pixels at the top of
position. When the group is expanded, the property is drawn directly
below with a INDENT_WIDTH-pixel left indent. The foldout state is persisted in the
shared _foldoutStates dictionary for the lifetime of the Editor session, and is
cleared automatically when the cache exceeds MAX_FOLDOUT_CACHE_SIZE entries.