/// <summary> /// Late update. /// </summary> protected virtual void LateUpdate() { if (IsScrolling) { IsScrolling = false; InitIntertia(); } else if (!IsDragging && (InertiaDistance > 0f) && AlwaysCenter) { var delta = Utilites.DefaultGetDeltaTime(UnscaledTime); var distance = IntertiaVelocity > 0f ? Mathf.Min(InertiaDistance, IntertiaVelocity * delta) : Mathf.Max(-InertiaDistance, IntertiaVelocity * delta); Padding += distance; InertiaDistance -= Mathf.Abs(distance); if (InertiaDistance > 0f) { IntertiaVelocity += CurrentDecelerationRate * delta; ScrollVelocity = -IntertiaVelocity; } else { StopInertia(); } } }
/// <summary> /// Scroll. /// </summary> /// <param name="delta">Delta.</param> protected virtual void Scroll(float delta) { Padding += delta; CurrentScrollValue += delta; var time_delta = Utilites.DefaultGetDeltaTime(UnscaledTime); var new_velocity = (PrevScrollValue - CurrentScrollValue) / time_delta; ScrollVelocity = Mathf.Lerp(ScrollVelocity, new_velocity, time_delta * 10); PrevScrollValue = CurrentScrollValue; }