Version 3.3.1.2

PropertyGroupAttribute class

Namespace: Sirenix.OdinInspector
Assembly: Sirenix.OdinInspector.Attributes
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Parameter | AttributeTargets.Delegate | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter | AttributeTargets.All, AllowMultiple = true, Inherited = true)]
[Conditional("UNITY_EDITOR")]
public abstract class PropertyGroupAttribute : Attribute, _Attribute

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

note

Note that this attribute has special behaviour for "combining" several attributes into one, as one group, may be declared across attributes in several members, completely out of order. See CombineValuesWith(PropertyGroupAttribute).

Inheritance
  • System.Object
  • System.Attribute
  • PropertyGroupAttribute
Remarks

All group attributes for a group with the same name (and of the same attribute type) are combined into a single representative group attribute using the CombineValuesWith(PropertyGroupAttribute) method, which is called by the Combine(PropertyGroupAttribute) method.

This behaviour is a little unusual, but it is important that you understand it when creating groups with many custom parameters that may have to be combined.

Example

This example shows how BoxGroupAttribute could be implemented.

[AttributeUsage(AttributeTargets.All, 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, float 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;
    }
}

Constructors

PropertyGroupAttribute(String)
Initializes a new instance of the PropertyGroupAttribute class.
public PropertyGroupAttribute(string groupId)
Parameters
System.String groupId

The group identifier.

PropertyGroupAttribute(String, Single)
Initializes a new instance of the PropertyGroupAttribute class.
public PropertyGroupAttribute(string groupId, float order)
Parameters
System.String groupId

The group identifier.

System.Single order

The group order.

Fields

AnimateVisibility
Whether to animate the visibility changes of this group or make the visual transition instantly. True by default.
public bool AnimateVisibility
GroupID
The ID used to grouping properties together.
public string GroupID
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.
public string GroupName
HideWhenChildrenAreInvisible
Whether to hide the group by default when all its children are not visible. True by default.
public bool HideWhenChildrenAreInvisible
Order
The order of the group.
public float Order
VisibleIf
If not null, this resolved string controls the group's visibility. Note that if HideWhenChildrenAreInvisible is true, there must be *both* a visible child *and* this condition must be true, before the group is shown.
public string VisibleIf

Methods

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; }

public PropertyGroupAttribute Combine(PropertyGroupAttribute other)
Parameters
PropertyGroupAttribute other

The attribute to combine with.

Returns
PropertyGroupAttribute

The instance that the method was invoked on.

Exceptions
System.ArgumentNullException

The argument 'other' was null.

System.ArgumentException

Attributes to combine are not of the same type. or PropertyGroupAttributes to combine must have the same group id.

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.

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

protected virtual void CombineValuesWith(PropertyGroupAttribute other)
Parameters
PropertyGroupAttribute other

The attribute to combine with. This parameter is guaranteed to be of the correct attribute type.