private IEnumerator LerpToContent() { ItemFoundToSnap.Invoke(LerpTargetIndex); mLerping = true; Vector3 originalContentPos = contentTransform.localPosition; float elapsedTime = 0; while (elapsedTime < mLerpTime) { elapsedTime += Time.deltaTime; contentTransform.localPosition = Vector3.Lerp(originalContentPos, lerpTarget, (elapsedTime / mLerpTime)); yield return(null); } ItemSnappedTo.Invoke(LerpTargetIndex); mLerping = false; }
private IEnumerator SlideAndLerp() { mSliding = true; while (Mathf.Abs(scrollRect.velocity.x) > snappingVelocityThreshold) { yield return(null); } lerpTarget = FindClosestFrom(contentTransform.localPosition); ItemFoundToSnap.Invoke(LerpTargetIndex); while (Vector3.Distance(contentTransform.localPosition, lerpTarget) > 1) { contentTransform.localPosition = Vector3.Lerp(scrollRect.content.localPosition, lerpTarget, 7.5f * Time.deltaTime); yield return(null); } mSliding = false; scrollRect.velocity = Vector2.zero; contentTransform.localPosition = lerpTarget; ItemSnappedTo.Invoke(LerpTargetIndex); }