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)
上一篇 2022年7月21日 上午7:00
下一篇 2022年7月21日 上午7:00


相关推荐

  • Win10 IIS Web服务器安装与配置

    Win10 IIS Web服务器安装与配置这几天课程实训,使用IIS配置服务器,课本上内容太久,老师也没有讲过,自己摸索了一下,所以记录一下安装IIS打开程序和功能,选择左边启用或关闭Windows功能,建议根据下图勾选,确定后等待安装完成打开IIS直接使用Cortana搜索管理工具,打开选择InternetinformationServices(IIS)管理器点击左边栏,在计算机名下,网站文件夹下已经默认存

    2022年5月30日
    45
  • 安装mysql-python报错_mac好用的ssh

    安装mysql-python报错_mac好用的sshmac系统安装mysqlclient时,会报错OSError:mysql_confignotfound解决办法在项目路径下输入以下内容PATH="$PATH":/usr

    2022年8月7日
    14
  • encodeURIComponent编码后java后台的解码

    encodeURIComponent编码后java后台的解码

    2021年9月16日
    641
  • malloc函数的使用

    malloc函数的使用include stdio h 先讲最基本的语法 最后是完整的例子 2021 5 309 30malloc 是 memory 内存 allocate 分配 的缩写 请求分配内存 include malloc h malloc 在 malloc h 文件中放着 intmain void inti 5 14 行 分配了 4 个字节静态分配 malloc h stdio h

    2026年3月16日
    1
  • 智能体Pro

    智能体Pro

    2026年3月15日
    2
  • 深度学习 — 卷积神经网络CNN(LeNet-5网络详解)

    深度学习 — 卷积神经网络CNN(LeNet-5网络详解)卷积神经网络 Convolutiona CNN 是一种前馈型的神经网络 其在大型图像处理方面有出色的表现 目前已经被大范围使用到图像分类 定位等领域中 相比于其他神经网络结构 卷积神经网络需要的参数相对较少 使的其能够广泛应用 本节打算先介绍背景和简单的基本概念术语 然后详细介绍 LeNet 5 网络 其工作流程大家需要先搞清楚 学习原理其实是基于 BP 学习原理的 只

    2026年3月16日
    3

发表回复

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

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