Class GridLayoutGroup
Layout class to arrange child elements in a grid format.
Inherited Members
Namespace: UnityEngine.UI
Assembly: UnityEngine.UI.dll
Syntax
[AddComponentMenu("Layout/Grid Layout Group", 152)]
public class GridLayoutGroup : LayoutGroup, ILayoutElement, ILayoutGroup, ILayoutController
Remarks
The GridLayoutGroup component is used to layout child layout elements in a uniform grid where all cells have the same size. The size and the spacing between cells is controlled by the GridLayoutGroup itself. The children have no influence on their sizes.
Constructors
GridLayoutGroup()
Protected default constructor. Use UnityEngine.GameObject.AddComponent<T>() to add a GridLayoutGroup to a GameObject.
Declaration
protected GridLayoutGroup()
Fields
m_CellSize
Serialized backing field for cellSize.
Declaration
[SerializeField]
protected Vector2 m_CellSize
Field Value
| Type | Description |
|---|---|
| Vector2 |
m_Constraint
Serialized backing field for constraint.
Declaration
[SerializeField]
protected GridLayoutGroup.Constraint m_Constraint
Field Value
| Type | Description |
|---|---|
| GridLayoutGroup.Constraint |
m_ConstraintCount
Serialized backing field for constraintCount.
Declaration
[SerializeField]
protected int m_ConstraintCount
Field Value
| Type | Description |
|---|---|
| int |
m_Spacing
Serialized backing field for spacing.
Declaration
[SerializeField]
protected Vector2 m_Spacing
Field Value
| Type | Description |
|---|---|
| Vector2 |
m_StartAxis
Serialized backing field for startAxis.
Declaration
[SerializeField]
protected GridLayoutGroup.Axis m_StartAxis
Field Value
| Type | Description |
|---|---|
| GridLayoutGroup.Axis |
m_StartCorner
Serialized backing field for startCorner.
Declaration
[SerializeField]
protected GridLayoutGroup.Corner m_StartCorner
Field Value
| Type | Description |
|---|---|
| GridLayoutGroup.Corner |
Properties
cellSize
The size to use for each cell in the grid.
Declaration
public Vector2 cellSize { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector2 |
constraint
Which constraint to use for the GridLayoutGroup.
Declaration
public GridLayoutGroup.Constraint constraint { get; set; }
Property Value
| Type | Description |
|---|---|
| GridLayoutGroup.Constraint |
Remarks
Specifying a constraint can make the GridLayoutGroup work better in conjunction with a [[ContentSizeFitter]] component. When GridLayoutGroup is used on a RectTransform with a manually specified size, there's no need to specify a constraint.
constraintCount
How many cells there should be along the constrained axis.
Declaration
public int constraintCount { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
generatedColumnCount
The number of columns that the layout group generates after the layout process is complete.
Declaration
public int generatedColumnCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
Remarks
The layout system sets this value to 0 if there are no child GameObjects participating in layout.
When you set constraint to FixedColumnCount, this value is equal
to the minimum of constraintCount and the number of child GameObjects.
generatedRowCount
The number of rows that the layout group generates after the layout process is complete.
Declaration
public int generatedRowCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
Remarks
The layout system sets this value to 0 if there are no child GameObjects participating in layout.
When you set constraint to FixedRowCount, this value is equal
to the minimum of constraintCount and the number of child GameObjects.
spacing
The spacing to use between layout elements in the grid on both axises.
Declaration
public Vector2 spacing { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector2 |
startAxis
Which axis should cells be placed along first
Declaration
public GridLayoutGroup.Axis startAxis { get; set; }
Property Value
| Type | Description |
|---|---|
| GridLayoutGroup.Axis |
Remarks
When startAxis is set to horizontal, an entire row will be filled out before proceeding to the next row. When set to vertical, an entire column will be filled out before proceeding to the next column.
startCorner
Which corner should the first cell be placed in?
Declaration
public GridLayoutGroup.Corner startCorner { get; set; }
Property Value
| Type | Description |
|---|---|
| GridLayoutGroup.Corner |
Methods
CalculateLayoutInputHorizontal()
Called by the layout system to calculate the horizontal layout size. Also see ILayoutElement
Declaration
public override void CalculateLayoutInputHorizontal()
Overrides
CalculateLayoutInputVertical()
Called by the layout system to calculate the vertical layout size. Also see ILayoutElement
Declaration
public override void CalculateLayoutInputVertical()
Overrides
OnValidate()
Declaration
protected override void OnValidate()
Overrides
SetLayoutHorizontal()
Called by the layout system Also see ILayoutElement
Declaration
public override void SetLayoutHorizontal()
Overrides
SetLayoutVertical()
Called by the layout system Also see ILayoutElement
Declaration
public override void SetLayoutVertical()