Odin Inspector 系列教程 --- Value Dropdown Attribute

2024-02-09 22:08

本文主要是介绍Odin Inspector 系列教程 --- Value Dropdown Attribute,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Value Dropdown Attribute特性用于任何属性,并使用可配置选项创建下拉列表。使用此选项可为用户提供一组特定的选项供您选择。
也就是创建一些特殊的下拉条

这个里面的属性就有点多了,达到了16个!!!
下面笔者逐个讲解

MemberName,也是唯一一个有参构造函数需要的属性,有两种形式的Drop下拉条,一种是直接数值的,另一种是Key-Value形式的
7643202-5133392a301e7482.gif
    /*【MemberName】*/[PropertySpace(40, 0)][ValueDropdown("TextureSizes")]public int SomeSize1;private static int[] TextureSizes = new int[] { 32, 64, 128, 256, 512, 1024, 2048, 4096 };[ValueDropdown("FriendlyTextureSizes")]public int SomeSize2;private static IEnumerable FriendlyTextureSizes = new ValueDropdownList<int>(){{ "Small", 256 },{ "Medium", 512 },{ "Large", 1024 },};
【SortDropdownItems】默认为false 开启后为下拉列表为根据Key升序排序
7643202-0d2e87e0c595e834.gif
    /*【SortDropdownItems】默认为false 开启后为下拉列表为根据Key升序排序*/[PropertySpace(40, 0)][ValueDropdown("SortList1")]public int SomeSize3;private IEnumerable SortList1 = new ValueDropdownList<int>(){{ "Small", 256 },{ "Medium", 512 },{ "Large", 1024 },{ "A", 128 },};[PropertySpace(0, 40)][ValueDropdown("SortList2", SortDropdownItems = true)]public int SomeSize4;private List<ValueDropdownItem<int>> SortList2 = new ValueDropdownList<int>(){{ "Small", 256 },{ "Medium", 512 },{ "Large", 1024 },{ "A", 128 },};
【DropdownTitle】给下来条提供一个标题
7643202-9a139d5edd540247.gif
    [PropertySpace(0, 40)][ValueDropdown("TextureSizes", DropdownTitle = "下拉条标题")]public int SomeSize5;
【DropdownHeight】下拉条高度
7643202-8d497fb864acf9ad.gif
    /*【DropdownHeight】下拉条高度*/[PropertySpace(0, 40)][ValueDropdown("TextureSizes", DropdownHeight = 80)]public int SomeSize6;
【DropdownWidth】下拉条的宽度
7643202-94faa27ba6d8709c.gif
    /*【DropdownWidth】下拉条的宽度*/[PropertySpace(0, 40)][ValueDropdown("TextureSizes", DropdownWidth = 100)]public int SomeSize7;
【FlattenTreeView】是否使用平铺的树形视图
7643202-b8448162f2aff711.gif
    /*【FlattenTreeView】是否使用平铺的树形视图*/[PropertySpace(0, 40)][ValueDropdown("TreeViewOfInts", FlattenTreeView = true)]//默认为false,如果设置为true则禁用树形结构使用平铺模式public int SomeSize8;
【DoubleClickToConfirm】需要双击才能确地选中的内容
7643202-0522a8c8db841a5e.gif
    /*【DoubleClickToConfirm】需要双击才能确地选中的内容*/[PropertySpace(0, 40)][ValueDropdown("TreeViewOfInts", DoubleClickToConfirm = true)]//需要双击才能选中public int SomeSize9;
【HideChildProperties】是否隐藏此类型所含有的属性信息
7643202-f9351ae2fc862355.png
    /*【HideChildProperties】是否隐藏此类型所含有的属性信息*/[ValueDropdown("RangVector3", HideChildProperties = true)]//public Vector3 vector3HideChildProperties;[PropertySpace(0, 40)][ValueDropdown("RangVector3", HideChildProperties = false)]//public Vector3 vector3ShowChildProperties;public IEnumerable<Vector3>  RangVector3(){return Enumerable.Range(0, 10).Select(i => new Vector3(i, i, i));}
【AppendNextDrawer】下拉条变成一个小的选择器,代替原有的宽型下拉条
7643202-132b3d1fe697a04a.gif
    /*【AppendNextDrawer】下拉条变成一个小的选择器,代替原有的宽型下拉条*/[PropertySpace(0, 40)][ValueDropdown("TreeViewOfInts", AppendNextDrawer = true)]//public int SomeSize11;
【DisableGUIInAppendedDrawer】配合AppendNextDrawer使用,显示的数值为灰度状态,达到不可更改数值的目的
7643202-55796b6570049c75.gif
    /*【DisableGUIInAppendedDrawer】配合AppendNextDrawer使用,显示的数值为灰度状态,达到不可更改数值的目的*/[PropertySpace(0, 40)][ValueDropdown("TreeViewOfInts", AppendNextDrawer = true, DisableGUIInAppendedDrawer = true)]//public int SomeSize12;
ExpandAllMenuItems】下拉条里面的条目是否全部展开
7643202-01569c004ab367f8.gif
    /*【ExpandAllMenuItems】下拉条里面的条目是否全部展开*/[ValueDropdown("TreeViewOfInts" , ExpandAllMenuItems = false)]//public int SomeSize13;[PropertySpace(0, 40)][ValueDropdown("TreeViewOfInts", ExpandAllMenuItems =true )]//public int SomeSize14;
【IsUniqueList】在添加的列表Item前面添加勾选框,可以一次性勾选多个Item并添加
7643202-c01d00466668a841.gif
    /*【IsUniqueList】在添加的列表Item前面添加勾选框,可以一次性勾选多个Item并添加*/[ValueDropdown("GetAllSceneObjects", IsUniqueList = false)]public List<GameObject> UniqueGameobjectList0;[PropertySpace(0, 40)][ValueDropdown("GetAllSceneObjects", IsUniqueList = true)]public List<GameObject> UniqueGameobjectList1;
【ExcludeExistingValuesInList】添加列中不会显示已经选中的Item
7643202-a494380d06e61060.gif
    /*【ExcludeExistingValuesInList】添加列中不会显示已经选中的Item*/[ValueDropdown("GetAllSceneObjects")]public List<GameObject> UniqueGameobjectList2;[PropertySpace(0, 40)][ValueDropdown("GetAllSceneObjects", ExcludeExistingValuesInList = true)]public List<GameObject> UniqueGameobjectList3;
【DisableListAddButtonBehaviour】禁用下拉列表,以弹窗的形式弹出
7643202-ce51f8559caf0457.gif
    /*【DisableListAddButtonBehaviour】禁用下拉列表,以弹窗的形式弹出*/[PropertySpace(0, 40)][ValueDropdown("GetAllSceneObjects", DisableListAddButtonBehaviour = true, IsUniqueList = true)]public List<GameObject> UniqueGameobjectList4;
【DrawDropdownForListElements】已经添加的Item不会再出现Item下拉表
7643202-cc3b46a31df970df.gif
    /*【DrawDropdownForListElements】已经添加的Item不会再出现Item下拉表*/[PropertySpace(0, 40)][ValueDropdown("GetAllSceneObjects", DrawDropdownForListElements = false)]public List<GameObject> UniqueGameobjectList5;
``##### 【NumberOfItemsBeforeEnablingSearch】查过指定数量的Item则出现搜索框。默认是10。![](https://upload-images.jianshu.io/upload_images/7643202-87b2e38d89c171cc.gif?imageMogr2/auto-orient/strip)```cs/*【NumberOfItemsBeforeEnablingSearch】查过指定数量的Item则出现搜索框。默认是10。*/[ValueDropdown("GetAllSceneObjects", NumberOfItemsBeforeEnablingSearch =200)]public List<GameObject> UniqueGameobjectList6;[PropertySpace(0, 40)][ValueDropdown("GetAllSceneObjects", NumberOfItemsBeforeEnablingSearch = 20)]public List<GameObject> UniqueGameobjectList7;
示例完整代码(含有一些其他辅助性功能代码)
using Sirenix.OdinInspector;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;public class ValueDropdownAttributeExample : MonoBehaviour
{/*【MemberName】*/[PropertySpace(40, 0)][ValueDropdown("TextureSizes")]public int SomeSize1;private static int[] TextureSizes = new int[] { 32, 64, 128, 256, 512, 1024, 2048, 4096 };[ValueDropdown("FriendlyTextureSizes")]public int SomeSize2;private static IEnumerable FriendlyTextureSizes = new ValueDropdownList<int>(){{ "Small", 256 },{ "Medium", 512 },{ "Large", 1024 },};/*【SortDropdownItems】默认为false 开启后为下拉列表为根据Key升序排序*/[PropertySpace(40, 0)][ValueDropdown("SortList1")]public int SomeSize3;private IEnumerable SortList1 = new ValueDropdownList<int>(){{ "Small", 256 },{ "Medium", 512 },{ "Large", 1024 },{ "A", 128 },};[PropertySpace(0, 40)][ValueDropdown("SortList2", SortDropdownItems = true)]public int SomeSize4;private List<ValueDropdownItem<int>> SortList2 = new ValueDropdownList<int>(){{ "Small", 256 },{ "Medium", 512 },{ "Large", 1024 },{ "A", 128 },};/*【DropdownTitle】给下来条提供一个标题*/[PropertySpace(0, 40)][ValueDropdown("TextureSizes", DropdownTitle = "下拉条标题")]public int SomeSize5;/*【DropdownHeight】下拉条高度*/[PropertySpace(0, 40)][ValueDropdown("TextureSizes", DropdownHeight = 80)]public int SomeSize6;/*【DropdownWidth】下拉条的宽度*/[PropertySpace(0, 40)][ValueDropdown("TextureSizes", DropdownWidth = 100)]public int SomeSize7;/*【FlattenTreeView】是否使用平铺的树形视图*/[PropertySpace(0, 40)][ValueDropdown("TreeViewOfInts", FlattenTreeView = true)]//默认为false,如果设置为true则禁用树形结构使用平铺模式public int SomeSize8;/*【DoubleClickToConfirm】需要双击才能确地选中的内容*/[PropertySpace(0, 40)][ValueDropdown("TreeViewOfInts", DoubleClickToConfirm = true)]//需要双击才能选中public int SomeSize9;/*【HideChildProperties】是否隐藏此类型所含有的属性信息*/[ValueDropdown("RangVector3", HideChildProperties = true)]//public Vector3 vector3HideChildProperties;[PropertySpace(0, 40)][ValueDropdown("RangVector3", HideChildProperties = false)]//public Vector3 vector3ShowChildProperties;public IEnumerable<Vector3>  RangVector3(){return Enumerable.Range(0, 10).Select(i => new Vector3(i, i, i));}/*【AppendNextDrawer】下拉条变成一个小的选择器,代替原有的宽型下拉条*/[PropertySpace(0, 40)][ValueDropdown("TreeViewOfInts", AppendNextDrawer = true)]//public int SomeSize11;/*【DisableGUIInAppendedDrawer】配合AppendNextDrawer使用,显示的数值为灰度状态,达到不可更改数值的目的*/[PropertySpace(0, 40)][ValueDropdown("TreeViewOfInts", AppendNextDrawer = true, DisableGUIInAppendedDrawer = true)]//public int SomeSize12;/*【ExpandAllMenuItems】下拉条里面的条目是否全部展开*/[ValueDropdown("TreeViewOfInts" , ExpandAllMenuItems = false)]//public int SomeSize13;[PropertySpace(0, 40)][ValueDropdown("TreeViewOfInts", ExpandAllMenuItems =true )]//public int SomeSize14;/*【IsUniqueList】在添加的列表Item前面添加勾选框,可以一次性勾选多个Item并添加*/[ValueDropdown("GetAllSceneObjects", IsUniqueList = false)]public List<GameObject> UniqueGameobjectList0;[PropertySpace(0, 40)][ValueDropdown("GetAllSceneObjects", IsUniqueList = true)]public List<GameObject> UniqueGameobjectList1;/*【ExcludeExistingValuesInList】添加列中不会显示已经选中的Item*/[ValueDropdown("GetAllSceneObjects")]public List<GameObject> UniqueGameobjectList2;[PropertySpace(0, 40)][ValueDropdown("GetAllSceneObjects", ExcludeExistingValuesInList = true)]public List<GameObject> UniqueGameobjectList3;/*【DisableListAddButtonBehaviour】禁用下拉列表,以弹窗的形式弹出*/[PropertySpace(0, 40)][ValueDropdown("GetAllSceneObjects", DisableListAddButtonBehaviour = true, IsUniqueList = true)]public List<GameObject> UniqueGameobjectList4;/*【DrawDropdownForListElements】已经添加的Item不会再出现Item下拉表*/[PropertySpace(0, 40)][ValueDropdown("GetAllSceneObjects", DrawDropdownForListElements = false)]public List<GameObject> UniqueGameobjectList5;/*【NumberOfItemsBeforeEnablingSearch】查过指定数量的Item则出现搜索框。默认是10。*/[ValueDropdown("GetAllSceneObjects", NumberOfItemsBeforeEnablingSearch =200)]public List<GameObject> UniqueGameobjectList6;[PropertySpace(0, 40)][ValueDropdown("GetAllSceneObjects", NumberOfItemsBeforeEnablingSearch = 20)]public List<GameObject> UniqueGameobjectList7;[ValueDropdown("GetListOfMonoBehaviours", AppendNextDrawer = true, HideChildProperties = false)]public MonoBehaviour SomeMonoBehaviour;private IEnumerable<MonoBehaviour> GetListOfMonoBehaviours(){return GameObject.FindObjectsOfType<MonoBehaviour>();}[ValueDropdown("KeyCodes")]public KeyCode FilteredEnum;private static IEnumerable<KeyCode> KeyCodes = Enumerable.Range((int)KeyCode.Alpha0, 10).Cast<KeyCode>();[ValueDropdown("TreeViewOfInts", ExpandAllMenuItems = true)]public List<int> IntTreeview = new List<int>() { 1, 2, 7 };/// <summary>/// 以“/”符号作为类别分隔符/// </summary>private IEnumerable TreeViewOfInts = new ValueDropdownList<int>()
{{ "Node 1/Node 1.1", 1 },{ "Node 1/Node 1.2", 2 },{ "Node 2/Node 2.1", 3 },{ "Node 3/Node 3.1", 4 },{ "Node 3/Node 3.2", 5 },{ "Node 1/Node 3.1/Node 3.1.1", 6 },{ "Node 1/Node 3.1/Node 3.1.2", 7 },{ "Node 1", -1 },{ "Node 2", -2 },{ "Node 3", -3 },{ "Node 4", -4 },
};/// <summary>/// IsUniqueList为true 每个Item上面有一个勾选框/// </summary>[ValueDropdown("GetAllSceneObjects", IsUniqueList = true, HideChildProperties = false)]public List<GameObject> UniqueGameobjectList;private static IEnumerable GetAllSceneObjects(){Func<Transform, string> getPath = null;getPath = x => (x ? getPath(x.parent) + "/" + x.gameObject.name : "");//三元运算符 其中X为Transformreturn GameObject.FindObjectsOfType<GameObject>().Select(x => new ValueDropdownItem(getPath(x.transform), x));}/// <summary>/// ExcludeExistingValuesInList 为 ture则选中的item不在出现在等待选择的列下拉表中/// DrawDropdownForListElements 为 true  每个item都有一个下拉列表/// </summary>[ValueDropdown("GetAllSceneObjects", IsUniqueList = false, DropdownTitle = "Select Scene Object", DrawDropdownForListElements = false, ExcludeExistingValuesInList = true)]public List<GameObject> UniqueGameobjectListMode2;private static IEnumerable GetAllScriptableObjects(){return UnityEditor.AssetDatabase.FindAssets("t:ScriptableObject").Select(x => UnityEditor.AssetDatabase.GUIDToAssetPath(x)).Select(x => new ValueDropdownItem(x, UnityEditor.AssetDatabase.LoadAssetAtPath<ScriptableObject>(x)));}private static IEnumerable GetAllSirenixAssets(){var root = "Assets/Plugins/Sirenix/";return UnityEditor.AssetDatabase.GetAllAssetPaths().Where(x => x.StartsWith(root)).Select(x => x.Substring(root.Length)).Select(x => new ValueDropdownItem(x, UnityEditor.AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(root + x)));}
}

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

这篇关于Odin Inspector 系列教程 --- Value Dropdown Attribute的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/695395

相关文章

React+TS前台项目实战(十七)-- 全局常用组件Dropdown封装

文章目录 前言Dropdown组件1. 功能分析2. 代码+详细注释3. 使用方式4. 效果展示 总结 前言 今天这篇主要讲全局Dropdown组件封装,可根据UI设计师要求自定义修改。 Dropdown组件 1. 功能分析 (1)通过position属性,可以控制下拉选项的位置 (2)通过传入width属性, 可以自定义下拉选项的宽度 (3)通过传入classN

Steam邮件推送内容有哪些?配置教程详解!

Steam邮件推送功能是否安全?如何个性化邮件推送内容? Steam作为全球最大的数字游戏分发平台之一,不仅提供了海量的游戏资源,还通过邮件推送为用户提供最新的游戏信息、促销活动和个性化推荐。AokSend将详细介绍Steam邮件推送的主要内容。 Steam邮件推送:促销优惠 每当平台举办大型促销活动,如夏季促销、冬季促销、黑色星期五等,用户都会收到邮件通知。这些邮件详细列出了打折游戏、

JavaWeb系列二十: jQuery的DOM操作 下

jQuery的DOM操作 CSS-DOM操作多选框案例页面加载完毕触发方法作业布置jQuery获取选中复选框的值jQuery控制checkbox被选中jQuery控制(全选/全不选/反选)jQuery动态添加删除用户 CSS-DOM操作 获取和设置元素的样式属性: css()获取和设置元素透明度: opacity属性获取和设置元素高度, 宽度: height(), widt

X-AnyLabeling使用教程

1.AI 模型自动分割标注使用教程 2.AI 模型自动目标检测标注使用教程

C语言入门系列:探秘二级指针与多级指针的奇妙世界

文章目录 一,指针的回忆杀1,指针的概念2,指针的声明和赋值3,指针的使用3.1 直接给指针变量赋值3.2 通过*运算符读写指针指向的内存3.2.1 读3.2.2 写 二,二级指针详解1,定义2,示例说明3,二级指针与一级指针、普通变量的关系3.1,与一级指针的关系3.2,与普通变量的关系,示例说明 4,二级指针的常见用途5,二级指针扩展到多级指针 小结 C语言的学习之旅中,二级

青龙面板2.9之Cdle傻妞机器人编译教程

看到有的朋友对傻妞机器人感兴趣,这里写一下傻妞机器人的编译教程。 第一步,这里以linux amd64为例,去官网下载安装go语言安装包: 第二步,输入下方指令 cd /usr/local && wget https://golang.google.cn/dl/go1.16.7.linux-amd64.tar.gz -O go1.16.7.linux-amd64.tar.gz

青龙面板部署通用教程,含服务器、路由器、X86等部署方法

1. 拉取镜像/更新镜像 docker pull whyour/qinglong:latest 2. 删除镜像 docker rmi whyour/qinglong:latest 3. 启动容器 普通服务器 docker run -dit \-v $PWD/ql/config:/ql/config \-v $PWD/ql/log:/ql/log \-v $PWD/ql/db:

宝塔面板部署青龙面板教程【简单易上手】

首先,你得有一台部署了宝塔面板的服务器(自己用本地电脑也可以)。 宝塔面板部署自行百度一下,很简单,这里就不走流程了,官网版本就可以,无需开心版。 首先,打开宝塔面板的软件商店,找到下图这个软件(Docker管理器)安装,青龙面板还是安装在docker里,这里依赖宝塔面板安装和管理docker。 安装完成后,进入SSH终端管理,输入代码安装青龙面板。ssh可以直接宝塔里操作,也可以安装ssh连接

PS系统教程25

介绍软件 BR(bridge) PS 配套软件,方便素材整理、管理素材 作用:起到桥梁作用 注意:PS和BR尽量保持版本一致 下载和安装可通过CSDN社区搜索,有免费安装指导。 安装之后,我们打开照片只需双击照片,就自动在Ps软件中打开。 前提:电脑上有PS软件 三种预览格式 全屏预览 评星级 直接按数字键就可以 方向键可以更换图片 esc退出 幻灯片放

JavaWeb系列六: 动态WEB开发核心(Servlet) 上

韩老师学生 官网文档为什么会出现Servlet什么是ServletServlet在JavaWeb项目位置Servlet基本使用Servlet开发方式说明快速入门- 手动开发 servlet浏览器请求Servlet UML分析Servlet生命周期GET和POST请求分发处理通过继承HttpServlet开发ServletIDEA配置ServletServlet注意事项和细节 Servlet注