Class AspectRatioFitter
Resizes a RectTransform to fit a specified aspect ratio.
Inherited Members
Namespace: UnityEngine.UI
Assembly: UnityEngine.UI.dll
Syntax
[AddComponentMenu("Layout/Aspect Ratio Fitter", 142)]
[ExecuteAlways]
[RequireComponent(typeof(RectTransform))]
[DisallowMultipleComponent]
public class AspectRatioFitter : UIBehaviour, ILayoutSelfController, ILayoutController
Constructors
AspectRatioFitter()
Protected default constructor. Use UnityEngine.GameObject.AddComponent<T>() to add an AspectRatioFitter to a GameObject.
Declaration
protected AspectRatioFitter()
Properties
aspectMode
The mode to use to enforce the aspect ratio.
Declaration
public AspectRatioFitter.AspectMode aspectMode { get; set; }
Property Value
| Type | Description |
|---|---|
| AspectRatioFitter.AspectMode |
aspectRatio
The aspect ratio to enforce. This means width divided by height.
Declaration
public float aspectRatio { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
Methods
IsAspectModeValid()
Returns whether the current aspect mode is valid for this object.
Declaration
public bool IsAspectModeValid()
Returns
| Type | Description |
|---|---|
| bool | True if valid. |
IsComponentValidOnObject()
Returns whether this component is valid on the current object (not valid on a root Canvas).
Declaration
public bool IsComponentValidOnObject()
Returns
| Type | Description |
|---|---|
| bool | True if valid. |
OnDisable()
Called when it becomes disabled. Removes aspect-ratio sizing constraints.
Declaration
protected override void OnDisable()
Overrides
OnEnable()
Called when it becomes enabled. Applies the aspect ratio constraint to the RectTransform.
Declaration
protected override void OnEnable()
Overrides
OnRectTransformDimensionsChange()
Function called when this RectTransform or parent RectTransform has changed dimensions.
Declaration
protected override void OnRectTransformDimensionsChange()
Overrides
OnTransformParentChanged()
Called when the parent transform changes. Applies the aspect ratio constraint to the RectTransform.
Declaration
protected override void OnTransformParentChanged()
Overrides
OnValidate()
Declaration
protected override void OnValidate()
Overrides
SetDirty()
Mark the AspectRatioFitter as dirty.
Declaration
protected void SetDirty()
SetLayoutHorizontal()
Method called by the layout system. Has no effect
Declaration
public virtual void SetLayoutHorizontal()
SetLayoutVertical()
Method called by the layout system. Has no effect
Declaration
public virtual void SetLayoutVertical()
Start()
Checks if the object setup is supported and the AspectMode is valid.
Declaration
protected override void Start()
Overrides
Update()
Update the rect based on the delayed dirty. Got around issue of calling onValidate from OnEnable function.
Declaration
protected virtual void Update()