private static IEnumerator TweenCoroutine(ITween tween, float start, float distance, IScheduler scheduler, IObserver <float> observer, CancellationToken token) { while (true) { if (token.IsCancellationRequested) { observer.OnCompleted(); yield break; } while (scheduler.Paused) { yield return(null); } var now = scheduler.Now - start; if (tween.CalculateFinishTime(distance) < now) { break; } observer.OnNext(tween.CalculatePosition(now, distance)); yield return(null); } observer.OnNext(tween.CalculatePosition(tween.CalculateFinishTime(distance), distance)); observer.OnCompleted(); }
public static Velocity CalculateFinishVelocity(this ITween tween, float distance) { var finishTime = tween.CalculateFinishTime(distance); var pos1 = tween.CalculatePosition(finishTime - (float)Tweener.TIME_DELTA, distance); var pos2 = tween.CalculatePosition(finishTime, distance); return(Velocity.FromPerSecond((pos2 - pos1) * distance / Tweener.TIME_DELTA)); }