PropertyGroupAttribute

Attribute to derive from if you wish to create a new property group type, such as box groups or tab groups.

unknown:<note>(29555,8)

namespace Sirenix.OdinInspector
{
[AttributeUsageAttribute((AttributeTargets)448, AllowMultiple = True, Inherited = True)]
public abstract class PropertyGroupAttribute : ShowInInspectorAttribute
}

Requirements

Namespace: Sirenix.OdinInspector
Assembly: Sirenix.OdinInspector
Version: 1.0.5.0

See Also

Constructors

Definition Description
PropertyGroupAttribute(string, int) Initializes a new instance of the PropertyGroupAttribute class.

Properties

Return Type Definition Description
string GroupID The ID used to grouping properties together.
string GroupName The name of the group. This is the last part of the group ID if there is a path, otherwise it is just the group ID.
int Order The order of the group.

Methods

Return Type Definition Description
PropertyGroupAttribute Combine(PropertyGroupAttribute)

Combines this attribute with another attribute of the same type. This method invokes the virtual CombineValuesWith(PropertyGroupAttribute) method to invoke custom combine logic.

All group attributes are combined to one attribute used by a single OdinGroupDrawer.

Example:

protected override void CombineValuesWith(PropertyGroupAttribute other) { this.Title = this.Title ?? (other as MyGroupAttribute).Title; }

void CombineValuesWith(PropertyGroupAttribute)

Override this method to add custom combine logic to your group attribute. This method determines how your group's parameters combine when spread across multiple attribute declarations in the same class.

Rememember, in .NET, member order is not guaranteed, so you never know which order your attributes will be combined in.

Example

This example shows how BoxGroupAttribute could be implemented.

[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class BoxGroupAttribute : PropertyGroupAttribute
{
    public string Label { get; private set; }
    public bool ShowLabel { get; private set; }
    public bool CenterLabel { get; private set; }

    public BoxGroupAttribute(string group, bool showLabel = true, bool centerLabel = false, int order = 0)
        : base(group, order)
    {
        this.Label = group;
        this.ShowLabel = showLabel;
        this.CenterLabel = centerLabel;
    }

    protected override void CombineValuesWith(PropertyGroupAttribute other)
    {
        // The given attribute parameter is *guaranteed* to be of type BoxGroupAttribute.
        var attr = other as BoxGroupAttribute;

        // If this attribute has no label, we the other group's label, thus preserving the label across combines.
        if (this.Label == null)
        {
            this.Label = attr.Label;
        }

        // Combine ShowLabel and CenterLabel parameters.
        this.ShowLabel |= attr.ShowLabel;
        this.CenterLabel |= attr.CenterLabel;
    }
}