Odin Inspector 系列教程 --- List Drawer Settings Attribute

2024-02-09 21:58

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

List Drawer Settings Attribute 自定义数组或者列表绘制方式

Odin已经重写对应的数组和列表的绘制
7643202-1fd4387236917c53.gif
    [Title("List Basics")][InfoBox("现在可以拖动列表元素来重新排序并逐个删除它们,并且列表具有分页功能(尝试添加大量元素!)您仍然可以从项目视图一次将许多资产拖到列表中—只需将它们拖到列表本身,并将它们插入到您想要添加它们的地方.")]public List<float> FloatList;
将[Range]属性应用于此列表,代替传统的float形式
7643202-b906512fe2affedd.gif
    [InfoBox("将[Range]属性应用于此列表,代替传统的float形式")][Range(0, 1)]public float[] FloatRangeArray;
不同方式的只读方式
7643202-70de46cc2f1044fd.png
    [ListDrawerSettings(IsReadOnly = true)]public int[] ReadOnlyArray1 = new int[] { 1, 2, 3 };[ReadOnly]public int[] ReadOnlyArray2 = new int[] { 1, 2, 3 };
负责数据结构的数组或列表
7643202-a797f45548147a4f.png
    public SomeOtherStruct[] SomeStructList;
自定义page每页的个数
7643202-1e3aff03a3fdefec.gif
    [Title("Advanced List Customization")][InfoBox("Using [ListDrawerSettings], lists can be customized in a wide variety of ways.")][ListDrawerSettings(NumberOfItemsPerPage = 5)]public int[] FiveItemsPerPage;
显示对应元素的索引和指定其元素的标签
7643202-7aea566df3e99438.gif
    [ListDrawerSettings(ShowIndexLabels = true, ListElementLabelName = "SomeString")]public SomeStruct[] IndexLabels;
禁止拖拽item,禁止翻页,禁止显示item个数
7643202-6bf0231c4edeb655.png
    [ListDrawerSettings(DraggableItems = false, Expanded = false, ShowIndexLabels = true, ShowPaging = false, ShowItemCount = false, HideRemoveButton = true)]public int[] MoreListSettings = new int[] { 1, 2, 3 };
【OnBeginListElementGUI】【OnEndListElementGUI】在每个列表元素的前后调用一个函数,并传入对应元素的索引
7643202-eb049dd7b68c0998.gif
    [ListDrawerSettings(OnBeginListElementGUI = "BeginDrawListElement", OnEndListElementGUI = "EndDrawListElement")]public SomeStruct[] InjectListElementGUI;private void BeginDrawListElement(int index){SirenixEditorGUI.BeginBox(this.InjectListElementGUI[index].SomeString);}private void EndDrawListElement(int index){SirenixEditorGUI.EndBox();}
使用它将自定义GUI注入到列表的标题栏中。
7643202-b1b3c8c02c1419e3.png
    [ListDrawerSettings(OnTitleBarGUI = "DrawRefreshButton")]public List<int> CustomButtons;private void DrawRefreshButton(){if (SirenixEditorGUI.ToolbarButton(EditorIcons.Refresh)){Debug.Log(this.CustomButtons.Count.ToString());}}
【CustomAddFunction 】覆盖将对象添加到列表的默认行为。如果引用的成员返回列表类型元素,则将对每个选定对象调用该元素一次。如果引用的方法返回void,那么不管选择了多少对象,它都只会被调用一次。
7643202-d8780945d615008f.gif
    [ListDrawerSettings(CustomAddFunction = "CustomAddFunction")]public List<int> CustomAddBehaviour;private int CustomAddFunction(){return this.CustomAddBehaviour.Count+100;}
完整示例代码
using Sirenix.OdinInspector;
using Sirenix.Utilities.Editor;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class ListDrawerSettingsAttributeExample : MonoBehaviour
{[PropertyOrder(int.MinValue), OnInspectorGUI]private void DrawIntroInfoBox(){SirenixEditorGUI.InfoMessageBox("Odin开箱即用,无需检查,即可全面升级检查器中列表和数组的图形.");}[Title("List Basics")][InfoBox("现在可以拖动列表元素来重新排序并逐个删除它们,并且列表具有分页功能(尝试添加大量元素!)您仍然可以从项目视图一次将许多资产拖到列表中—只需将它们拖到列表本身,并将它们插入到您想要添加它们的地方.")]public List<float> FloatList;[InfoBox("将[Range]属性应用于此列表,代替传统的float形式")][Range(0, 1)]public float[] FloatRangeArray;[ListDrawerSettings(IsReadOnly = true)]public int[] ReadOnlyArray1 = new int[] { 1, 2, 3 };[ReadOnly]public int[] ReadOnlyArray2 = new int[] { 1, 2, 3 };public SomeOtherStruct[] SomeStructList;[Title("Advanced List Customization")][InfoBox("Using [ListDrawerSettings], lists can be customized in a wide variety of ways.")][ListDrawerSettings(NumberOfItemsPerPage = 5)]public int[] FiveItemsPerPage;[ListDrawerSettings(ShowIndexLabels = true, ListElementLabelName = "SomeString")]public SomeStruct[] IndexLabels;[ListDrawerSettings(DraggableItems = false, Expanded = false, ShowIndexLabels = true, ShowPaging = false, ShowItemCount = false, HideRemoveButton = true)]public int[] MoreListSettings = new int[] { 1, 2, 3 };[ListDrawerSettings(OnBeginListElementGUI = "BeginDrawListElement", OnEndListElementGUI = "EndDrawListElement")]public SomeStruct[] InjectListElementGUI;private void BeginDrawListElement(int index){SirenixEditorGUI.BeginBox(this.InjectListElementGUI[index].SomeString);}private void EndDrawListElement(int index){SirenixEditorGUI.EndBox();}[ListDrawerSettings(OnTitleBarGUI = "DrawRefreshButton")]public List<int> CustomButtons;private void DrawRefreshButton(){if (SirenixEditorGUI.ToolbarButton(EditorIcons.Refresh)){Debug.Log(this.CustomButtons.Count.ToString());}}[ListDrawerSettings(CustomAddFunction = "CustomAddFunction")]public List<int> CustomAddBehaviour;private int CustomAddFunction(){return this.CustomAddBehaviour.Count+100;}[Serializable]public struct SomeStruct{public string SomeString;public int One;public int Two;public int Three;}[Serializable]public struct SomeOtherStruct{[HorizontalGroup("Split", 55), PropertyOrder(-1)][PreviewField(50, Sirenix.OdinInspector.ObjectFieldAlignment.Left), HideLabel]public UnityEngine.MonoBehaviour SomeObject;[FoldoutGroup("Split/$Name", false)]public int A, B, C;[FoldoutGroup("Split/$Name", false)]public int Two;[FoldoutGroup("Split/$Name", false)]public int Three;private string Name { get { return this.SomeObject ? this.SomeObject.name : "Null"; } }}
}

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

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



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

相关文章

Python pandas库自学超详细教程

《Pythonpandas库自学超详细教程》文章介绍了Pandas库的基本功能、安装方法及核心操作,涵盖数据导入(CSV/Excel等)、数据结构(Series、DataFrame)、数据清洗、转换... 目录一、什么是Pandas库(1)、Pandas 应用(2)、Pandas 功能(3)、数据结构二、安

2025版mysql8.0.41 winx64 手动安装详细教程

《2025版mysql8.0.41winx64手动安装详细教程》本文指导Windows系统下MySQL安装配置,包含解压、设置环境变量、my.ini配置、初始化密码获取、服务安装与手动启动等步骤,... 目录一、下载安装包二、配置环境变量三、安装配置四、启动 mysql 服务,修改密码一、下载安装包安装地

电脑提示d3dx11_43.dll缺失怎么办? DLL文件丢失的多种修复教程

《电脑提示d3dx11_43.dll缺失怎么办?DLL文件丢失的多种修复教程》在使用电脑玩游戏或运行某些图形处理软件时,有时会遇到系统提示“d3dx11_43.dll缺失”的错误,下面我们就来分享超... 在计算机使用过程中,我们可能会遇到一些错误提示,其中之一就是缺失某个dll文件。其中,d3dx11_4

Linux下在线安装启动VNC教程

《Linux下在线安装启动VNC教程》本文指导在CentOS7上在线安装VNC,包含安装、配置密码、启动/停止、清理重启步骤及注意事项,强调需安装VNC桌面以避免黑屏,并解决端口冲突和目录权限问题... 目录描述安装VNC安装 VNC 桌面可能遇到的问题总结描js述linux中的VNC就类似于Window

Go语言编译环境设置教程

《Go语言编译环境设置教程》Go语言支持高并发(goroutine)、自动垃圾回收,编译为跨平台二进制文件,云原生兼容且社区活跃,开发便捷,内置测试与vet工具辅助检测错误,依赖模块化管理,提升开发效... 目录Go语言优势下载 Go  配置编译环境配置 GOPROXYIDE 设置(VS Code)一些基本

Python错误AttributeError: 'NoneType' object has no attribute问题的彻底解决方法

《Python错误AttributeError:NoneTypeobjecthasnoattribute问题的彻底解决方法》在Python项目开发和调试过程中,经常会碰到这样一个异常信息... 目录问题背景与概述错误解读:AttributeError: 'NoneType' object has no at

Windows环境下解决Matplotlib中文字体显示问题的详细教程

《Windows环境下解决Matplotlib中文字体显示问题的详细教程》本文详细介绍了在Windows下解决Matplotlib中文显示问题的方法,包括安装字体、更新缓存、配置文件设置及编码調整,并... 目录引言问题分析解决方案详解1. 检查系统已安装字体2. 手动添加中文字体(以SimHei为例)步骤

Java JDK1.8 安装和环境配置教程详解

《JavaJDK1.8安装和环境配置教程详解》文章简要介绍了JDK1.8的安装流程,包括官网下载对应系统版本、安装时选择非系统盘路径、配置JAVA_HOME、CLASSPATH和Path环境变量,... 目录1.下载JDK2.安装JDK3.配置环境变量4.检验JDK官网下载地址:Java Downloads

使用Docker构建Python Flask程序的详细教程

《使用Docker构建PythonFlask程序的详细教程》在当今的软件开发领域,容器化技术正变得越来越流行,而Docker无疑是其中的佼佼者,本文我们就来聊聊如何使用Docker构建一个简单的Py... 目录引言一、准备工作二、创建 Flask 应用程序三、创建 dockerfile四、构建 Docker

C# 比较两个list 之间元素差异的常用方法

《C#比较两个list之间元素差异的常用方法》:本文主要介绍C#比较两个list之间元素差异,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录1. 使用Except方法2. 使用Except的逆操作3. 使用LINQ的Join,GroupJoin