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

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

简介

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

  • DisableContextMenu
  • CustomContextMenu
  • OnValueChanged
  • DrawWithUnity

声明

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

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

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

API详解



DisableContextMenuAttribute

简介

使用此属性可以屏蔽掉右键点击后弹出菜单。

PS:比如说对于数组列表,Odin将使用自定义的方式进行绘制,对于标题栏和每一条元素都可以响应右键的点击并弹出菜单,如果想禁用的话,可以选择使用此菜单

API详解

  • Fields

    类 型 名 称 说 明
    bool DisableForMember 是否禁用使用此属性标签的字段、方法、属性的右键菜单
    bool DisableForCollectionElements 是否禁用元素的右键菜单
  • Properties

  • Constructors

    参 数 描 述
    bool disableForMember = true, bool disableCollectionElements = false 各个参数的含义参见Fields中说明

示例

public class MyComponent : MonoBehaviour
{
    [DisableContextMenu]
    public Vector3 MyVector;
}


CustomContextMenuAttribute

简介

使用此属性标签后可以为字段、属性和方法,添加自定义的右键菜单

API详解

  • Fields

    类 型 名 称 说 明
    string MenuItem 菜单名称,可以使用/进行设置多级菜单
    string MethodName 右键菜单被点击后,指定的执行方法的名称
  • Properties

  • Constructors

    参 数 描 述
    string menuItem, string methodName 各个参数的含义参见Fields中说明

示例

public class MyComponent : MonoBehaviour
{
    [CustomContextMenu("My custom option", "MyAction")]
    public Vector3 MyVector;

    private void MyAction()
    {
        MyVector = Random.onUnitSphere;
    }
}


OnValueChangedAttribute

简介

使用此属性标签后,当字段或者属性值的发生变化时会调用通过标签指的函数

PS:此属性标签仅适用于字段或者属性,同时此属性标签仅可使用在编译器中,同时通过脚本修改其值不会触发此标签

API详解

  • Fields

    类 型 名 称 说 明
    string MethodName
    bool IncludeChildren
  • Properties

  • Constructors

    参 数 描 述
    string methodName, bool includeChildren = false 各个参数的含义参见Fields中说明

示例

public class MyComponent : MonoBehaviour
{
    [OnValueChanged("MyCallback")]
    public int MyInt;

    private void MyCallback()
    {
        ......
    }
}


DrawWithUnityAttribute

简介

使用Odin后,odin会接管属性和字段的绘制方式,不再采用Unity默认的绘制方法,如果某些情况下需要使用Unity自身的绘制,则可以使用添加些属性标签

PS:此属性标签仅适用于字段或者属性

API详解

  • Fields
  • Properties
  • Constructors

示例

public class DrawWithUnityExamples : MonoBehaviour
{
    [DrawWithUnity]
    public GameObject ObjectDrawnWithUnity;
}


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