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

相关文章

C#集成DeepSeek模型实现AI私有化的流程步骤(本地部署与API调用教程)

《C#集成DeepSeek模型实现AI私有化的流程步骤(本地部署与API调用教程)》本文主要介绍了C#集成DeepSeek模型实现AI私有化的方法,包括搭建基础环境,如安装Ollama和下载DeepS... 目录前言搭建基础环境1、安装 Ollama2、下载 DeepSeek R1 模型客户端 ChatBo

JAVA集成本地部署的DeepSeek的图文教程

《JAVA集成本地部署的DeepSeek的图文教程》本文主要介绍了JAVA集成本地部署的DeepSeek的图文教程,包含配置环境变量及下载DeepSeek-R1模型并启动,具有一定的参考价值,感兴趣的... 目录一、下载部署DeepSeek1.下载ollama2.下载DeepSeek-R1模型并启动 二、J

Vue项目的甘特图组件之dhtmlx-gantt使用教程和实现效果展示(推荐)

《Vue项目的甘特图组件之dhtmlx-gantt使用教程和实现效果展示(推荐)》文章介绍了如何使用dhtmlx-gantt组件来实现公司的甘特图需求,并提供了一个简单的Vue组件示例,文章还分享了一... 目录一、首先 npm 安装插件二、创建一个vue组件三、业务页面内 引用自定义组件:四、dhtmlx

MySQL zip安装包配置教程

《MySQLzip安装包配置教程》这篇文章详细介绍了如何使用zip安装包在Windows11上安装MySQL8.0,包括下载、解压、配置环境变量、初始化数据库、安装服务以及更改密码等步骤,感兴趣的朋... 目录mysql zip安装包配置教程1、下载zip安装包:2、安装2.1 解压zip包到安装目录2.2

Java使用Tesseract-OCR实战教程

《Java使用Tesseract-OCR实战教程》本文介绍了如何在Java中使用Tesseract-OCR进行文本提取,包括Tesseract-OCR的安装、中文训练库的配置、依赖库的引入以及具体的代... 目录Java使用Tesseract-OCRTesseract-OCR安装配置中文训练库引入依赖代码实

Ubuntu固定虚拟机ip地址的方法教程

《Ubuntu固定虚拟机ip地址的方法教程》本文详细介绍了如何在Ubuntu虚拟机中固定IP地址,包括检查和编辑`/etc/apt/sources.list`文件、更新网络配置文件以及使用Networ... 1、由于虚拟机网络是桥接,所以ip地址会不停地变化,接下来我们就讲述ip如何固定 2、如果apt安

PyCharm 接入 DeepSeek最新完整教程

《PyCharm接入DeepSeek最新完整教程》文章介绍了DeepSeek-V3模型的性能提升以及如何在PyCharm中接入和使用DeepSeek进行代码开发,本文通过图文并茂的形式给大家介绍的... 目录DeepSeek-V3效果演示创建API Key在PyCharm中下载Continue插件配置Con

Deepseek R1模型本地化部署+API接口调用详细教程(释放AI生产力)

《DeepseekR1模型本地化部署+API接口调用详细教程(释放AI生产力)》本文介绍了本地部署DeepSeekR1模型和通过API调用将其集成到VSCode中的过程,作者详细步骤展示了如何下载和... 目录前言一、deepseek R1模型与chatGPT o1系列模型对比二、本地部署步骤1.安装oll

在不同系统间迁移Python程序的方法与教程

《在不同系统间迁移Python程序的方法与教程》本文介绍了几种将Windows上编写的Python程序迁移到Linux服务器上的方法,包括使用虚拟环境和依赖冻结、容器化技术(如Docker)、使用An... 目录使用虚拟环境和依赖冻结1. 创建虚拟环境2. 冻结依赖使用容器化技术(如 docker)1. 创

Spring Boot整合log4j2日志配置的详细教程

《SpringBoot整合log4j2日志配置的详细教程》:本文主要介绍SpringBoot项目中整合Log4j2日志框架的步骤和配置,包括常用日志框架的比较、配置参数介绍、Log4j2配置详解... 目录前言一、常用日志框架二、配置参数介绍1. 日志级别2. 输出形式3. 日志格式3.1 PatternL