OdinGroupDrawer<TGroupAttribute>

Base class for all group drawers. Use this class to create your own custom group drawers. OdinGroupDrawer are used to group multiple properties together using an attribute.

Note that all box group attributes needs to inherit from the PropertyGroupAttribute

Remember to provide your custom drawer with an OdinDrawerAttributein order for it to be located by the DrawerLocator.

namespace Sirenix.OdinInspector.Editor
{
public abstract class OdinGroupDrawer<TGroupAttribute> : OdinDrawer
where TGroupAttribute : Sirenix.OdinInspector.PropertyGroupAttribute
}

Requirements

Namespace: Sirenix.OdinInspector.Editor
Assembly: Sirenix.OdinInspector
Version: 1.0.6.1

See Also

Properties

Return Type Definition Description
GUICallType GUICallType Drawing properties using GUICallType.GUILayout and overriding DrawPropertyGroupLayout is the default behavior. But you can also draw the property group the "good" old Unity way, by overriding and implementing GetRectHeight and DrawPropertyGroupRect. Just make sure to override GUICallType as well and return GUICallType.Rect

Methods

Return Type Definition Description
void DrawPropertyGroupLayout(InspectorProperty, TGroupAttribute, GUIContent) Draws the property group with GUILayout support. This method is called from DrawPropertyImplementation if the GUICallType is set to GUILayout, which is the default.
void DrawPropertyGroupRect(Rect, InspectorProperty, TGroupAttribute, GUIContent) Draws the property group in the Rect provided. This method does not support the GUILayout, and is only called by DrawPropertyImplementation if the GUICallType is set to Rect, which is not the default. If the GUICallType is set to Rect, both GetRectHeight and DrawPropertyGroupRect needs to be implemented. If the GUICallType is set to GUILayout, implementing DrawPropertyGroupLayout will suffice.
void DrawPropertyImplementation(InspectorProperty, GUIContent) Draws the actual property. This method is called by this.DrawProperty(...)
float GetRectHeight(InspectorProperty, TGroupAttribute, GUIContent) Return the GUI height of the property. This method is called by DrawPropertyImplementation if the GUICallType is set to Rect, which is not the default. If the GUICallType is set to Rect, both GetRectHeight and DrawPropertyGroupRect needs to be implemented. If the GUICallType is set to GUILayout, implementing DrawPropertyGroupLayout will suffice.

Example

[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class MyBoxGroupAttribute : PropertyGroupAttribute
{
    public MyBoxGroupAttribute(string group, int order = 0) : base(group, order)
    {
    }
}

// Remember to wrap your custom group drawer within a #if UNITY_EDITOR condition, or locate the file inside an Editor folder.
[OdinDrawer]
public class BoxGroupAttributeDrawer : OdinGroupDrawer<MyBoxGroupAttribute>
{
    protected override void DrawPropertyGroupLayout(InspectorProperty property, MyBoxGroupAttribute attribute, GUIContent label)
    {
        GUILayout.BeginVertical("box");
        for (int i = 0; i < property.Children.Count; i++)
        {
            InspectorUtilities.DrawProperty(property.Children[i]);
        }
        GUILayout.EndVertical();
    }
}

// Usage:
public class MyComponent : MonoBehaviour
{
    [MyBoxGroup("MyGroup")]
    public int A;

    [MyBoxGroup("MyGroup")]
    public int B;

    [MyBoxGroup("MyGroup")]
    public int C;
}