public void FocusOnLineNumber(int lineNumber) { if (theContent.sizeDelta.y <= theScrollView.sizeDelta.y) { theContent.anchoredPosition = new Vector2(theContent.anchoredPosition.x, 0); return; } float offset = theTextField.inputRect.anchoredPosition.y; // Here Y 0 is top, -Y is up and +Y is down // Since that's how it is in the contents anchor positions float topY = -offset - theTextField.DetermineYOffset(lineNumber); float botY = topY + approxLineHeight; topY -= margin; botY += margin; Rect current = new Rect(theContent.anchoredPosition, theScrollView.sizeDelta); if (botY > current.yMax) { // Move down to line theContent.anchoredPosition = new Vector2(current.x, Mathf.Max(Mathf.Min(botY - current.height, theContent.sizeDelta.y - current.height), 0)); } else if (topY < current.y) { // Move up to line theContent.anchoredPosition = new Vector2(current.x, Mathf.Max(Mathf.Min(topY, theContent.sizeDelta.y - current.height), 0)); } }
private void moveMarker() { if (lineNumber < 0) { theMarkerRect.anchoredPosition = new Vector2(0, -5000); } else //+20 on x to fix offset. Should possibly be changed in UI instead { theMarkerRect.anchoredPosition = new Vector2(20, theTextField.DetermineYOffset(lineNumber)); } }
private void MoveMarker() { if (lineNumber < 0) { theMarkerRect.gameObject.SetActive(false); } else { theMarkerRect.gameObject.SetActive(true); theMarkerRect.anchoredPosition = new Vector2(0, theTextField.DetermineYOffset(lineNumber)); } }