Class UnityUiUtils
Helpers for Unity UI (uGUI) operations
Inherited Members
Namespace: Serenity.Global.Infrastructure.Utils
Assembly: Serenity.UnityGlobal.Infrastructure.dll
Syntax
public static class UnityUiUtils
Methods
CalculateBoundingRect(RectTransform[])
Declaration
public static RectTransform CalculateBoundingRect(RectTransform[] rectTransforms)
Parameters
| Type | Name | Description |
|---|---|---|
| RectTransform[] | rectTransforms |
Returns
| Type | Description |
|---|---|
| RectTransform |
IsStretchedX(RectTransform)
Declaration
public static bool IsStretchedX(RectTransform rt)
Parameters
| Type | Name | Description |
|---|---|---|
| RectTransform | rt |
Returns
| Type | Description |
|---|---|
| bool |
IsStretchedY(RectTransform)
Declaration
public static bool IsStretchedY(RectTransform rt)
Parameters
| Type | Name | Description |
|---|---|---|
| RectTransform | rt |
Returns
| Type | Description |
|---|---|
| bool |
MeasureStackedRowExtent(RectTransform, int, float)
Measures how tall the first rowCount visible rows of a stacked container are,
including the layout group's spacing and vertical padding.
Declaration
public static float MeasureStackedRowExtent(RectTransform container, int rowCount, float fallbackSpacing)
Parameters
| Type | Name | Description |
|---|---|---|
| RectTransform | container | The container whose children are measured. |
| int | rowCount | How many rows to include. |
| float | fallbackSpacing | Spacing used when the container carries no layout group. |
Returns
| Type | Description |
|---|---|
| float | The measured height, or 0 when there is nothing to measure. |
Remarks
Only active children count: a pooled list keeps its surplus rows alive but deactivated, and measuring those would clamp the viewport to a height the player never sees filled.
PinScrollViewportHeight(ScrollRect, float)
Pins a scroll viewport to a fixed height so its layout parent cannot stretch it back open.
Declaration
public static void PinScrollViewportHeight(ScrollRect scrollRect, float height)
Parameters
| Type | Name | Description |
|---|---|---|
| ScrollRect | scrollRect | The viewport's ScrollRect. |
| float | height | The height to pin, in pixels. Ignored when not positive. |
SafeSetHeight(RectTransform, float)
Declaration
public static void SafeSetHeight(RectTransform rt, float height)
Parameters
| Type | Name | Description |
|---|---|---|
| RectTransform | rt | |
| float | height |
SafeSetWidth(RectTransform, float)
Declaration
public static void SafeSetWidth(RectTransform rt, float width)
Parameters
| Type | Name | Description |
|---|---|---|
| RectTransform | rt | |
| float | width |
WaitForComponent<T>(MonoBehaviour, GameObject, Action<T>, float)
Declaration
public static IEnumerator WaitForComponent<T>(MonoBehaviour context, GameObject root, Action<T> onFound, float timeout = 2) where T : Component
Parameters
| Type | Name | Description |
|---|---|---|
| MonoBehaviour | context | |
| GameObject | root | |
| Action<T> | onFound | |
| float | timeout |
Returns
| Type | Description |
|---|---|
| IEnumerator |
Type Parameters
| Name | Description |
|---|---|
| T |
WrapInVerticalScrollViewport(RectTransform, string)
Wraps a vertically stacked container in a masked, clamped UnityEngine.UI.ScrollRect viewport, so a list that outgrows its panel scrolls instead of spilling off-screen.
Declaration
public static ScrollRect WrapInVerticalScrollViewport(RectTransform content, string viewportName)
Parameters
| Type | Name | Description |
|---|---|---|
| RectTransform | content | The container holding the rows. Must already have a parent. |
| string | viewportName | Name given to the created viewport object. |
Returns
| Type | Description |
|---|---|
| ScrollRect | The configured ScrollRect, or |
Remarks
The container is reparented under a new viewport object that takes its place in the parent's layout, keeping the sibling order the panel authored. A UnityEngine.UI.ContentSizeFitter is added to the container when it has none, because a ScrollRect's content must size itself for the scrollable extent to be known at all.
Shared by every panel that renders a growable row list — the leaderboard's ranked entries and the achievements listing — because the viewport wiring is one piece of knowledge, and two hand-written copies drift into two different scroll behaviours.