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

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

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

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • QTreeView使用总结1,一个简单示例

    QTreeView使用总结1,一个简单示例1,简介本文为一个最简单的QTreeView初始化过程的示例。除去了一切操作响应等细节,只是展示使QTreeView显示出带层次结构的数据,至少需要哪些代码。只附带了一点点常用设置项。2,效果3,代码一个QTreeView插入三层数据的最简单代码示例:voidMainWindow::InitTree(){//1,构造Model,这里示例具有3层关系的model构造过程QSt…

  • 华为手机屏幕锁屏时间设置_华为手机自动锁屏时间设置「建议收藏」

    华为手机屏幕锁屏时间设置_华为手机自动锁屏时间设置「建议收藏」设置华为手机自动锁屏2113时间的方法如下:们需5261要的材料分别4102有:华为手机、1653设置app。1、首先,打开华为手机,打开设置,在设置界面中找到“锁屏和密码”按钮。2、然后在锁屏和密码界面中,点击“安全锁定设置”按钮。3、最后在安全锁定设置界面中,点击“自动锁屏”,您就设置手机自动锁屏时间了。本回答被网友采纳,可能是打开了2113省电模式的原因,当电量低于20%时将提5261示开启…

  • FFM原理理解与应用

    FFM原理理解与应用本文参考了美团团队的介绍文章。http://tech.meituan.com/deep-understanding-of-ffm-principles-and-practices.html以及http://blog.csdn.net/zc02051126/article/details/54614230FM和FFM模型是最近几年提出的模型,凭借其在数据量比较大并且特征稀疏的情况下,…

  • UML活动图、状态图

    UML活动图、状态图 本文主要介绍状态图和活动图。一.状态图     状态(state)是指在对象的生命期中的某个条件或状况,在此期间对象将满足某些条件、执行某些活动或等待某些事件。所有对象都具有状态,状态是对象执行了一系列活动的结果,当某个事件发生后,对象的状态发生变化。    状态图(statechartdiagram):     用来描述一个特定的对象所有可能的状态,以及由于各种事件的发…

  • JPA规范:一对多、一对一、多对多的双向关联与级联操作以及JPA联合主键

    JPA规范:一对多、一对一、多对多的双向关联与级联操作以及JPA联合主键

  • 。。。,带着这三点疑问,让们层层深入的对HTTPS原理进行剖析!

    点击上方“全栈程序员社区”,星标公众号 重磅干货,第一时间送达 作者:leapMie https://blog.leapmie.com/archives/418/ HTTPS 随着…

发表回复

您的电子邮箱地址不会被公开。

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