Namespace: | Sirenix.OdinInspector |
Assembly: | Sirenix.OdinInspector.Attributes |
[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 = false)]
[Conditional("UNITY_EDITOR")]
public class ButtonAttribute : ShowInInspectorAttribute, _Attribute
Buttons are used on functions, and allows for clickable buttons in the inspector.
The following example shows a component that has an initialize method, that can be called from the inspector.
public class MyComponent : MonoBehaviour
{
[Button]
private void Init()
{
// ...
}
}
The following example show how a Button could be used to test a function.
public class MyBot : MonoBehaviour
{
[Button]
private void Jump()
{
// ...
}
}
The following example show how a Button can named differently than the function it's been attached to.
public class MyComponent : MonoBehaviour
{
[Button("Function")]
private void MyFunction()
{
// ...
}
}
public ButtonAttribute()
public ButtonAttribute(ButtonSizes size)
ButtonSizes | size | The size of the button. |
public ButtonAttribute(ButtonSizes size, ButtonStyle parameterBtnStyle)
ButtonSizes | size | The size of the button. |
ButtonStyle | parameterBtnStyle | Button style for methods with parameters. |
public ButtonAttribute(ButtonStyle parameterBtnStyle)
ButtonStyle | parameterBtnStyle | Button style for methods with parameters. |
public ButtonAttribute(SdfIconType icon)
SdfIconType | icon | The icon to be displayed inside the button. |
public ButtonAttribute(SdfIconType icon, IconAlignment iconAlignment)
SdfIconType | icon | The icon to be displayed inside the button. |
IconAlignment | iconAlignment | The alignment of the icon that is displayed inside the button. |
public ButtonAttribute(SdfIconType icon, string name)
SdfIconType | icon | The icon to be displayed inside the button. |
System.String | name | Custom name for the button. |
public ButtonAttribute(int buttonSize)
System.Int32 | buttonSize | The size of the button. |
public ButtonAttribute(int buttonSize, ButtonStyle parameterBtnStyle)
System.Int32 | buttonSize | The size of the button. |
ButtonStyle | parameterBtnStyle | Button style for methods with parameters. |
public ButtonAttribute(string name)
System.String | name | Custom name for the button. |
public ButtonAttribute(string name, ButtonSizes buttonSize)
System.String | name | Custom name for the button. |
ButtonSizes | buttonSize | Size of the button. |
public ButtonAttribute(string name, ButtonSizes buttonSize, ButtonStyle parameterBtnStyle)
System.String | name | Custom name for the button. |
ButtonSizes | buttonSize | Size of the button. |
ButtonStyle | parameterBtnStyle | Button style for methods with parameters. |
public ButtonAttribute(string name, ButtonStyle parameterBtnStyle)
System.String | name | Custom name for the button. |
ButtonStyle | parameterBtnStyle | Button style for methods with parameters. |
public ButtonAttribute(string name, int buttonSize)
System.String | name | Custom name for the button. |
System.Int32 | buttonSize | Size of the button in pixels. |
public ButtonAttribute(string name, int buttonSize, ButtonStyle parameterBtnStyle)
System.String | name | Custom name for the button. |
System.Int32 | buttonSize | Size of the button in pixels. |
ButtonStyle | parameterBtnStyle | Button style for methods with parameters. |
public bool DirtyOnClick
Whether to display the button method's parameters (if any) as values in the inspector. True by default.
If this is set to false, the button method will instead be invoked through an ActionResolver or ValueResolver (based on whether it returns a value), giving access to contextual named parameter values like "InspectorProperty property" that can be passed to the button method.
public bool DisplayParameters
public bool Expanded
public SdfIconType Icon
public string Name
public ButtonStyle Style
public float ButtonAlignment { get; set; }
public int ButtonHeight { get; set; }
public bool DrawResult { get; set; }
public bool DrawResultIsSet { get; }
public bool HasDefinedButtonAlignment { get; }
public bool HasDefinedButtonHeight { get; }
public bool HasDefinedButtonIconAlignment { get; }
public bool HasDefinedIcon { get; }
public bool HasDefinedStretch { get; }
public IconAlignment IconAlignment { get; set; }
public bool Stretch { get; set; }