Class UnityUiAnchorUtils
Thin Unity adapter over UiAnchorMapper: turns the pure anchor factors into the UnityEngine.Vector2 pivots and offsets uGUI consumes.
Inherited Members
Namespace: Serenity.Ui.Infrastructure.Views
Assembly: Serenity.UnityUi.Infrastructure.dll
Syntax
public static class UnityUiAnchorUtils
Remarks
Lives in the Ui infrastructure rather than the Menu one so that anything screen-anchored — menus, the HUD, future overlays — shares a single conversion instead of each re-deriving the nine-case mapping.
Methods
ApplyAnchoredPlacement(RectTransform, UiAnchorType, Vector2)
Anchors a RectTransform to a corner or edge of its parent and places it there, so the element keeps its screen position at every resolution.
Declaration
public static void ApplyAnchoredPlacement(RectTransform rectTransform, UiAnchorType alignment, Vector2 offset)
Parameters
| Type | Name | Description |
|---|---|---|
| RectTransform | rectTransform | The transform to place. |
| UiAnchorType | alignment | The corner or edge to anchor to. |
| Vector2 | offset | The nudge from that anchor, with positive X right and positive Y up regardless of the corner. |
GetAnchorBasedPosition(UiAnchorType, Vector2)
Converts a margin into the anchored position that pushes an element inwards from its anchor.
Declaration
public static Vector2 GetAnchorBasedPosition(UiAnchorType alignment, Vector2 borderMargin)
Parameters
| Type | Name | Description |
|---|---|---|
| UiAnchorType | alignment | The nine-way anchor. |
| Vector2 | borderMargin | The margin to apply, as a positive distance. |
Returns
| Type | Description |
|---|---|
| Vector2 | The anchored position. |
GetAnchorPivotForAlignment(UiAnchorType)
Returns the anchor/pivot point for an alignment, in uGUI's 0..1 space.
Declaration
public static Vector2 GetAnchorPivotForAlignment(UiAnchorType alignment)
Parameters
| Type | Name | Description |
|---|---|---|
| UiAnchorType | alignment | The nine-way anchor. |
Returns
| Type | Description |
|---|---|
| Vector2 | The matching anchor-min/anchor-max/pivot point. |