Table Matrix Attribute特性:用于進一步指定Odin應如何繪制二維數組欧募。
這也是提高滿滿逼格的特性
官方示例展示
工程示例
【TableMatrix】HorizontalTitle:提供一個橫向的標題 VerticalTitle :提供一個縱向的標題 SquareCells:為True院仿,則其他的cell的寬高將于第一個cell的寬度相等
[ShowInInspector]
[TableMatrix(HorizontalTitle = "橫向方形矩陣標題",VerticalTitle = "縱向方形矩陣標題", SquareCells = true)] //SquareCells 為True,則其他的cell的寬高將于第一個cell的寬度相等
public Texture2D[,] SquareCelledMatrix = new Texture2D[8, 4]
{
{ null, null, null, null },
{ null, null, null, null },
{ null, null, null, null },
{ null, null, null, null },
{ null, null, null, null },
{ null, null, null, null },
{ null, null, null, null },
{ null, null, null,null },
};
[PropertySpace(40)]
[ShowInInspector]
[TableMatrix(SquareCells = true)]
public Mesh[,] PrefabMatrix = new Mesh[8, 4]
{
{ null, null, null, null },
{ null, null, null, null },
{ null, null, null, null },
{ null, null, null, null },
{ null, null, null, null },
{ null, null, null, null },
{ null, null, null, null },
{ null, null, null, null },
};
【IsReadOnly 】為true,則不能調整矩陣的順序
[PropertySpace(40)]
[ShowInInspector]
[TableMatrix(HorizontalTitle = "只讀矩陣", IsReadOnly = true)]//IsReadOnly 不可更改矩陣的順序
public int[,] ReadOnlyMatrix = new int[5, 5];
【Transpose】作用起到一個順序調到的效果
[PropertySpace(40)]
[ShowInInspector, DoNotDrawAsReference]
[TableMatrix(HorizontalTitle = "Transposed Custom Cell Drawing", DrawElementMethod = "DrawColoredEnumElement", ResizableColumns = true, RowHeight = 16, Transpose = true)]//Transpose順序顛倒
public bool[,] Transposed { get { return CustomCellDrawing; } set { CustomCellDrawing = value; } }
private static bool DrawColoredEnumElement(Rect rect, bool value)
{
if (Event.current.type == EventType.MouseDown && rect.Contains(Event.current.mousePosition))
{
value = !value;
GUI.changed = true;
Event.current.Use();
}
UnityEditor.EditorGUI.DrawRect(rect.Padding(1), value ? new Color(0.1f, 0.8f, 0.2f) : new Color(0, 0, 0, 0.5f));
return value;
}
其他輔助效果 ResizableColumns:是否可以通過鼠標調整列的寬度 RowHeight:固定行高度
完整示例代碼
using Sirenix.OdinInspector;
using Sirenix.Utilities;
using UnityEngine;
public class TableMatrixAttributeExample : MonoBehaviour
{
[ShowInInspector]
[TableMatrix(HorizontalTitle = "橫向方形矩陣標題",VerticalTitle = "縱向方形矩陣標題", SquareCells = true)] //SquareCells 為True,則其他的cell的寬高將于第一個cell的寬度相等
public Texture2D[,] SquareCelledMatrix = new Texture2D[8, 4]
{
{ null, null, null, null },
{ null, null, null, null },
{ null, null, null, null },
{ null, null, null, null },
{ null, null, null, null },
{ null, null, null, null },
{ null, null, null, null },
{ null, null, null,null },
};
[PropertySpace(40)]
[ShowInInspector]
[TableMatrix(SquareCells = true)]
public Mesh[,] PrefabMatrix = new Mesh[8, 4]
{
{ null, null, null, null },
{ null, null, null, null },
{ null, null, null, null },
{ null, null, null, null },
{ null, null, null, null },
{ null, null, null, null },
{ null, null, null, null },
{ null, null, null, null },
};
[PropertySpace(40)]
[ShowInInspector]
[TableMatrix(HorizontalTitle = "只讀矩陣", IsReadOnly = true)]//IsReadOnly 不可更改矩陣的順序
public int[,] ReadOnlyMatrix = new int[5, 5];
[PropertySpace(40)]
[ShowInInspector]
[TableMatrix(HorizontalTitle = "橫向標題", VerticalTitle = "縱向標題")]
public InfoMessageType[,] LabledMatrix = new InfoMessageType[6, 6];
[PropertySpace(40)]
[ShowInInspector]
[TableMatrix(HorizontalTitle = "Custom Cell Drawing", DrawElementMethod = "DrawColoredEnumElement", ResizableColumns = false, RowHeight = 40)]
public bool[,] CustomCellDrawing;
[PropertySpace(40)]
[ShowInInspector, DoNotDrawAsReference]
[TableMatrix(HorizontalTitle = "Transposed Custom Cell Drawing", DrawElementMethod = "DrawColoredEnumElement", ResizableColumns = true, RowHeight = 16, Transpose = true)]//Transpose順序顛倒
public bool[,] Transposed { get { return CustomCellDrawing; } set { CustomCellDrawing = value; } }
private static bool DrawColoredEnumElement(Rect rect, bool value)
{
if (Event.current.type == EventType.MouseDown && rect.Contains(Event.current.mousePosition))
{
value = !value;
GUI.changed = true;
Event.current.Use();
}
UnityEditor.EditorGUI.DrawRect(rect.Padding(1), value ? new Color(0.1f, 0.8f, 0.2f) : new Color(0, 0, 0, 0.5f));
return value;
}
}