public void KeepElementInView(RectTransform toGameObject) { Assets.Scripts.Utils.UIX.UpdateLayout(ScrollRect.transform); // Debug.Log("----------------------------------------------------------------------"); var byWhatPercent = 0f; var topSpace = 250f; var percent = GetCarretPositionPercent(Mathf.Abs(toGameObject.anchoredPosition.y) + topSpace); // Debug.Log("percent: " + percent); if (percent > 50) { // Debug.Log("Lower part of the document"); byWhatPercent = Mathf.Abs(100 - (percent - 50)); // Debug.Log(percent + ", " + byWhatPercent); topSpace = UsefullUtils.GetPercent(550, byWhatPercent); // Debug.Log(topSpace); percent = GetCarretPositionPercent(Mathf.Abs(toGameObject.anchoredPosition.y) + topSpace); } else { byWhatPercent = Mathf.Abs(100 - (50 - percent)); // Debug.Log(percent + ", " + byWhatPercent); topSpace = UsefullUtils.GetPercent(250f, byWhatPercent); // Debug.Log(topSpace); percent = GetCarretPositionPercent(Mathf.Abs(toGameObject.anchoredPosition.y) + topSpace); // Debug.Log("Upper part of the document"); } // Debug.Log("percent: " + percent); var scrollValue = UsefullUtils.InvertPercent(percent) / 100; // Debug.Log("scrollValue: " + scrollValue); Scroll(scrollValue); }