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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • [261]Connection reset by peer的常见原因及解决办法[通俗易懂]

    [261]Connection reset by peer的常见原因及解决办法[通俗易懂]1,如果一端的Socket被关闭(或主动关闭,或因为异常退出而引起的关闭),另一端仍发送数据,发送的第一个数据包引发该异常(Connectresetbypeer)。Socket默认连接60秒,60秒之内没有进行心跳交互,即读写数据,就会自动关闭连接。2,一端退出,但退出时并未关闭该连接,另一端如果在从连接中读数据则抛出该异常(Connectionreset)。简单的…

    2022年6月26日
    24
  • java rpm卸载_使用RPM卸载软件「建议收藏」

    java rpm卸载_使用RPM卸载软件「建议收藏」rpm-e做了什么rpm-e(等同于rpm–erase)这个命令能够卸载或擦除一个或多个安装包,当RPM卸载一个RPM包时,做了以下几件事:确保数据库中没有其它包引用了要卸载的包。执行卸载前的脚本(如果有的话)检查配置文件是否已经被修改过,如果是,则保留它们的一个备份。查询数据库,找到这个包安装的所有文件,如果该些文件不属于别的包,则将它们删除。执行卸载后的脚本(如果有的话)从数据库中…

    2022年9月23日
    0
  • iOS自动化之WDA(WebDriverAgent)安装

    iOS自动化之WDA(WebDriverAgent)安装1、WDA介绍WebDriverAgent在iOS端实现了一个WebDriverserver,借助这个server我们可以远程控制iOS设备。你可以启动、杀死应用,点击、滚动视图

    2022年7月4日
    50
  • 97ai新网址

    97ai新网址http://70.86.178.188/?fromuser=xxhhcc

    2022年6月8日
    51
  • 计算机系统性能取决于,计算机的性能主要取决于什么,「建议收藏」

    计算机系统性能取决于,计算机的性能主要取决于什么,「建议收藏」计算机的性能主要取决于什么什么主要取决于电脑的性能,一台计算机的性能主要取决于字长、运算速度(每秒可以执行的指令数)、内存容量、外部内存容量、I/O速度、视频内存、硬盘速度、CPU主频(CPU内核的时钟频率)。微型计算机的功能或性能不是由某个指标决定的,而是由它的系统结构、指令系统、硬件组成、软件配置等因素决定的。但是对于大多数普通用户来说,电脑的性能一般可以从以下几个指标来评价。1.运行速度运算…

    2022年6月28日
    40
  • google域名邮箱申请 gmail域名邮箱申请(企业应用套件)指南

    google域名邮箱申请 gmail域名邮箱申请(企业应用套件)指南

    2021年12月9日
    51

发表回复

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

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