Inspectable Attributes

This feature is only available in Inspector Gadgets Pro.

Unlike the Decorator Attributes which inherit from PropertyAttribute and alter the way Unity shows a serialized field in the Inspector, the following attributes inherit from InspectableAttribute and add extra elements at the bottom of the Inspector (see the links on the right for the full list).

These attributes have several properties which can be set in the constructor:

  • Label and Tooltip - the text and tooltip to show in the Inspector.
  • DisplayIndex - determines the order in which the inspectable is to be drawn amongst the regular serialized fields, starting with 0 at the top of the Inspector.
  • When - determines when the inspectable is drawn: always (default), in play mode only, or in edit mode only.

Inspectable

The [Inspectable] attribute adds the attributed field or property to the Inspector as if it were serialized. Works on static members as well.

Label

The [Label] attribute adds a read-only label to display the value of any field, property (with a getter), or method (with no parameters), even static and private ones.

  • If the value will change constantly, you can set the ConstantlyRepaint property to true.
  • If the value is likely to be long, you can set the Multiline property to true.
[InspectorGadgets.Attributes.Label]
string PropertyLabel { get; set; }	 

Button

The [Button] attribute adds a button in the Inspector which the user can click to invoke the attributed method.

  • The will automatically be given the method’s name (with spaces between words) unless you specify a different Label in its constructor.
  • If it is an instance method and multiple objects are selected, the method will be called once for each selected object.
  • If the method has a non-void return type, the returned value will be logged.
  • If you assign SetDirty = true in the attribute’s constructor, it will automatically call UnityEditor.EditorUtility.SetDirty on the target after invoking the method to make sure changes are saved properly.
[InspectorGadgets.Attributes.Button]
void InspectorButton() { }