unity中的UGUI一些组件的使用

一、Toggle Group(Script)

LeftButtons上添加Toggle Group组件,属性Allow Switch Off打对勾,代表它的所有子物体上带有Toggle组件的属性Is On是关闭状态。

至此一个按钮组ToggleGroup制作完毕,在这个组下的Toggle只有一个可以被选择。

二、Grid Layout Group组件

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

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

[SerializeField] protected Vector2 m_CellSize = new Vector2(100, 100);
public Vector2 cellSize { get { return m_CellSize; } set { SetProperty(ref m_CellSize, value); } }

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

4、Start Corner:Corner枚举类型

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

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

 5、Start Axis:Axis枚举类型

public enum Axis 
{ 
    Horizontal = 0,     //水平
    Vertical = 1        //垂直
}

(1)Horizontal:水平
优先水平排列单元格
(2)Vertical:垂直
优先垂直排列单元格

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

7、Constraint:Constraint枚举类型

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

猜你喜欢

转载自www.cnblogs.com/Study088/p/8964308.html