Class UnityLayoutBuilder
Translates the engine-agnostic layout model (LayoutConfig / LayoutSize) onto Unity uGUI primitives — UnityEngine.UI.HorizontalLayoutGroup/UnityEngine.UI.VerticalLayoutGroup, UnityEngine.UI.LayoutElement, UnityEngine.UI.ContentSizeFitter and UnityEngine.UI.ScrollRect. This is the single place where CSS-style flexbox semantics become Unity layout components, keeping that mapping out of the domain and out of the composite view.
Implements
Inherited Members
Namespace: Serenity.Ui.Infrastructure.Views
Assembly: Serenity.UnityUi.Infrastructure.dll
Syntax
public class UnityLayoutBuilder : IHostedSizeApplier
Constructors
UnityLayoutBuilder()
Declaration
public UnityLayoutBuilder()
Methods
ApplyChildSize(GameObject, LayoutSize, bool)
Configures the UnityEngine.UI.LayoutElement of child so it occupies
size along its parent container's main axis.
Declaration
public void ApplyChildSize(GameObject child, LayoutSize size, bool parentIsHorizontal)
Parameters
| Type | Name | Description |
|---|---|---|
| GameObject | child | The child GameObject placed inside a container built by this builder. |
| LayoutSize | size | The CSS-style main-axis size for the child. |
| bool | parentIsHorizontal | True when the parent container's main axis is horizontal. |
ApplyHostedAutoSize(GameObject, IHostableView, bool)
Reserves a hosted view's reported content size on its UnityEngine.UI.LayoutElement. An auto-sized hosted view (e.g. a menu) has no content of its own for the layout group to measure, so the size it reports through IHostableView is applied as the preferred size instead. Re-run whenever the hosted view re-measures (it sizes itself over several frames after being shown), since the build-time measurement is stale.
Declaration
public void ApplyHostedAutoSize(GameObject childGameObject, IHostableView hostable, bool parentHorizontal)
Parameters
| Type | Name | Description |
|---|---|---|
| GameObject | childGameObject | The hosted view's GameObject placed inside the container. |
| IHostableView | hostable | The hosted view reporting its preferred content size. |
| bool | parentHorizontal | True when the parent container's main axis is horizontal. |
BuildContainer(GameObject, LayoutConfig, bool, LayoutScrollAxis)
Applies config to host and returns the transform that
children should be parented under. For a non-scrolling container this is the host itself; for
a scrolling container it is the generated scroll content object (the host receives a
UnityEngine.UI.ScrollRect with a masked viewport and a generated scrollbar). Scrolling is a
view-definition-level setting (IScrollableViewDefinition),
so it is passed explicitly rather than read from the layout.
Declaration
public Transform BuildContainer(GameObject host, LayoutConfig config, bool scrollable, LayoutScrollAxis scrollAxis)
Parameters
| Type | Name | Description |
|---|---|---|
| GameObject | host | The container GameObject to configure (must have a RectTransform). |
| LayoutConfig | config | The layout to realize. |
| bool | scrollable | Whether the container scrolls its overflowing content. |
| LayoutScrollAxis | scrollAxis | The axis the container scrolls along when |
Returns
| Type | Description |
|---|---|
| Transform | The transform under which this container's children must be placed. |