Odin Inspector 系列教程 --- Table List Attribute

Table List Attribute特性:用于在检查器中将列表和数组呈现为表。

7643202-bd15b82846af4674.gif
7643202-cceb3d38c04b1c5a.gif
【ShowIndexLabels】设置为True,则为每个元素绘制一个标签,其中显示元素的索引。
7643202-c56c3b33926817ee.png
    [TableList(ShowIndexLabels = true)]
    public List<SomeCustomClass> TableListWithIndexLabels = new List<SomeCustomClass>()
{
    new SomeCustomClass(),
    new SomeCustomClass(),
};
【DrawScrollView 】为True,为table添加一个滚动条,并设置滚动条最大高度(MaxScrollViewHeight )和最小高度(MinScrollViewHeight )
7643202-1a0cf3c513e58eb6.gif
    [TableList(DrawScrollView = true, MaxScrollViewHeight = 200, MinScrollViewHeight = 100)]
    public List<SomeCustomClass> MinMaxScrollViewTable = new List<SomeCustomClass>()
{
    new SomeCustomClass(),
    new SomeCustomClass(),
};
【ShowPaging】设置为True,则绘制一个翻页的选项 【NumberOfItemsPerPage】则设置每个分页含有的Item数量,默认15个
7643202-90e569cd4c8a2692.gif
    [TableList(ShowPaging = true, DrawScrollView = false)]
    public List<SomeCustomClass> TableWithPaging = new List<SomeCustomClass>()
{
    new SomeCustomClass(),
    new SomeCustomClass(),
    new SomeCustomClass(),
    new SomeCustomClass(),
    new SomeCustomClass(),
    new SomeCustomClass(),
    new SomeCustomClass(),
};
辅助性功能
  • 【IsReadOnly】在检查器中不可修改
  • 【HideToolbar】隐藏翻页等工具
  • 【CellPadding】每个Item及属性的间隔
  • 【ScrollViewHeight】固定滚动条高度
  • 【MinScrollViewHeight】最小滚动条高度
  • 【MaxScrollViewHeight】最大滚动条高度




完整示例代码
using Sirenix.OdinInspector;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;


public class TableListAttributeExample : MonoBehaviour
{
    [TableList(ShowIndexLabels = true)]
    public List<SomeCustomClass> TableListWithIndexLabels = new List<SomeCustomClass>()
{
    new SomeCustomClass(),
    new SomeCustomClass(),
};

    [TableList(DrawScrollView = true, MaxScrollViewHeight = 200, MinScrollViewHeight = 100)]
    public List<SomeCustomClass> MinMaxScrollViewTable = new List<SomeCustomClass>()
{
    new SomeCustomClass(),
    new SomeCustomClass(),
};

    [TableList(DrawScrollView = false)]
    public List<SomeCustomClass> AlwaysExpandedTable = new List<SomeCustomClass>()
{
    new SomeCustomClass(),
    new SomeCustomClass(),
};

    [TableList(ShowPaging = true, DrawScrollView = false)]
    public List<SomeCustomClass> TableWithPaging = new List<SomeCustomClass>()
{
    new SomeCustomClass(),
    new SomeCustomClass(),
    new SomeCustomClass(),
    new SomeCustomClass(),
    new SomeCustomClass(),
    new SomeCustomClass(),
    new SomeCustomClass(),
};

    [Serializable]
    public class SomeCustomClass
    {
        [TableColumnWidth(57, Resizable = false)]
        [PreviewField(Alignment = ObjectFieldAlignment.Center)]
        public Texture Icon;

        [TextArea]
        public string Description = ExampleHelper.GetString();

        [VerticalGroup("Combined Column"), LabelWidth(22)]
        public string A, B, C;

        [TableColumnWidth(60)]
        [Button, VerticalGroup("Actions")]
        public void Test1() { }

        [TableColumnWidth(60)]
        [Button, VerticalGroup("Actions")]
        public void Test2() { }
    }
}

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

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值