Button

  06. Attributes No Comments

When added before a method causes the method to be shown inside the inspector view as a button.

By default the button is shown expanded to the full width of the inspector view with no prefix label, and with the button text auto-generated from the method name.

You can customize the button text by using the constructor with a single parameter.

You can customize the prefix label and the button text by using the constructor with two parameters.

You can also specify the name of a GUIStyle to use for drawing the button by using the constructor with three parameters.

Attribute Target

Method

Example

using Sisus.Attributes;
using UnityEngine;

public class Calculator : MonoBehaviour
{
	public int input1;
	public int input2;

	[PSpace(8f)]
	[ShowInInspector]
	public float Result
	{
		get;
		private set;
	}

	[PSpace(8f)]
	[Button]
	public void Sum()
	{
		Result = input1 + input2;
	}

	[Button]
	public void Multiply()
	{
		Result = input1 * input2;
	}

	[Button]
	public void Divide()
	{
		Result = (float)input1 / input2;
	}
}

Example Result