private static Vector2 CalculateAnchoredPosition(ScrollRect sr, RectTransform contentRtx, Vector3 childWorldPos, Vector2 childSize, Vector2 childPivot) { if ((sr.horizontal && sr.vertical) || (!sr.horizontal && !sr.vertical)) { MfLog.Error(LC.Trace, "Tried to scroll to a child on a ScrollRect that can scroll both horizontal and " + "vertical!"); return(contentRtx.anchoredPosition); } LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)sr.transform); // Can remove? if (sr.horizontal) { // This will not work when invoked during an Awake() float xDist = sr.ChildPosInContentRect(childWorldPos).x; float targetXPos = xDist + (childSize.x * childPivot.x) // Add the influence of a pivot on child if one present - (contentRtx.rect.width * contentRtx.pivot.x) // Subtract the influence of the content's pivot and the anchor of the parent rects - (((RectTransform)contentRtx.parent.transform).rect.width * contentRtx.anchorMin.x); return(sr.GetContentAnchoredPositionBounded(new Vector2(targetXPos, sr.content.anchoredPosition.y))); } else { float yDist = sr.ChildPosInContentRect(childWorldPos).y; float targetYPos = yDist - (childSize.y * (1.0f - childPivot.y)) // Subtract the influence of a pivot on child if one present + (contentRtx.rect.height * (1.0f - contentRtx.pivot.y)) // Add the influence of the content's pivot and the anchor of the parent rects + (((RectTransform)contentRtx.parent.transform).rect.height * (1.0f - contentRtx.anchorMin.y)); return(sr.GetContentAnchoredPositionBounded(new Vector2(sr.content.anchoredPosition.x, targetYPos))); } }