public void OnClick() { scrollRect.DOKill(); Vector2 valueToMove = (Vector2)scrollRect.transform.InverseTransformPoint(scrollRect.content.position) - (Vector2)scrollRect.transform.InverseTransformPoint(relatedItem.position); scrollRect.content.DOAnchorPos(valueToMove, 0.3f); }
public void JumpTo(int cellIndex, float tweenTime = 0f, OnCenterCallback onStart = null, OnCenterCallback onEnd = null) { if (cellIndex < 0 || cellIndex >= CellNum) { return; } _curCellIndex = cellIndex; float endScrollPos = GetCellScrollPos(cellIndex); _scrollRect.DOKill(); if (tweenTime < 0.001f) { //Instant tween this.ScrollPosition = endScrollPos; if (onStart != null) { onStart(cellIndex); } if (onEnd != null) { onEnd(cellIndex); } } else { //use DOTween move scrollRect if (onStart != null) { onStart(cellIndex); } TweenCallback onTweenFinish = () => { if (onEnd != null) { onEnd(cellIndex); } }; if (_scrollRect.horizontal) { _scrollRect.DOHorizontalNormalizedPos(endScrollPos, tweenTime).OnComplete(onTweenFinish).SetEase(easeType); } else { _scrollRect.DOVerticalNormalizedPos(endScrollPos, tweenTime).OnComplete(onTweenFinish).SetEase(easeType); } } }
public void OnBeginDrag(PointerEventData data) { scrollRect.DOKill(); firstPos = Input.mousePosition; }