Odin Inspector 系列教程 — Custom Value Drawer Attribute

Odin Inspector 系列教程 — Custom Value Drawer AttributeCustomValueDrawerAttribute特性,允许用户自定义一个绘制方法,字段将以自定的绘制方式展示在Inspector中,非常灵活。含有Label和不含有Label的字段[CustomValueDrawer(“HaveLabelNameFunction”)]publicstringHaveLabelName;…

大家好,又见面了,我是你们的朋友全栈君。

Custom Value Drawer Attribute 特性,允许用户自定义一个绘制方法,字段将以自定的绘制方式展示在Inspector中,非常灵活。

含有Label和不含有Label的字段
7643202-313444f24f0b9c5d.png

    [CustomValueDrawer("HaveLabelNameFunction")]
    public string HaveLabelName;
    [CustomValueDrawer("NoLabelNameFunction")]
    public string NoLabelName;

    public string HaveLabelNameFunction(string tempName, GUIContent label)
    {
        return EditorGUILayout.TextField(tempName);
    }
    public string NoLabelNameFunction(string tempName, GUIContent label)
    {
        return EditorGUILayout.TextField(label,tempName);
    }
绘制Slider滑动条
7643202-0888c5e4ea14c3bb.gif

    public float Max = 100, Min = 0;

    [CustomValueDrawer("MyStaticCustomDrawerStatic")]
    public float CustomDrawerStatic;
    private static float MyStaticCustomDrawerStatic(float value, GUIContent label)
    {
        return EditorGUILayout.Slider(label, value, 0f, 10f);
    }

    [CustomValueDrawer("MyStaticCustomDrawerInstance")]
    public float CustomDrawerInstance;

    private float MyStaticCustomDrawerInstance(float value, GUIContent label)
    {
        return EditorGUILayout.Slider(label, value, this.Min, this.Max);
    }

    [CustomValueDrawer("MyStaticCustomDrawerArray")]
    public float[] CustomDrawerArray = new float[] { 3f, 5f, 6f };


    private float MyStaticCustomDrawerArray(float value, GUIContent label)
    {
        return EditorGUILayout.Slider(value, this.Min, this.Max);
    }

完整示例代码

using Sirenix.OdinInspector;
using UnityEditor;
using UnityEngine;

public class CustomValueDrawerExample : MonoBehaviour
{
    public float Max = 100, Min = 0;

    [CustomValueDrawer("MyStaticCustomDrawerStatic")]
    public float CustomDrawerStatic;
    private static float MyStaticCustomDrawerStatic(float value, GUIContent label)
    {
        return EditorGUILayout.Slider(label, value, 0f, 10f);
    }

    [CustomValueDrawer("MyStaticCustomDrawerInstance")]
    public float CustomDrawerInstance;

    private float MyStaticCustomDrawerInstance(float value, GUIContent label)
    {
        return EditorGUILayout.Slider(label, value, this.Min, this.Max);
    }

    [CustomValueDrawer("MyStaticCustomDrawerArray")]
    public float[] CustomDrawerArray = new float[] { 3f, 5f, 6f };


    private float MyStaticCustomDrawerArray(float value, GUIContent label)
    {
        return EditorGUILayout.Slider(value, this.Min, this.Max);
    }

    [CustomValueDrawer("HaveLabelNameFunction")]
    public string HaveLabelName;
    [CustomValueDrawer("NoLabelNameFunction")]
    public string NoLabelName;

    public string HaveLabelNameFunction(string tempName, GUIContent label)
    {
        return EditorGUILayout.TextField(tempName);
    }
    public string NoLabelNameFunction(string tempName, GUIContent label)
    {
        return EditorGUILayout.TextField(label,tempName);
    }
}

更多教程内容详见:革命性Unity 编辑器扩展工具 — Odin Inspector 系列教程

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/162813.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • phpstorm 2022 激活码_在线激活

    (phpstorm 2022 激活码)本文适用于JetBrains家族所有ide,包括IntelliJidea,phpstorm,webstorm,pycharm,datagrip等。IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html…

    2022年3月21日
    318
  • cb使用msagent

    cb使用msagent—-1、添加agent控件—-选择菜单component,importactivexcontrol——在importactivex下的列表框中选择microsoftagentcontrol2.0(version2.0),点击按钮install——在install对话框中点击按钮ok——在confirm对话框中点击按钮yes——在对话框中点击按钮ok。至此,agent控件

    2022年6月16日
    32
  • Content-Disposition的使用和注意事项

    Content-Disposition的使用和注意事项我们在开发web系统时有时会有以下需求:希望某类或者某已知MIME类型的文件(比如:*.gif;*.txt;*.htm)能够在访问时弹出“文件下载”对话框希望以原始文件名(上传时的文件名

    2022年7月1日
    20
  • stat 文件_readlink函数

    stat 文件_readlink函数statstat函数主要用于获取文件的inode信息。stat命令其实就是调用的stat函数。stat中时间的辨析atime(最近访问时间)mtime(最近更改时间):指最近修改文件内容的时间ctime(最近改动时间):指最近改动inode的时间1)chmod777stat_1.txtstat之后发现ctime变了。改变了文件的权限,文件权限保存在inode里面。2)vims

    2022年8月21日
    6
  • MySQL数据库优化技巧大全

    MySQL数据库优化技巧大全

    2022年2月18日
    38
  • 8421BCD码 5421BCD码 余三码 格雷码 余三循环码之间的关系,转换以及简易方法

    8421BCD码 5421BCD码 余三码 格雷码 余三循环码之间的关系,转换以及简易方法8421BCD码5421BCD码余三码格雷码余三循环码之间的关系,转换以及简易方法1.有权码和无权码的包括2.各种码值的介绍8421码的简介8421码又称为BCD码,是十进代码中最常用的一种。在这种编码方式中,每一位二值代码的“1”都代表一个固定数值。将每位“1”所代表的 二进制数加起来就可以得到它所代表的十进制数字。因为代码中从左至右看每一位“1”分别代表数字“8”“4…

    2025年8月1日
    4

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号