/// <summary> /// 移动 /// </summary> private void Move(MoveDirType dir) { if (isMove) { return; } isMove = true; float value = 0; Vector3 beforeIndexPos = Vector3.one; switch (dir) { case MoveDirType.Left: //归位 beforeIndexPos = GetVectorByIndex(MoveDirType.Left); value = -beforeIndexPos.x; //界限值 if (value >= minPos.x) { value = minPos.x; onMoveToMinPos(true); } else { onMoveToMinPos(false); onMoveToMaxPos(false); } break; case MoveDirType.Right: //归位 beforeIndexPos = GetVectorByIndex(MoveDirType.Right); value = -beforeIndexPos.x; //界限值 if (value <= -maxPos.x) { value = -maxPos.x; onMoveToMaxPos(true); } else { onMoveToMinPos(false); onMoveToMaxPos(false); } break; } scrollRect.StopMovement(); Tweener tweener = content.DOLocalMoveX(value, 0.35f, true); tweener.OnComplete(() => { isMove = false; onMoveEnd(); }); onValueChanged(content.anchoredPosition); }
/// <summary> /// 通过下标获取坐标 /// </summary> private Vector3 GetVectorByIndex(MoveDirType dir) { float floatIndex = GetCurScrollPerLineIndex(); int index = 0; switch (dir) { case MoveDirType.Left: index = Mathf.CeilToInt(floatIndex - 0.15f); index -= 1; break; case MoveDirType.Right: index = Mathf.FloorToInt(floatIndex + 0.15f); index += 1; break; } Vector3 indexPos = GetLocalPositionByIndex(index); return(indexPos); }