Game Development Reference
In-Depth Information
By default, these settings are used automatically based on the native controls setting
of the
Min
and
Preferred
sizes; however, these can also be overridden by adding a
Layout Element
component manually, to child components to define the
Min
and
Preferred
size of the content.
When you add the
Content Size Fitter
to a GameObject, you get three options per axis:
The options provide the following capabilities:
•
Unconstrained
: Do nothing, the
Content Size Fitter
does not control this axis
•
MinSize
: This lays out the content and restricts the
Rect Transforms
width or
height to the minimum values of the GameObjects content and/or children
•
PreferredSize
: This lays out the content and restricts the
Rect Transforms
width or height to the preferred values of the GameObjects content
and/or children
Using the
Content Size Fitter
becomes especially important when you are working
with content sized to the target platforms resolution and if you have additional
background images/layouts on a parent GameObject or dynamically sized content.
As an example, let's create a text chat window that will automatically grow and
shrink based on the text within it:
1.
Add a Canvas to the scene (
Create
|
UI
|
Canvas
) or use one that you
already have.
2.
Right-click on the
Canvas
and select to
UI
|
Image
- this is our text window
background.
3.
Right-click on the
Image
and select to
UI
|
Text
to add a
child text
component.
Note that the text size now overlaps the
Image
.