Odin Inspector 系列教程 — List Drawer Settings Attribute
2023-06-13 09:12:43 时间
大家好,又见面了,我是你们的朋友全栈君。
List Drawer Settings Attribute 自定义数组或者列表绘制方式
Odin已经重写对应的数组和列表的绘制
[Title("List Basics")]
[InfoBox("现在可以拖动列表元素来重新排序并逐个删除它们,并且列表具有分页功能(尝试添加大量元素!)您仍然可以从项目视图一次将许多资产拖到列表中—只需将它们拖到列表本身,并将它们插入到您想要添加它们的地方.")]
public List<float> FloatList;
将[Range]属性应用于此列表,代替传统的float形式
[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;
自定义page每页的个数
[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;
禁止拖拽item,禁止翻页,禁止显示item个数
[ListDrawerSettings(DraggableItems = false, Expanded = false, ShowIndexLabels = true, ShowPaging = false, ShowItemCount = false, HideRemoveButton = true)]
public int[] MoreListSettings = new int[] { 1, 2, 3 };
【OnBeginListElementGUI】【OnEndListElementGUI】在每个列表元素的前后调用一个函数,并传入对应元素的索引
[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注入到列表的标题栏中。
[ListDrawerSettings(OnTitleBarGUI = "DrawRefreshButton")]
public List<int> CustomButtons;
private void DrawRefreshButton()
{
if (SirenixEditorGUI.ToolbarButton(EditorIcons.Refresh))
{
Debug.Log(this.CustomButtons.Count.ToString());
}
}
【CustomAddFunction 】覆盖将对象添加到列表的默认行为。如果引用的成员返回列表类型元素,则将对每个选定对象调用该元素一次。如果引用的方法返回void,那么不管选择了多少对象,它都只会被调用一次。
[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"; } }
}
}
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/162794.html原文链接:https://javaforall.cn
相关文章
- 逗号拼接字符串转list[通俗易懂]
- 数组使用arrays.aslist转化为集合_int数组转list集合
- oracle中list_oracle listagg 拼接字符串过长
- java——ArrayList和LinkedList的区别以及List的实现
- spring mvc 接收页面表单List 怎么处理
- jdk1.8 list 多条件排序
- ORA-14632: cannot specify PARALLEL clause when adding a List subpartition ORACLE 报错 故障修复 远程处理
- Python list列表详解
- 《Drools7.0.0.Final规则引擎教程》相同对象and List使用详解编程语言
- Redis List 操作简明教程(redislist操作)
- 利用Redis构建新的List存储方式(redis存储list)
- Redis中的List数据结构详解(redis中list数据)
- Redis如何清空List:技巧分享(redis清空list)
- 类型探索Redis中List数据结构的优势(redis中的list)
- 性能优化提升Redis List性能的简单方法(redis的list)
- 轻松高效:Redis存取List的最佳实践(redis 存取list)
- 利用Redis实现列表数据存储(获取redis的list)
- Oracle中使用List命令查看表结构(list命令oracle)
- 从Redis读取List数据简单又高效(从redis读取list)
- 实现使用List实现Redis队列(redis队列用list)
- 警惕Redis List被空出(redis里list为空)
- List<>中Find的用法小结
- java使用list实现数据库的like功能
- javaScript如何处理从java后台返回的list