Odin Inspector 系列教程 — List Drawer Settings Attribute

Odin Inspector 系列教程 — List Drawer Settings AttributeListDrawerSettingsAttribute自定义数组或者列表绘制方式Odin已经重写对应的数组和列表的绘制[Title(“ListBasics”)][InfoBox(“现在可以拖动列表元素来重新排序并逐个删除它们,并且列表具有分页功能(尝试添加大量元素!)您仍然可以从项目视图一次将许多资产拖到列表中—只需将它们拖到列表本…

大家好,又见面了,我是你们的朋友全栈君。

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 系列教程

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/162794.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • JavaSE基础(101) 遍历ArrayList集合的4种方式[通俗易懂]

    JavaSE基础(101) 遍历ArrayList集合的4种方式[通俗易懂]ArrayList遍历:取出ArrayList集合中的数据①:for循环②:增强for循环:foreach③:Iterator:迭代器④:ListIterator:双向迭代器ex:/***ArrayList遍历:取出ArrayList集合中的数据*①:for循环*②:增强for循环:foreach*③:Iterator:迭代器*④:…

    2022年7月22日
    14
  • 华为云:申请免费证书、部署HTTPS证书操作流程[通俗易懂]

    华为云:申请免费证书、部署HTTPS证书操作流程[通俗易懂]一、前提:(1)已经有华为云账号;(2)已经申请域名;(3)已经购买华为云弹性服务器;二、目的:(1)部署SSL证书之后能通过https地址访问服务;三、流程:1.申请免费证书:(注:官方证书操作链接:https://support.huaweicloud.com/usermanual-scm/scm_01_0132.html)(1)在搜索栏搜索“免…

    2022年9月27日
    2
  • layoutSubviews的使用

    layoutSubviews的使用-(void)layoutSubviews{ }layoutSubviews是对subviews的重新布局以下情况会被调用1.直接调用layoutSubviews.如:[selflayoutSubviews];2.用addSubview添加视图时会触发3.滚动UIScrollView时会触发4.旋转屏幕的时候会触发父视图的layoutSu

    2022年7月15日
    17
  • FPGA中实现对数运算「建议收藏」

    FPGA中实现对数运算「建议收藏」FPGA中实现对数运算主要有三种方法:(1)在外部直接算好对数值,按照数值范围做个表,存在ram里,到时候查表。为了减少表深度,提高资源利用率,可以考虑去掉部分低位数值,损失一定的精度。(2)使用cordic算法求解对数。(3)log10(x)=ln(x)*log10(e),log10(e)是常数可以手动先计算好,用IPCore的话多个乘法器。下面介绍使用IP核fl…

    2025年6月28日
    5
  • Iscsiadm解析

    Iscsiadm解析1.#iscsiadm-mdiscovery-tst-p192.168.4.109:3260发现新增target-m模式discovery-t类型(iSCSI3discoverytypes:SendTargets,SLP,andiSNS)-T目标名称stsendtargets发送目标-p…

    2022年8月23日
    7
  • Linux系统查看CPU「建议收藏」

    Linux系统查看CPU「建议收藏」    在linux的系统维护中,可能需要经常查看cpu使用率,分析系统整体的运行情况,以便性能分析优化。而监控CPU的性能一般包括以下3点:运行队列、CPU使用率和上下文切换。    对于每一个CPU来说运行队列最好不要超过3,例如,如果是双核CPU就不要超过6。如果队列长期保持在3以上,说明任何一个进程运行时都不能马上得到cpu的响应,这时可能需要考虑升级cpu。另外满负荷运…

    2022年4月19日
    160

发表回复

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

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