Odin-按钮
发布于 2021-12-26
Button
用于为一个方法在Inspector中绘制一个触发该方法的功能按钮
在Inspector上绘制各个按钮,如果有参数,默认折叠的方式展示

[Button]
private void Default()
{
}
[Button]
private void Default(float a, float b, GameObject c)
{
}
[Button]
private void Default(float t, float b, float[] c)
{
}
以为为这个button指定一个名称,而且也可以通过特殊字符$引用一个字段作为名称

public string ButtonName = "Dynamic button name";
public bool Toggle;
[Button("$ButtonName")]
private void DefaultSizedButton()
{
this.Toggle = !this.Toggle;
}
可以通过特殊字符@ 写入方法体调用

[Button("@\"Expression label: \" + DateTime.Now.ToString(\"HH:mm:ss\")")]
public void ExpressionLabel()
{
this.Toggle = !this.Toggle;
}
ButtonSizes指定不同尺寸大小的按钮

[Button(ButtonSizes.Small), GUIColor(0.3f, 0.8f, 1)]
private void SmallButton()
{
this.Toggle = !this.Toggle;
}
[Button(ButtonSizes.Medium), GUIColor(0.4f, 0.4f, 1)]
private void MediumSizedButton()
{
this.Toggle = !this.Toggle;
}
[Button(ButtonSizes.Large), GUIColor(0.5f, 0.8f, 0.5f)]
private void LargeButton()
{
this.Toggle = !this.Toggle;
}
[Button(ButtonSizes.Gigantic),GUIColor(0.6f, 0.8f, 0)]
private void GiganticButton()
{
this.Toggle = !this.Toggle;
}
也是自定义尺寸

[Button(90)]
private void CustomSizedButton()
{
this.Toggle = !this.Toggle;
}
ButtonStyle指定展示样式

[Button(ButtonSizes.Medium, ButtonStyle.FoldoutButton)]
private int FoldoutButton(int a = 2, int b = 2)
{
return a + b;
}
[Button(ButtonSizes.Medium, ButtonStyle.FoldoutButton)]
private void FoldoutButton(int a, int b, ref int result)
{
result = a + b;
}
[Button(ButtonSizes.Large, ButtonStyle.Box)]
private void Box(float a, float b, out float c)
{
c = a + b;
}
[Button(ButtonSizes.Large, ButtonStyle.Box)]
private void Box(int a, float b, out float c)
{
c = a + b;
}
[Button(ButtonSizes.Large, ButtonStyle.CompactBox)]
public void CompactBox(int a, float b, out float c)
{
c = a + b;
}
Expanded如果有参数的控制是否强制展开折页(去除折页方式)

[Button(ButtonStyle.CompactBox, Expanded = true)]
private void CompactExpanded(float a, float b, GameObject c)
{
}
[Button(ButtonSizes.Medium, ButtonStyle.Box, Expanded = true)]
private void FullExpanded(float a, float b)
{
}
ButtonGroup
用于可用于任何实例函数,并将按钮添加到组织为水平组的检查器中。使用此按钮可以将多个按钮组织在一个整齐的水平组中。

[ButtonGroup]
private void A()
{
}
[ButtonGroup]
private void B()
{
}
[ButtonGroup]
private void C()
{
}
[ButtonGroup]
private void D()
{
}
[Button(ButtonSizes.Large)]
[ButtonGroup("My Button Group")]
private void E()
{
}
[GUIColor(0, 1, 0)]
[ButtonGroup("My Button Group")]
private void F()
{
}
InlineButton
用于将一个按钮添加到属性的末尾

// Inline Buttons:
[InlineButton("A")]
public int InlineButton;
[InlineButton("A")]
[InlineButton("B", "Custom Button Name")]
public int ChainedButtons;
private void A()
{
Debug.Log("A");
}
private void B()
{
Debug.Log("B");
}