Class SafeArea
A component that drives a RectTransform to fit within the device's safe area.
Inherited Members
Namespace: UnityEngine.UI
Assembly: UnityEngine.UI.dll
Syntax
[DisallowMultipleComponent]
[RequireComponent(typeof(RectTransform))]
[AddComponentMenu("UI (Canvas)/Safe Area")]
[ExecuteAlways]
public class SafeArea : UIBehaviour
Remarks
Inset edges, alignment centering, and reference orientation are configurable. Edge and alignment directions are authored in the reference orientation and remapped to the current device orientation at runtime.
Properties
Alignment
Controls which axis to center the rect by equalizing insets on both sides
Declaration
public SafeArea.AlignmentMode Alignment { get; set; }
Property Value
| Type | Description |
|---|---|
| SafeArea.AlignmentMode |
Edges
Controls which edges of the device to inset to respect the safe area
Declaration
public SafeArea.SafeAreaMode Edges { get; set; }
Property Value
| Type | Description |
|---|---|
| SafeArea.SafeAreaMode |
ReferenceOrientation
The reference orientation to determine edges to respect safe area
Declaration
public ScreenOrientation ReferenceOrientation { get; set; }
Property Value
| Type | Description |
|---|---|
| ScreenOrientation |
RespectSafeAreaScreenBottom
Whether this UI component respects (inset to) the safe area on the screen's bottom edge for the current device orientation.
Declaration
public bool RespectSafeAreaScreenBottom { get; }
Property Value
| Type | Description |
|---|---|
| bool |
RespectSafeAreaScreenLeft
Whether this UI component respects (inset to) the safe area on the screen's left edge for the current device orientation.
Declaration
public bool RespectSafeAreaScreenLeft { get; }
Property Value
| Type | Description |
|---|---|
| bool |
RespectSafeAreaScreenRight
Whether this UI component respects (inset to) the safe area on the screen's right edge for the current device orientation.
Declaration
public bool RespectSafeAreaScreenRight { get; }
Property Value
| Type | Description |
|---|---|
| bool |
RespectSafeAreaScreenTop
Whether this UI component respects (inset to) the safe area on the screen's top edge for the current device orientation.
Declaration
public bool RespectSafeAreaScreenTop { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
Awake()
Called when the script instance is loaded. Caches the RectTransform and initializes the driven transform tracker.
Declaration
protected override void Awake()
Overrides
GetReferenceOrientationMappedDirection(SafeAreaMode)
Calculate and return the orientation that any given reference orientation direction is mapped to.
Declaration
public SafeArea.SafeAreaMode GetReferenceOrientationMappedDirection(SafeArea.SafeAreaMode referenceOrientationDirection)
Parameters
| Type | Name | Description |
|---|---|---|
| SafeArea.SafeAreaMode | referenceOrientationDirection | The direction in reference orientation space to map. |
Returns
| Type | Description |
|---|---|
| SafeArea.SafeAreaMode | The direction in screen space for the current device orientation. |
OnDestroy()
Called when the component is destroyed. Clears the RectTransform property tracking.
Declaration
protected override void OnDestroy()
Overrides
OnDisable()
Called when it becomes disabled. Clears the RectTransform property tracking.
Declaration
protected override void OnDisable()
Overrides
OnEnable()
Called when it becomes enabled. Claims driven ownership of the RectTransform and applies the safe area values.
Declaration
protected override void OnEnable()
Overrides
OnValidate()
Called in the editor when the script is loaded or an inspector value changes. Warns about conflicting RectTransform drivers.
Declaration
protected override void OnValidate()