UGUI之Grid Layout Group组件介绍

Grid Layout Group是LayoutGroup的子类

脚本属性截图如下:

UGUI之Grid Layout Group组件介绍_第1张图片

1、Padding:RectOffset类型,矩形偏移,详解请戳UGUI之Horizontal Layout Group组件介绍

2、Cell Size:Vector2类型,默认值为(100,100),网格中的每个单元格的大小

[SerializeField]protectedVector2 m_CellSize =newVector2(100,100);publicVector2 cellSize {get{returnm_CellSize; }set{ SetProperty(refm_CellSize,value); } }

Spacing:这里的Spacing不同于水平布局、垂直布局,是Vector2类型,既然是网格布局,当然存在水平方向的间隔和垂直方向的间隔,这里也不做过多的介绍。

3、Start Corner:Corner枚举类型

publicenumCorner {    UpperLeft =0,//左上角UpperRight =1,//右上角LowerLeft =2,//左下角LowerRight =3//右下角}

第一个单元格放在哪个角落,默认为UpperLeft左上角

4、Start Axis:Axis枚举类型

publicenumAxis {    Horizontal =0,//水平Vertical =1//垂直}


(1)Horizontal:水平

优先水平排列单元格

(2)Vertical:垂直

优先垂直排列单元格

5、Child Alignment:TextAnchor枚举类型,文本锚点,详解请戳UGUI之Horizontal Layout Group组件介绍

6、Constraint:Constraint枚举类型

publicenumConstraint {    Flexible =0,//不限制行数和列数FixedColumnCount =1,//约束指定数量的列数FixedRowCount =2//约束指定数量的行数}

下面以几个截图来看看上面几个设置具体是怎样的作用:

以下单元格物体加了一个Text来表示其编号,并且Hierarchy面板中的层级关系并未调整

图一:默认情况

UGUI之Grid Layout Group组件介绍_第2张图片

图二:设置Start Corner为Upper Right

UGUI之Grid Layout Group组件介绍_第3张图片

图三:设置Start Axis为Vertical

UGUI之Grid Layout Group组件介绍_第4张图片

图四:设置Start Corner为Lower Left、Start Axis为Vertical

UGUI之Grid Layout Group组件介绍_第5张图片

从以上图中不难看出这两个设置的使用用途。

实际开发中,我常与Content Size Fitter组件一起使用

UGUI之Grid Layout Group组件介绍_第6张图片

你可能感兴趣的:(UGUI之Grid Layout Group组件介绍)