Table List Attribute特性:用于在檢查器中將列表和數組呈現為表。
【ShowIndexLabels】設置為True,則為每個元素繪制一個標簽,其中顯示元素的索引。
[TableList(ShowIndexLabels = true)]
public List<SomeCustomClass> TableListWithIndexLabels = new List<SomeCustomClass>()
{
new SomeCustomClass(),
new SomeCustomClass(),
};
【DrawScrollView 】為True,為table添加一個滾動條,并設置滾動條最大高度(MaxScrollViewHeight )和最小高度(MinScrollViewHeight )
[TableList(DrawScrollView = true, MaxScrollViewHeight = 200, MinScrollViewHeight = 100)]
public List<SomeCustomClass> MinMaxScrollViewTable = new List<SomeCustomClass>()
{
new SomeCustomClass(),
new SomeCustomClass(),
};
【ShowPaging】設置為True,則繪制一個翻頁的選項 【NumberOfItemsPerPage】則設置每個分頁含有的Item數量,默認15個
[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() { }
}
}