private void HandleSelfFittingAlongAxis(int axis) { //获取目标轴的适应类型 FitMode fitting = (axis == 0 ? horizontalFit : verticalFit); if (fitting == FitMode.Unconstrained) { // Keep a reference to the tracked transform, but don't control its properties: m_Tracker.Add(this, rectTransform, DrivenTransformProperties.None); return; } //添加Tracker的部分无法被修改 m_Tracker.Add(this, rectTransform, (axis == 0 ? DrivenTransformProperties.SizeDeltaX : DrivenTransformProperties.SizeDeltaY)); // Set size to min or preferred size //根据类型选择适应的尺寸 if (fitting == FitMode.MinSize) { rectTransform.SetSizeWithCurrentAnchors((RectTransform.Axis)axis, LayoutUtility.GetMinSize(m_Rect, axis)); } else { rectTransform.SetSizeWithCurrentAnchors((RectTransform.Axis)axis, LayoutUtility.GetPreferredSize(m_Rect, axis)); } }
/// <summary> /// /// <para> /// Set the positions and sizes of the child layout elements for the given axis. /// </para> /// /// </summary> /// <param name="axis">The axis to handle. 0 is horizontal and 1 is vertical.</param><param name="isVertical">Is this group a vertical group?</param> protected void SetChildrenAlongAxis(int axis, bool isVertical) { float num1 = this.rectTransform.rect.size[axis]; if (isVertical ^ axis == 1) { float num2 = num1 - (axis != 0 ? (float)this.padding.vertical : (float)this.padding.horizontal); for (int index = 0; index < this.rectChildren.Count; ++index) { RectTransform rect = this.rectChildren[index]; float minSize = LayoutUtility.GetMinSize(rect, axis); float preferredSize = LayoutUtility.GetPreferredSize(rect, axis); float a = LayoutUtility.GetFlexibleSize(rect, axis); if ((axis != 0 ? (this.childForceExpandHeight ? 1 : 0) : (this.childForceExpandWidth ? 1 : 0)) != 0) { a = Mathf.Max(a, 1f); } float num3 = Mathf.Clamp(num2, minSize, (double)a <= 0.0 ? preferredSize : num1); float startOffset = this.GetStartOffset(axis, num3); this.SetChildAlongAxis(rect, axis, startOffset, num3); } } else { float pos = axis != 0 ? (float)this.padding.top : (float)this.padding.left; if ((double)this.GetTotalFlexibleSize(axis) == 0.0 && (double)this.GetTotalPreferredSize(axis) < (double)num1) { pos = this.GetStartOffset(axis, this.GetTotalPreferredSize(axis) - (axis != 0 ? (float)this.padding.vertical : (float)this.padding.horizontal)); } float t = 0.0f; if ((double)this.GetTotalMinSize(axis) != (double)this.GetTotalPreferredSize(axis)) { t = Mathf.Clamp01((float)(((double)num1 - (double)this.GetTotalMinSize(axis)) / ((double)this.GetTotalPreferredSize(axis) - (double)this.GetTotalMinSize(axis)))); } float num2 = 0.0f; if ((double)num1 > (double)this.GetTotalPreferredSize(axis) && (double)this.GetTotalFlexibleSize(axis) > 0.0) { num2 = (num1 - this.GetTotalPreferredSize(axis)) / this.GetTotalFlexibleSize(axis); } for (int index = 0; index < this.rectChildren.Count; ++index) { RectTransform rect = this.rectChildren[index]; float minSize = LayoutUtility.GetMinSize(rect, axis); float preferredSize = LayoutUtility.GetPreferredSize(rect, axis); float a = LayoutUtility.GetFlexibleSize(rect, axis); if ((axis != 0 ? (this.childForceExpandHeight ? 1 : 0) : (this.childForceExpandWidth ? 1 : 0)) != 0) { a = Mathf.Max(a, 1f); } float size = Mathf.Lerp(minSize, preferredSize, t) + a * num2; this.SetChildAlongAxis(rect, axis, pos, size); pos += size + this.spacing; } } }
protected void SetChildrenAlongAxis(int axis, bool isVertical) { float num = base.rectTransform.rect.size[axis]; if (isVertical ^ (axis == 1)) { float num2 = num - ((axis != 0) ? ((float)base.padding.vertical) : ((float)base.padding.horizontal)); for (int i = 0; i < base.rectChildren.Count; i++) { RectTransform rect = base.rectChildren[i]; float minSize = LayoutUtility.GetMinSize(rect, axis); float preferredSize = LayoutUtility.GetPreferredSize(rect, axis); float flexibleSize = LayoutUtility.GetFlexibleSize(rect, axis); if ((axis != 0) ? this.childForceExpandHeight : this.childForceExpandWidth) { flexibleSize = Mathf.Max(flexibleSize, 1f); } float requiredSpaceWithoutPadding = Mathf.Clamp(num2, minSize, (flexibleSize <= 0f) ? preferredSize : num); float startOffset = base.GetStartOffset(axis, requiredSpaceWithoutPadding); base.SetChildAlongAxis(rect, axis, startOffset, requiredSpaceWithoutPadding); } } else { float pos = (axis != 0) ? ((float)base.padding.top) : ((float)base.padding.left); if ((base.GetTotalFlexibleSize(axis) == 0f) && (base.GetTotalPreferredSize(axis) < num)) { pos = base.GetStartOffset(axis, base.GetTotalPreferredSize(axis) - ((axis != 0) ? ((float)base.padding.vertical) : ((float)base.padding.horizontal))); } float t = 0f; if (base.GetTotalMinSize(axis) != base.GetTotalPreferredSize(axis)) { t = Mathf.Clamp01((num - base.GetTotalMinSize(axis)) / (base.GetTotalPreferredSize(axis) - base.GetTotalMinSize(axis))); } float num11 = 0f; if ((num > base.GetTotalPreferredSize(axis)) && (base.GetTotalFlexibleSize(axis) > 0f)) { num11 = (num - base.GetTotalPreferredSize(axis)) / base.GetTotalFlexibleSize(axis); } for (int j = 0; j < base.rectChildren.Count; j++) { RectTransform transform2 = base.rectChildren[j]; float a = LayoutUtility.GetMinSize(transform2, axis); float b = LayoutUtility.GetPreferredSize(transform2, axis); float num15 = LayoutUtility.GetFlexibleSize(transform2, axis); if ((axis != 0) ? this.childForceExpandHeight : this.childForceExpandWidth) { num15 = Mathf.Max(num15, 1f); } float size = Mathf.Lerp(a, b, t) + (num15 * num11); base.SetChildAlongAxis(transform2, axis, pos, size); pos += size + this.spacing; } } }
private void HandleSelfFittingAlongAxis(int axis) { FitMode fitting = (axis == 0 ? horizontalFit : verticalFit); if (fitting == FitMode.Unconstrained) { // Keep a reference to the tracked transform, but don't control its properties: m_Tracker.Add(this, rectTransform, DrivenTransformProperties.None); return; } m_Tracker.Add(this, rectTransform, (axis == 0 ? DrivenTransformProperties.SizeDeltaX : DrivenTransformProperties.SizeDeltaY)); // Set size to min or preferred size if (fitting == FitMode.MinSize) { rectTransform.SetSizeWithCurrentAnchors((RectTransform.Axis)axis, LayoutUtility.GetMinSize(m_Rect, axis)); } else { float toBeSize = LayoutUtility.GetPreferredSize(m_Rect, axis); var p = m_Rect.parent as RectTransform; if (!ReferenceEquals(p, null)) { if (axis == 0 && m_HorizontalConstrainToParentSize) { toBeSize = Mathf.Clamp(toBeSize, 0, p.rect.size.x); } if (axis == 1) { if (m_VerticalConstrainToParentSize) { toBeSize = Mathf.Clamp(toBeSize, 0, p.rect.size.y); } if (m_VerticalConstrainToCanvasSize) { float constrt = RootCanvasRectTransform.rect.size.y * m_VerticalCanvasSizeFraction; if (m_VerticalConstrainToConstant) { constrt += m_VerticalConstant; } toBeSize = Mathf.Clamp(toBeSize, 0, constrt); } } } rectTransform.SetSizeWithCurrentAnchors((RectTransform.Axis)axis, toBeSize); } }
private void HandleSelfFittingAlongAxis(int axis) { FitMode fitting = (axis == 0 ? horizontalFit : verticalFit); if (fitting == FitMode.Unconstrained) { // Keep a reference to the tracked transform, but don't control its properties: m_Tracker.Add(this, rectTsfm, DrivenTransformProperties.None); return; } DrivenTransformProperties flags = DrivenTransformProperties.ScaleX | DrivenTransformProperties.ScaleY; if (horizontalFit != FitMode.Unconstrained) { flags |= DrivenTransformProperties.SizeDeltaX; } if (verticalFit != FitMode.Unconstrained) { flags |= DrivenTransformProperties.SizeDeltaY; } m_Tracker.Add(this, rectTsfm, flags); // Set size to min or preferred size float newSize = 0f; if (fitting == FitMode.MinSize) { newSize = LayoutUtility.GetMinSize(m_Rect, axis); newSize = axis == 0 ? Mathf.Max(newSize, m_fixedSize.x) : Mathf.Max(newSize, m_fixedSize.y); } else { newSize = LayoutUtility.GetPreferredSize(m_Rect, axis); } Vector2 newSizeV; if (axis == 0) { newSizeV = new Vector2(Mathf.Max(newSize, m_fixedSize.x), m_Rect.sizeDelta.y); } else { newSizeV = new Vector2(m_Rect.sizeDelta.x, Mathf.Max(newSize, m_fixedSize.y)); } m_Rect.SetSizeWithCurrentAnchors((RectTransform.Axis)axis, newSize); m_Rect.localScale = CalculateSizeScale(newSizeV, axis); }
protected void CalcAlongAxisExtended(int axis, bool isVertical) { float padding = (float)((axis != 0) ? base.padding.vertical : base.padding.horizontal); float totalMin = padding; float totalPreffered = padding; float totalFlexible = 0f; bool notOrderingAxis = isVertical ^ axis == 1; for (int i = 0; i < base.rectChildren.Count; i++) { RectTransform rect = base.rectChildren[i]; float minSize = LayoutUtility.GetMinSize(rect, axis); float preferredSize = LayoutUtility.GetPreferredSize(rect, axis); float flexibleSize = LayoutUtility.GetFlexibleSize(rect, axis); RectOffset margins = LayoutUtilityExtended.GetMargin(rect); float margin = (float)((axis != 0) ? margins.vertical : margins.horizontal); if ((axis != 0) ? this.childForceExpandHeight : this.childForceExpandWidth) { flexibleSize = Mathf.Max(flexibleSize, 1f); } if (notOrderingAxis) { totalMin = Mathf.Max(minSize + padding + margin, totalMin); totalPreffered = Mathf.Max(preferredSize + padding + margin, totalPreffered); totalFlexible = Mathf.Max(flexibleSize, totalFlexible); } else { totalMin += minSize + this.spacing + margin; totalPreffered += preferredSize + this.spacing + margin; totalFlexible += flexibleSize; } } if (!notOrderingAxis && base.rectChildren.Count > 0) { totalMin -= this.spacing; totalPreffered -= this.spacing; } totalPreffered = Mathf.Max(totalMin, totalPreffered); base.SetLayoutInputForAxis(totalMin, totalPreffered, totalFlexible, axis); }
protected void CalcAlongAxis(int axis, bool isVertical) { float combinedPadding = (axis == 0 ? padding.horizontal : padding.vertical); float totalMin = combinedPadding; float totalPreferred = combinedPadding; float totalFlexible = 0; bool alongOtherAxis = (isVertical ^ (axis == 1)); for (int i = 0; i < rectChildren.Count; i++) { RectTransform child = rectChildren[i]; float min = LayoutUtility.GetMinSize(child, axis); float preferred = LayoutUtility.GetPreferredSize(child, axis); float flexible = LayoutUtility.GetFlexibleSize(child, axis); if ((axis == 0 ? childForceExpandWidth : childForceExpandHeight)) { flexible = Mathf.Max(flexible, 1); } if (alongOtherAxis) { totalMin = Mathf.Max(min + combinedPadding, totalMin); totalPreferred = Mathf.Max(preferred + combinedPadding, totalPreferred); totalFlexible = Mathf.Max(flexible, totalFlexible); } else { totalMin += min + spacing; totalPreferred += preferred + spacing; // Increment flexible size with element's flexible size. totalFlexible += flexible; } } if (!alongOtherAxis && rectChildren.Count > 0) { totalMin -= spacing; totalPreferred -= spacing; } totalPreferred = Mathf.Max(totalMin, totalPreferred); SetLayoutInputForAxis(totalMin, totalPreferred, totalFlexible, axis); }
private void GetChildSizes(RectTransform child, int axis, bool controlSize, bool childForceExpand, out float min, out float preferred, out float flexible) { if (!controlSize) { min = child.sizeDelta[axis]; preferred = min; flexible = 0f; } else { min = LayoutUtility.GetMinSize(child, axis); preferred = LayoutUtility.GetPreferredSize(child, axis); flexible = LayoutUtility.GetFlexibleSize(child, axis); } if (childForceExpand) { flexible = Mathf.Max(flexible, 1f); } }
private void HandleSelfFittingAlongAxis(int axis) { FitMode fitMode = (axis != 0) ? verticalFit : horizontalFit; if (fitMode == FitMode.Unconstrained) { m_Tracker.Add(this, rectTransform, DrivenTransformProperties.None); return; } m_Tracker.Add(this, rectTransform, (axis != 0) ? DrivenTransformProperties.SizeDeltaY : DrivenTransformProperties.SizeDeltaX); if (fitMode == FitMode.MinSize) { rectTransform.SetSizeWithCurrentAnchors((RectTransform.Axis)axis, LayoutUtility.GetMinSize(m_Rect, axis)); } else { rectTransform.SetSizeWithCurrentAnchors((RectTransform.Axis)axis, LayoutUtility.GetPreferredSize(m_Rect, axis)); } }
void CalculateLayoutInputForAxis(int axis) { // We need to reserve space for the padding. float combinedPadding = (axis == 0 ? padding.horizontal : padding.vertical); float totalmin = combinedPadding; float totalpreferred = combinedPadding; // And for the largest child. float min = 0; float preferred = 0; for (int i = 0; i < rectChildren.Count; i++) { RectTransform child = rectChildren[i]; min = Mathf.Max(min, LayoutUtility.GetMinSize(child, axis)); preferred = Mathf.Max(preferred, LayoutUtility.GetPreferredSize(child, axis)); } totalmin += min; totalpreferred += preferred; // We ignore flexible size for now, I have not decided what to do with it yet. SetLayoutInputForAxis(totalmin, totalpreferred, -1, axis); }
private void HandleSelfFittingAlongAxis(int axis) { FitMode fitting = (axis == 0 ? horizontalFit : verticalFit); if (fitting == FitMode.Unconstrained) { return; } m_Tracker.Add(this, rectTransform, (axis == 0 ? DrivenTransformProperties.SizeDeltaX : DrivenTransformProperties.SizeDeltaY)); // Set size to min or preferred size if (fitting == FitMode.MinSize) { rectTransform.SetSizeWithCurrentAnchors((RectTransform.Axis)axis, LayoutUtility.GetMinSize(m_Rect, axis)); } else { rectTransform.SetSizeWithCurrentAnchors((RectTransform.Axis)axis, LayoutUtility.GetPreferredSize(m_Rect, axis)); } }
/// <summary> /// /// <para> /// Calculate the layout element properties for this layout element along the given axis. /// </para> /// /// </summary> /// <param name="axis">The axis to calculate for. 0 is horizontal and 1 is vertical.</param><param name="isVertical">Is this group a vertical group?</param> protected void CalcAlongAxis(int axis, bool isVertical) { float num1 = axis != 0 ? (float)this.padding.vertical : (float)this.padding.horizontal; float num2 = num1; float b = num1; float num3 = 0.0f; bool flag = isVertical ^ axis == 1; for (int index = 0; index < this.rectChildren.Count; ++index) { RectTransform rect = this.rectChildren[index]; float minSize = LayoutUtility.GetMinSize(rect, axis); float preferredSize = LayoutUtility.GetPreferredSize(rect, axis); float a = LayoutUtility.GetFlexibleSize(rect, axis); if ((axis != 0 ? (this.childForceExpandHeight ? 1 : 0) : (this.childForceExpandWidth ? 1 : 0)) != 0) { a = Mathf.Max(a, 1f); } if (flag) { num2 = Mathf.Max(minSize + num1, num2); b = Mathf.Max(preferredSize + num1, b); num3 = Mathf.Max(a, num3); } else { num2 += minSize + this.spacing; b += preferredSize + this.spacing; num3 += a; } } if (!flag && this.rectChildren.Count > 0) { num2 -= this.spacing; b -= this.spacing; } float totalPreferred = Mathf.Max(num2, b); this.SetLayoutInputForAxis(num2, totalPreferred, num3, axis); }
protected void CalcAlongAxis(int axis, bool isVertical) { float num = (axis != 0) ? ((float)base.padding.vertical) : ((float)base.padding.horizontal); float b = num; float num3 = num; float num4 = 0f; bool flag = isVertical ^ (axis == 1); for (int i = 0; i < base.rectChildren.Count; i++) { RectTransform rect = base.rectChildren[i]; float minSize = LayoutUtility.GetMinSize(rect, axis); float preferredSize = LayoutUtility.GetPreferredSize(rect, axis); float flexibleSize = LayoutUtility.GetFlexibleSize(rect, axis); if ((axis != 0) ? this.childForceExpandHeight : this.childForceExpandWidth) { flexibleSize = Mathf.Max(flexibleSize, 1f); } if (flag) { b = Mathf.Max(minSize + num, b); num3 = Mathf.Max(preferredSize + num, num3); num4 = Mathf.Max(flexibleSize, num4); } else { b += minSize + this.spacing; num3 += preferredSize + this.spacing; num4 += flexibleSize; } } if (!flag && (base.rectChildren.Count > 0)) { b -= this.spacing; num3 -= this.spacing; } num3 = Mathf.Max(b, num3); base.SetLayoutInputForAxis(b, num3, num4, axis); }
private void HandleSelfFittingAlongAxis(int axis) { FitMode mode = (axis != 0) ? this.verticalFit : this.horizontalFit; if (mode != FitMode.Unconstrained) { this.m_Tracker.Add(this, this.rectTransform, (axis != 0) ? DrivenTransformProperties.SizeDeltaY : DrivenTransformProperties.SizeDeltaX); if (mode == FitMode.MinSize) { this.rectTransform.SetSizeWithCurrentAnchors((RectTransform.Axis)axis, LayoutUtility.GetMinSize(this.m_Rect, axis)); } else { this.rectTransform.SetSizeWithCurrentAnchors((RectTransform.Axis)axis, LayoutUtility.GetPreferredSize(this.m_Rect, axis)); } } }
protected void SetChildrenAlongAxisExtended(int axis, bool isVertical) { float axisSize = base.rectTransform.rect.size[axis]; bool notOrderingAxis = isVertical ^ axis == 1; if (notOrderingAxis) { float axisSize2 = axisSize - (float)((axis != 0) ? base.padding.vertical : base.padding.horizontal); for (int i = 0; i < base.rectChildren.Count; i++) { RectTransform rect = base.rectChildren[i]; float minSize = LayoutUtility.GetMinSize(rect, axis); float preferredSize = LayoutUtility.GetPreferredSize(rect, axis); float flexibleSize = LayoutUtility.GetFlexibleSize(rect, axis); RectOffset margin = LayoutUtilityExtended.GetMargin(rect); if ((axis != 0) ? this.childForceExpandHeight : this.childForceExpandWidth) { flexibleSize = Mathf.Max(flexibleSize, 1f); } float elementSize = Mathf.Clamp(axisSize2, minSize, (flexibleSize <= 0f) ? preferredSize : axisSize); // Subtract margins if (axis == 0 && this.m_SubtractMarginHorizontal) { elementSize -= margin.horizontal; elementSize = Mathf.Clamp(elementSize, minSize, elementSize); } else if (axis != 0 && this.m_SubtractMarginVertical) { elementSize -= margin.vertical; elementSize = Mathf.Clamp(elementSize, minSize, elementSize); } float startOffset = ((axis != 0) ? margin.top : margin.left) + base.GetStartOffset(axis, elementSize); base.SetChildAlongAxis(rect, axis, startOffset, elementSize); } } else { float offset = (float)((axis != 0) ? base.padding.top : base.padding.left); if (base.GetTotalFlexibleSize(axis) == 0f && base.GetTotalPreferredSize(axis) < axisSize) { offset = base.GetStartOffset(axis, base.GetTotalPreferredSize(axis) - (float)((axis != 0) ? base.padding.vertical : base.padding.horizontal)); } float axisSize6 = 0f; if (base.GetTotalMinSize(axis) != base.GetTotalPreferredSize(axis)) { axisSize6 = Mathf.Clamp01((axisSize - base.GetTotalMinSize(axis)) / (base.GetTotalPreferredSize(axis) - base.GetTotalMinSize(axis))); } float axisSize7 = 0f; if (axisSize > base.GetTotalPreferredSize(axis) && base.GetTotalFlexibleSize(axis) > 0f) { axisSize7 = (axisSize - base.GetTotalPreferredSize(axis)) / base.GetTotalFlexibleSize(axis); } for (int j = 0; j < base.rectChildren.Count; j++) { RectTransform rect2 = base.rectChildren[j]; float minSize2 = LayoutUtility.GetMinSize(rect2, axis); float preferredSize2 = LayoutUtility.GetPreferredSize(rect2, axis); float flexibleSize = LayoutUtility.GetFlexibleSize(rect2, axis); RectOffset margin = LayoutUtilityExtended.GetMargin(rect2); if ((axis != 0) ? this.childForceExpandHeight : this.childForceExpandWidth) { flexibleSize = Mathf.Max(flexibleSize, 1f); } float elementSize = Mathf.Lerp(minSize2, preferredSize2, axisSize6); elementSize += flexibleSize * axisSize7; offset += ((axis != 0) ? margin.top : margin.left); base.SetChildAlongAxis(rect2, axis, offset, elementSize); offset += elementSize + this.spacing + ((axis != 0) ? margin.bottom : margin.right); } } }
private void HandleSelfFittingAlongAxis(int axis) { ContentSizeFitter.FitMode fitMode = axis != 0 ? this.verticalFit : this.horizontalFit; if (fitMode == ContentSizeFitter.FitMode.Unconstrained) { return; } this.m_Tracker.Add((UnityEngine.Object) this, this.rectTransform, axis != 0 ? DrivenTransformProperties.SizeDeltaY : DrivenTransformProperties.SizeDeltaX); if (fitMode == ContentSizeFitter.FitMode.MinSize) { this.rectTransform.SetSizeWithCurrentAnchors((RectTransform.Axis)axis, LayoutUtility.GetMinSize(this.m_Rect, axis)); } else { this.rectTransform.SetSizeWithCurrentAnchors((RectTransform.Axis)axis, LayoutUtility.GetPreferredSize(this.m_Rect, axis)); } }
protected void SetChildrenAlongAxis(int axis, bool isVertical) { RectTransform rect = gameObject.GetComponent <RectTransform>(); rect.anchoredPosition = Vector2.zero; bool isForceExpand = (isVertical ? childForceExpandHeight : childForceExpandWidth); if (isForceExpand) { rect.anchorMin = Vector2.zero; rect.anchorMax = Vector2.one; rect.pivot = new Vector2(0.5f, 0.5f); rect.sizeDelta = Vector2.zero; } float size = rectTransform.rect.size[axis]; bool alongOtherAxis = (isVertical ^ (axis == 1)); float wh = (axis == 0 ? padding.horizontal : padding.vertical); float itemwh; if (alongOtherAxis) { float innerSize = size - (axis == 0 ? padding.horizontal : padding.vertical); itemwh = (axis == 1 ? itemWidth : itemHeight); float itemsize = (axis == 0 ? itemWidth : itemHeight); for (int i = 0; i < rectChildren.Count; i++) { RectTransform child = rectChildren[i]; float requiredSpace = 0; float min = LayoutUtility.GetMinSize(child, axis); float preferred = LayoutUtility.GetPreferredSize(child, axis); float flexible = LayoutUtility.GetFlexibleSize(child, axis); if ((axis == 0 ? childForceExpandWidth : childForceExpandHeight)) { flexible = Mathf.Max(flexible, 1); } requiredSpace = Mathf.Clamp(innerSize, min, flexible > 0 ? size : preferred); wh += itemwh + spacing; float startOffset = GetStartOffset(axis, requiredSpace); if ((axis == 1 ? childForceExpandHeight : childForceExpandWidth)) { SetChildAlongAxis(child, axis, startOffset, innerSize); } else { SetChildAlongAxis(child, axis, startOffset, itemsize); } } } else { itemwh = (axis == 0 ? itemWidth : itemHeight); float pos = (axis == 0 ? padding.left : padding.top); if (GetTotalFlexibleSize(axis) == 0 && GetTotalPreferredSize(axis) < size) { pos = GetStartOffset(axis, GetTotalPreferredSize(axis) - (axis == 0 ? padding.horizontal : padding.vertical)); } float minMaxLerp = 0; if (GetTotalMinSize(axis) != GetTotalPreferredSize(axis)) { minMaxLerp = Mathf.Clamp01((size - GetTotalMinSize(axis)) / (GetTotalPreferredSize(axis) - GetTotalMinSize(axis))); } float itemFlexibleMultiplier = 0; if (size > GetTotalPreferredSize(axis)) { if (GetTotalFlexibleSize(axis) > 0) { itemFlexibleMultiplier = (size - GetTotalPreferredSize(axis)) / GetTotalFlexibleSize(axis); } } for (int i = 0; i < rectChildren.Count; i++) { RectTransform child = rectChildren[i]; float childSize = 0; if ((axis == 1 ? childForceExpandHeight : childForceExpandWidth)) { float min = LayoutUtility.GetMinSize(child, axis); float preferred = LayoutUtility.GetPreferredSize(child, axis); float flexible = LayoutUtility.GetFlexibleSize(child, axis); flexible = Mathf.Max(flexible, 1); childSize = Mathf.Lerp(min, preferred, minMaxLerp); childSize += flexible * itemFlexibleMultiplier; } else { childSize += itemwh; wh += childSize + spacing; } SetChildAlongAxis(child, axis, pos, childSize); pos += childSize + spacing; } } if (!isForceExpand) { if (!isVertical) { rect.pivot = new Vector2(0f, 0.5f); rect.sizeDelta = new Vector2(wh, 0); rect.anchorMin = new Vector2(0f, 0f); rect.anchorMax = new Vector2(0f, 1.0f); } else { rect.pivot = new Vector2(0.5f, 1.0f); rect.sizeDelta = new Vector2(0, wh); rect.anchorMin = new Vector2(0, 1.0f); rect.anchorMax = new Vector2(1.0f, 1.0f); } } }