Namespace: | Sirenix.OdinInspector.Editor |
Assembly: | Sirenix.OdinInspector.Editor |
public abstract class OdinGroupDrawer<TGroupAttribute> : OdinDrawer where TGroupAttribute : PropertyGroupAttribute
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 Sirenix.OdinInspector.Editor.OdinDrawerAttribute
in order for it to be located by the
Checkout the manual for more information.
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class MyBoxGroupAttribute : PropertyGroupAttribute
{
public MyBoxGroupAttribute(string group, float 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.
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;
}
protected OdinGroupDrawer()
public TGroupAttribute Attribute { get; }
protected virtual bool CanDrawGroup(InspectorProperty property)
InspectorProperty | property |
System.Boolean |
public override sealed bool CanDrawProperty(InspectorProperty property)
InspectorProperty | property |
System.Boolean |
protected override void DrawPropertyLayout(GUIContent label)
UnityEngine.GUIContent | label | The label. This can be null, so make sure your drawer supports that. |