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 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).
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.
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;
}
}
public PropertyGroupAttribute(string groupId)
System.String | groupId | The group identifier. |
public PropertyGroupAttribute(string groupId, float order)
System.String | groupId | The group identifier. |
System.Single | order | The group order. |
public bool AnimateVisibility
public string GroupID
public string GroupName
public bool HideWhenChildrenAreInvisible
public float Order
public string VisibleIf
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)
PropertyGroupAttribute | other | The attribute to combine with. |
PropertyGroupAttribute | The instance that the method was invoked on. |
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. |
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)
PropertyGroupAttribute | other | The attribute to combine with. This parameter is guaranteed to be of the correct attribute type. |