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 CalculateStartVelocity(this ITween tween, float distance) { var pos1 = tween.CalculatePosition(0.0f, distance); var pos2 = tween.CalculatePosition((float)Tweener.TIME_DELTA, distance); return(Velocity.FromPerSecond((pos2 - pos1) * distance / Tweener.TIME_DELTA)); }
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)); }
private static IObservable <float> PlayInternal(ITween tween, float distance, IScheduler scheduler) { return(Observable .Defer(() => Observable.Return(scheduler.Now)) .ContinueWith(start => ObservableEx.FromMicroCoroutineWithInitialValue((observer, token) => TweenCoroutine(tween, start, distance, scheduler, observer, token), tween.CalculatePosition(scheduler.Now - start, distance)) )); }