TableMatrixAttribute

The TableMatrix attribute is used to further specify how Odin should draw two-dimensional arrays.

namespace Sirenix.OdinInspector
{
[AttributeUsageAttribute((AttributeTargets)384, AllowMultiple = False)]
public class TableMatrixAttribute : Attribute
}

Requirements

Namespace: Sirenix.OdinInspector
Assembly: Sirenix.OdinInspector
Version: 1.0.6.1

Fields

Return Type Definition Description
string DrawElementMethod Override how Odin draws each cell.

[TableMatrix(DrawElementMethod='DrawMyElement')]

public MyType[,] myArray;

private static MyType DrawElement(Rect rect, MyType value) { return GUI.DrawMyType(rect, value); }
bool HideColumnIndices If true, no column indices drawn.
bool HideRowIndices If true, no row indices drawn.
string HorizontalTitle The horizontal title label.
bool IsReadOnly If true, inserting, removing and dragging columns and rows will become unavailable. But the cells themselves will remain modifiable. If you want to disable everything, you can use the !:ReadOnly attribute.
bool ResizableColumns Whether or not columns are resizable.
int RowHeight The height for all rows. 0 = default row height.
bool SquareCells If true, the height of each row will be the same as the width of the first cell.
string VerticalTitle The vertical title label.

Example

// Inheriting from SerializedMonoBehaviour is only needed if you want Odin to serialize the multi-dimensional arrays for you.
// If you prefer doing that yourself, you can still make Odin show them in the inspector using the ShowInInspector attribute.
public class TableMatrixExamples : SerializedMonoBehaviour
{
    [InfoBox("Right-click and drag column and row labels in order to modify the tables."), PropertyOrder(-10), OnInspectorGUI]
    private void ShowMessageAtOP() { }

    [BoxGroup("Two Dimensional array without the TableMatrix attribute.")]
    public bool[,] BooleanTable = new bool[15, 6];

    [BoxGroup("ReadOnly table")]
    [TableMatrix(IsReadOnly = true)]
    public int[,] ReadOnlyTable = new int[5, 5];

    [BoxGroup("Labled table")]
    [TableMatrix(HorizontalTitle = "X axis", VerticalTitle = "Y axis")]
    public GameObject[,] LabledTable = new GameObject[15, 10];

    [BoxGroup("Enum table")]
    [TableMatrix(HorizontalTitle = "X axis")]
    public InfoMessageType[,] EnumTable = new InfoMessageType[4,4];

    [BoxGroup("Custom table")]
    [TableMatrix(DrawElementMethod = "DrawColoredEnumElement", ResizableColumns = false)]
    public bool[,] CustomCellDrawing = new bool[30,30];

    #if UNITY_EDITOR

        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;
        }

    #endif
}