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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Idea激活码最新教程2020.3.4版本,永久有效激活码,亲测可用,记得收藏

    Idea激活码最新教程2020.3.4版本,永久有效激活码,亲测可用,记得收藏Idea 激活码教程永久有效 2020 3 4 激活码教程 Windows 版永久激活 持续更新 Idea 激活码 2020 3 4 成功激活

    2025年5月22日
    2
  • 为什么补码是按位取反加一_补码为什么加1

    为什么补码是按位取反加一_补码为什么加1首先,阅读这篇文章的你,肯定是一个在网上已经纠结了很久的读者,因为你查阅了所有你能查到的资料,然后他们都会很耐心的告诉你,补码:就是按位取反,然后加一。准确无误,毫无破绽。但是,你搜遍了所有俯拾即是而且准确无误的答案,却仍然选择来看这篇毫不起眼的文章,原因只有一个,只因为你还没有得到你想要的东西。            因为你想要的,不是1+1=2,而是,1+1为什么等于2。当然,我们不讨论

    2022年8月15日
    4
  • 智能小车设计方案_智能小车研究目的及意义

    智能小车设计方案_智能小车研究目的及意义简介智能循迹小车是基于自动引导机器人系统,用以实现小车自动识别路线,以及选择正确的路线。智能循迹小车是一个运用传感器、单片机、电机驱动及自动控制等技术来实现按照预先设定的模式下,不受人为管理时能够自动实现循迹导航的高新科技。方案论证系统总体方案一、小车控制系统的结构框图二、程序流程框图三、循迹原理的简单描述循迹是指小车在白色地板上,循黑线行走通常采取的方法是红外探测法,红外探测法即利用红外线光遇到白色物体表面具有不同的反射性质的特点,在小车行驶过程…

    2022年10月18日
    2
  • Tomcat 7 下载地址

    Tomcat 7 下载地址Tomcat7百度云盘下载地址:https://pan.baidu.com/s/1Pvw3kIcCtKcYjaKrq7k-iQ

    2022年5月19日
    34
  • 各种技术网站的网址

    各种技术网站的网址http://www.eclipse.com/http://www.apache.org

    2022年7月17日
    19
  • File中createNewFile()和createTempFile()区别[通俗易懂]

    1、createTempFile():FilesampleDir=newFile(Environment.getExternalStorageDirectory().getAbsolutePath()+”/FMRecording”);mSampleFile=File.createTempFile(“FMRecording”,”.m4a”,sampleDir);主要的

    2022年4月11日
    263

发表回复

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

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