Odin Attributes 大全之 Type Specifics 系列 | (14)Table Matrix 特性

📂 Unity常用插件 | 总目录

📂 Unity 3D资源 | 目录索引

Odin Attributes 为Unity开发者提供了更多的自定义选项,使得开发过程更加高效和愉悦。通过使用这些特性,开发者可以创建更加专业和用户友好的编辑器界面,从而提升整个开发团队的工作效率。

在这里插入图片描述

【Odin Inspector and Serializer 最新版 (0积分)免费下载


Table Matrix 特性用于进一步指定Odin应如何绘制二维数组。这也是提高满满逼格的特性。

示例展示

在这里插入图片描述

1.【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 },
    };

在这里插入图片描述

2.【IsReadOnly 】为true,则不能调整矩阵的顺序

    [PropertySpace(40)]
    [ShowInInspector]
    [TableMatrix(HorizontalTitle = "只读矩阵", IsReadOnly = true)]//IsReadOnly 不可更改矩阵的顺序
    public int[,] ReadOnlyMatrix = new int[5, 5];

在这里插入图片描述

3.【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;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Unity打怪升级

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值