博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Odin Inspector 系列教程 --- Table Matrix Attribute
阅读量:4147 次
发布时间:2019-05-25

本文共 4501 字,大约阅读时间需要 15 分钟。

Table Matrix Attribute特性:用于进一步指定Odin应如何绘制二维数组。

这也是提高满满逼格的特性

官方示例展示
7643202-4e6f660304d7c0b5.gif
7643202-ac1f15a995142af4.gif

工程示例
7643202-aa2775cd599abe06.gif
【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,则不能调整矩阵的顺序
7643202-735253bd09b252d8.gif
[PropertySpace(40)]    [ShowInInspector]    [TableMatrix(HorizontalTitle = "只读矩阵", IsReadOnly = true)]//IsReadOnly 不可更改矩阵的顺序    public int[,] ReadOnlyMatrix = new int[5, 5];
【Transpose】作用起到一个顺序调到的效果
7643202-450398dcc208a268.gif
[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:固定行高度
7643202-b534a55e65de8c7f.gif
完整示例代码
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;    }}

更多教程内容详见:

转载地址:http://oijti.baihongyu.com/

你可能感兴趣的文章
Qt札记
查看>>
我的vimrc和gvimrc配置
查看>>
hdu 4280
查看>>
禁止使用类的copy构造函数和赋值操作符
查看>>
C++学习路线
查看>>
私有构造函数
查看>>
组队总结
查看>>
TitledBorder 设置JPanel边框
查看>>
DBCP——开源组件 的使用
查看>>
抓包工具
查看>>
海量数据相似度计算之simhash和海明距离
查看>>
DeepLearning tutorial(5)CNN卷积神经网络应用于人脸识别(详细流程+代码实现)
查看>>
DeepLearning tutorial(6)易用的深度学习框架Keras简介
查看>>
DeepLearning tutorial(7)深度学习框架Keras的使用-进阶
查看>>
流形学习-高维数据的降维与可视化
查看>>
Python-OpenCV人脸检测(代码)
查看>>
python+opencv之视频人脸识别
查看>>
人脸识别(OpenCV+Python)
查看>>
6个强大的AngularJS扩展应用
查看>>
网站用户登录系统设计——jsGen实现版
查看>>