public void FitSize(bool keepPosition = false) { if (!allowResize || !content) { return; } content.LateUpdate(); var toolBarRect = toolbar.rectTransform; var oldRect = rectTransform.rect; var rect = content.contentRect.rect; rectTransform.sizeDelta = new Vector2( rect.width, rect.height + toolBarRect.rect.height ); if (keepPosition) { var newRect = rectTransform.rect; var diff = new Vector3(oldRect.xMin, oldRect.yMax) - new Vector3(newRect.xMin, newRect.yMax); transform.localPosition += diff; } }