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 Dispose() { onCenterStart = null; onCenterEnd = null; }