Game Development Reference
In-Depth Information
•
Constraint
: We could all use a little constraint and the
Grid Layout Group
is
no different. If you want to limit the number of rows or columns, the grid
will show that you can set this property to either
Fixed Row Count
or
Fixed Column Count
, which will open up an additional
Constraint
Count
property for you to provide the constrained number. The default
is
Flexible
, which is basically unconstrained.
Unlike the vertical and horizontal groups, which resize the content to
fit the entire layout group area, the
Grid Layout Group
will actually
overflow and draw any additional cells that don't fit in the Group area
below the group, filling up more rows. If you don't want this behavior,
then you will need to either set a
Constraint
, add a
Mask
component
or limit how many child elements you add.
It will still resize the original image, however, to it your defined Cell
sizes by default.
For more details about the Mask component, see the
Mask
section
later in this chapter.
Layout options
The default behavior of the Layout Group components is good for most situations
but for others you want to add a finer level of control. For these situations, Unity has
provided several layout overrides to constraint the use of controls within a group or
as a standalone
UI
element:
•
Layout Element
•
Content Size Fitter
•
Aspect Ratio Fitter
•
Scroll Rects
•
Masks
All of these components can also be used on most
UI
controls as well
as to alter their behavior when presented on the canvas; the layout
groups are just the default use for these controls.