HorizontalLayoutGroup:继承自HorizontalOrVerticalLayoutGroup,HorizontalOrVerticalLayoutGroup继承自LayoutGroup,是水平布局组件。会受到LayoutElement组件的影响。

源码解析

UGUI源码解析——LayoutGroup

CalculateLayoutInputHorizontal:由布局系统调用。也请参见ILayoutElement。

1
2
3
4
5
6
// 实现了计算并设置m_TotalMinSize、m_TotalPreferredSize、m_TotalFlexibleSize属性值,调用了基类LayoutGroup中的SetLayoutInputForAxis方法
public override void CalculateLayoutInputHorizontal()
{
base.CalculateLayoutInputHorizontal();
CalcAlongAxis(0, false);
}

CalculateLayoutInputVertical:

1
2
3
4
public override void CalculateLayoutInputVertical()
{
CalcAlongAxis(1, false);
}

SetLayoutHorizontal:实现了设置子物体的位置和大小,调用了基类LayoutGroup中的SetChildAlongAxisWithScale或SetChildAlongAxis方法

1
2
3
4
public override void SetLayoutHorizontal()
{
SetChildrenAlongAxis(0, false);
}

SetLayoutHorizontal:实现了设置子物体的位置和大小,调用了基类LayoutGroup中的SetChildAlongAxisWithScale或SetChildAlongAxis方法

1
2
3
4
public override void SetLayoutVertical()
{
SetChildrenAlongAxis(1, false);
}