Unity插件之Odin 2.inspector使用-Buttons

Unity插件之Odin 2.inspector使用-Buttons

简介

Odin定义了很多的属性标签,通过这些属性标签很大程度上增强了编辑器功能,本文将详细介绍如下属性标签:

  • Button
  • InlineButton
  • ButtonGroup
  • ResponsiveButtonGroup

声明

本文中的内容属于个人总结整理而来,个人水平有限,对于部分细节难免有理解错误及遗漏之处,如果您在阅读过程中有所发现,希望您能指正,同时文章中的部分内容也参考了其它大神的文章,如果文章中的内容侵犯了您的权益,表示非常歉意,请您指出,我将尽快修改。

如果您进行转载,请标明出处。

Unity插件之Odin 2.inspector使用-Buttons(http://www.liyubin.com/articles/2019/03/26/1553609580931.html)

API详解



ButtonAttribute

简介

此属性标签继承自ShowInInspectorAttribute,使用此属性标签后,可以为方法绘制一个可以执行的按钮,按钮被点击后会调用对应的方法.对于带有参数的方法使用此属性标签后,将会绘制一个参数列表,通过修改列表中的参数做为方法被调用时传递的参数值

PS:此属性标签仅适用于方法

API详解

  • Fields

    类 型 名 称 说 明
    int ButtonHeight 按钮高度
    string Name 按钮名称,此字段设置后会重写按钮中文本显示内容
    ButtonStyle Style 按钮样式(CompactBox,FoldoutButton,Box)
    bool Expanded 是否展示按钮参数设置,如果按钮包含有参数,可以将其设置为true,将会展开参数列表
  • Properties

  • Constructors

    参 数 描 述
    ---
    ButtonSizes size 各个参数的含义参见Fields中说明
    int buttonSize 各个参数的含义参见Fields中说明
    string name 各个参数的含义参见Fields中说明
    string name, ButtonSizes buttonSize 各个参数的含义参见Fields中说明
    string name, int buttonSize 各个参数的含义参见Fields中说明
    ButtonStyle parameterBtnStyle 各个参数的含义参见Fields中说明
    int buttonSize, ButtonStyle parameterBtnStyle 各个参数的含义参见Fields中说明
    ButtonSizes size, ButtonStyle parameterBtnStyle 各个参数的含义参见Fields中说明
    string name, ButtonStyle parameterBtnStyle 各个参数的含义参见Fields中说明
    string name, ButtonSizes buttonSize, ButtonStyle parameterBtnStyle 各个参数的含义参见Fields中说明
    string name, int buttonSize, ButtonStyle parameterBtnStyle 各个参数的含义参见Fields中说明

    PS:ButtonSizes枚举为按钮添加了几个不同尺寸,分别为:Small,Medium,Large,Gigantic

示例

Unity插件之Odin 2.inspector使用-Buttons_第1张图片
Odin-ButtonAttribute


InlineButtonAttribute

简介

此用此属性标签后,将会在字段或者属性的后面绘制一个可点击的按钮,点击此按钮后会调用设定的函数

PS:此属性标签仅可用于字段、属性

API详解

  • Fields

  • Properties

    Get/Set 类 型 名 称 描 述
    Get&Set string MemberMethod 按钮被点击后,调用的方法名称
    Get&Set string Label 按钮上显示文本内容
  • Constructors

    参 数 描 述
    string memberMethod, string label = null 各个参数的含义参见Fields中说明

示例

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


ButtonGroupAttribute

简介

此属性标签继承自PropertyGroupAttribute,使用此属性标签后,可以将一组方法以按钮的形式在面板中绘制

PS:此属性标签仅可用于方法

API详解

  • Fields

  • Properties

  • Constructors

    参 数 描 述
    string group = "_DefaultGroup", int order = 0

示例

Unity插件之Odin 2.inspector使用-Buttons_第2张图片
Odin-ButtonGroupAttribute


ResponsiveButtonGroupAttribute

TODO:



你可能感兴趣的:(Unity插件之Odin 2.inspector使用-Buttons)