Class LayoutGroup
Inherited Members
Namespace: UnityEngine.UI
Syntax
[DisallowMultipleComponent]
[ExecuteAlways]
[RequireComponent(typeof(RectTransform))]
public abstract class LayoutGroup : UIBehaviour, ILayoutElement, ILayoutGroup, ILayoutController
Constructors
LayoutGroup()
Declaration
protected LayoutGroup()
Fields
m_ChildAlignment
Declaration
[SerializeField]
protected TextAnchor m_ChildAlignment
Field Value
| Type | Description |
|---|---|
| TextAnchor |
m_Padding
Declaration
[SerializeField]
protected RectOffset m_Padding
Field Value
| Type | Description |
|---|---|
| RectOffset |
m_Tracker
Declaration
protected DrivenRectTransformTracker m_Tracker
Field Value
| Type | Description |
|---|---|
| DrivenRectTransformTracker |
Properties
childAlignment
The alignment to use for the child layout elements in the layout group.
Declaration
public TextAnchor childAlignment { get; set; }
Property Value
| Type | Description |
|---|---|
| TextAnchor |
Remarks
If a layout element does not specify a flexible width or height, its child elements many not use the available space within the layout group. In this case, use the alignment settings to specify how to align child elements within their layout group.
flexibleHeight
See LayoutElement.flexibleHeight
Declaration
public virtual float flexibleHeight { get; }
Property Value
| Type | Description |
|---|---|
| Single |
Implements
flexibleWidth
See LayoutElement.flexibleWidth
Declaration
public virtual float flexibleWidth { get; }
Property Value
| Type | Description |
|---|---|
| Single |
Implements
layoutPriority
See LayoutElement.layoutPriority
Declaration
public virtual int layoutPriority { get; }
Property Value
| Type | Description |
|---|---|
| Int32 |
Implements
minHeight
See LayoutElement.minHeight
Declaration
public virtual float minHeight { get; }
Property Value
| Type | Description |
|---|---|
| Single |
Implements
minWidth
See LayoutElement.minWidth
Declaration
public virtual float minWidth { get; }
Property Value
| Type | Description |
|---|---|
| Single |
Implements
padding
The padding to add around the child layout elements.
Declaration
public RectOffset padding { get; set; }
Property Value
| Type | Description |
|---|---|
| RectOffset |
preferredHeight
See LayoutElement.preferredHeight
Declaration
public virtual float preferredHeight { get; }
Property Value
| Type | Description |
|---|---|
| Single |
Implements
preferredWidth
See LayoutElement.preferredWidth
Declaration
public virtual float preferredWidth { get; }
Property Value
| Type | Description |
|---|---|
| Single |
Implements
rectChildren
Declaration
protected List<RectTransform> rectChildren { get; }
Property Value
| Type | Description |
|---|---|
| List<RectTransform> |
rectTransform
Declaration
protected RectTransform rectTransform { get; }
Property Value
| Type | Description |
|---|---|
| RectTransform |
Methods
CalculateLayoutInputHorizontal()
Declaration
public virtual void CalculateLayoutInputHorizontal()
Implements
CalculateLayoutInputVertical()
Declaration
public abstract void CalculateLayoutInputVertical()
Implements
GetAlignmentOnAxis(Int32)
Returns the alignment on the specified axis as a fraction where 0 is left/top, 0.5 is middle, and 1 is right/bottom.
Declaration
protected float GetAlignmentOnAxis(int axis)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | axis | The axis to get alignment along. 0 is horizontal and 1 is vertical. |
Returns
| Type | Description |
|---|---|
| Single | The alignment as a fraction where 0 is left/top, 0.5 is middle, and 1 is right/bottom. |
GetStartOffset(Int32, Single)
Returns the calculated position of the first child layout element along the given axis.
Declaration
protected float GetStartOffset(int axis, float requiredSpaceWithoutPadding)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | axis | The axis index. 0 is horizontal and 1 is vertical. |
| Single | requiredSpaceWithoutPadding | The total space required on the given axis for all the layout elements including spacing and excluding padding. |
Returns
| Type | Description |
|---|---|
| Single | The position of the first child along the given axis. |
GetTotalFlexibleSize(Int32)
The flexible size for the layout group on the given axis.
Declaration
protected float GetTotalFlexibleSize(int axis)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | axis | The axis index. 0 is horizontal and 1 is vertical. |
Returns
| Type | Description |
|---|---|
| Single | The flexible size |
GetTotalMinSize(Int32)
The min size for the layout group on the given axis.
Declaration
protected float GetTotalMinSize(int axis)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | axis | The axis index. 0 is horizontal and 1 is vertical. |
Returns
| Type | Description |
|---|---|
| Single | The min size |
GetTotalPreferredSize(Int32)
The preferred size for the layout group on the given axis.
Declaration
protected float GetTotalPreferredSize(int axis)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | axis | The axis index. 0 is horizontal and 1 is vertical. |
Returns
| Type | Description |
|---|---|
| Single | The preferred size. |
OnDidApplyAnimationProperties()
Callback for when properties have been changed by animation.
Declaration
protected override void OnDidApplyAnimationProperties()
Overrides
OnDisable()
Declaration
protected override void OnDisable()
Overrides
OnEnable()
Declaration
protected override void OnEnable()
Overrides
OnRectTransformDimensionsChange()
Declaration
protected override void OnRectTransformDimensionsChange()
Overrides
OnTransformChildrenChanged()
Declaration
protected virtual void OnTransformChildrenChanged()
SetChildAlongAxis(RectTransform, Int32, Single)
Set the position and size of a child layout element along the given axis.
Declaration
protected void SetChildAlongAxis(RectTransform rect, int axis, float pos)
Parameters
| Type | Name | Description |
|---|---|---|
| RectTransform | rect | The RectTransform of the child layout element. |
| Int32 | axis | The axis to set the position and size along. 0 is horizontal and 1 is vertical. |
| Single | pos | The position from the left side or top. |
SetChildAlongAxis(RectTransform, Int32, Single, Single)
Set the position and size of a child layout element along the given axis.
Declaration
protected void SetChildAlongAxis(RectTransform rect, int axis, float pos, float size)
Parameters
| Type | Name | Description |
|---|---|---|
| RectTransform | rect | The RectTransform of the child layout element. |
| Int32 | axis | The axis to set the position and size along. 0 is horizontal and 1 is vertical. |
| Single | pos | The position from the left side or top. |
| Single | size | The size. |
SetChildAlongAxisWithScale(RectTransform, Int32, Single, Single)
Set the position and size of a child layout element along the given axis.
Declaration
protected void SetChildAlongAxisWithScale(RectTransform rect, int axis, float pos, float scaleFactor)
Parameters
| Type | Name | Description |
|---|---|---|
| RectTransform | rect | The RectTransform of the child layout element. |
| Int32 | axis | The axis to set the position and size along. 0 is horizontal and 1 is vertical. |
| Single | pos | The position from the left side or top. |
| Single | scaleFactor |
SetChildAlongAxisWithScale(RectTransform, Int32, Single, Single, Single)
Set the position and size of a child layout element along the given axis.
Declaration
protected void SetChildAlongAxisWithScale(RectTransform rect, int axis, float pos, float size, float scaleFactor)
Parameters
| Type | Name | Description |
|---|---|---|
| RectTransform | rect | The RectTransform of the child layout element. |
| Int32 | axis | The axis to set the position and size along. 0 is horizontal and 1 is vertical. |
| Single | pos | The position from the left side or top. |
| Single | size | The size. |
| Single | scaleFactor |
SetDirty()
Mark the LayoutGroup as dirty.
Declaration
protected void SetDirty()
SetLayoutHorizontal()
Declaration
public abstract void SetLayoutHorizontal()
Implements
SetLayoutInputForAxis(Single, Single, Single, Int32)
Used to set the calculated layout properties for the given axis.
Declaration
protected void SetLayoutInputForAxis(float totalMin, float totalPreferred, float totalFlexible, int axis)
Parameters
| Type | Name | Description |
|---|---|---|
| Single | totalMin | The min size for the layout group. |
| Single | totalPreferred | The preferred size for the layout group. |
| Single | totalFlexible | The flexible size for the layout group. |
| Int32 | axis | The axis to set sizes for. 0 is horizontal and 1 is vertical. |
SetLayoutVertical()
Declaration
public abstract void SetLayoutVertical()
Implements
SetProperty<T>(ref T, T)
Helper method used to set a given property if it has changed.
Declaration
protected void SetProperty<T>(ref T currentValue, T newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| T | currentValue | A reference to the member value. |
| T | newValue | The new value. |
Type Parameters
| Name | Description |
|---|---|
| T |