Inspector Button
Adding instance button to the inspector
[InspectorButton("Do Stuffs")]
private void InspectorButton()
{
// do wonderful stuffs
}
[InspectorButton(Expanded = true)]
private void InspectorButtonWithValue(int value)
{
// do wonderful stuffs with value
}
The usage can be changed by adding parameters.
// enable or disable (default: DisableInPlayMode)
[InspectorButton(Mode = InspectorButtonMode.DisabledInPlayMode)]
[InspectorButton(Mode = InspectorButtonMode.EnabledInPlayMode)]
[InspectorButton(Mode = InspectorButtonMode.AlwaysEnabled)]
// set button name (default: function name)
[InspectorButton(name: "My faviourite name")]
// expanded (default: false), work on function with parameter
[InspectorButton(Expanded = true)]
If you are modifying serialized values, please add undo data to Unity Editor, and set your object dirty for serializing.
[InspectorButton]
private void ModifyPosition()
{
#if UNITY_EDITOR
UnityEditor.Undo.RecordObject(this, "Modify Position");
UnityEditor.Undo.RecordObject(transform, "Modify Position");
#endif
transform.position = Vector3.one;
#if UNITY_EDITOR
UnityEditor.EditorUtility.SetDirty(this);
#endif
}
Last updated