Version 2.1.0.0

Odin has a dedicated attribute overview with examples

OnInspectorGUIAttribute class

Namespace: Sirenix.OdinInspector
Assembly: Sirenix.OdinInspector.Attributes
[DontApplyToListElements]
[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 = false, Inherited = true)]
public sealed class OnInspectorGUIAttribute : ShowInInspectorAttribute, _Attribute

OnInspectorGUI is used on any property, and will call the specified function whenever the inspector code is running.

Use this to create custom inspector GUI for an object.

Inheritance
Example

public MyComponent : MonoBehaviour
{
	[OnInspectorGUI]
	private void MyInspectorGUI()
	{
		GUILayout.Label("Label drawn from callback");
	}
}
Example

The following example shows how a callback can be set before another property.

public MyComponent : MonoBehaviour
{
	[OnInspectorGUI("MyInspectorGUI", false)]
	public int MyField;

	private void MyInspectorGUI()
	{
		GUILayout.Label("Label before My Field property");
	}
}
Example

The following example shows how callbacks can be added both before and after a property.

public MyComponent : MonoBehaviour
{
	[OnInspectorGUI("GUIBefore", "GUIAfter")]
	public int MyField;

	private void GUIBefore()
	{
		GUILayout.Label("Label before My Field property");
	}

	private void GUIAfter()
	{
		GUILayout.Label("Label after My Field property");
	}
}

Constructors

OnInspectorGUIAttribute()
Calls the function when the inspector is being drawn.
public OnInspectorGUIAttribute()
OnInspectorGUIAttribute(String, Boolean)
Adds callback to the specified method when the property is being drawn.
public OnInspectorGUIAttribute(string methodName, bool append = true)
Parameters
System.String methodName

The name of the member function.

System.Boolean append

If true the method will be called after the property has been drawn. Otherwise the method will be called before.

OnInspectorGUIAttribute(String, String)
Adds callback to the specified method when the property is being drawn.
public OnInspectorGUIAttribute(string prependMethodName, string appendMethodName)
Parameters
System.String prependMethodName

The name of the member function to invoke before the property is drawn.

System.String appendMethodName

The name of the member function to invoke after the property is drawn.

Fields

AppendMethodName
The name of the method to be called after the property is drawn, if any.
public string AppendMethodName
PrependMethodName
The name of the method to be called before the property is drawn, if any.
public string PrependMethodName

This website is brand new and built with the Odin 2.1 beta in mind. This means you might discover some features such as attribute expressions that are only available in the beta.

You can download the 2.1 beta from here and read the patch-notes here.