OnInspectorGUIAttribute

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.

namespace Sirenix.OdinInspector
{
[AttributeUsageAttribute((AttributeTargets)448, AllowMultiple = False, Inherited = True)]
[DontApplyToListElementsAttribute]
public sealed class OnInspectorGUIAttribute : ShowInInspectorAttribute
}

Requirements

Namespace: Sirenix.OdinInspector
Assembly: Sirenix.OdinInspector
Version: 1.0.4.1

Constructors

Definition Description
OnInspectorGUIAttribute() Calls the function when the inspector is being drawn.
OnInspectorGUIAttribute(string, bool) Adds callback to the specified method when the property is being drawn.
OnInspectorGUIAttribute(string, string) Adds callback to the specified method when the property is being drawn.

Properties

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

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