Exemplo n.º 1
0
 private UniRx.IObservable <int> CounterAnimation(IReactiveProperty <int> property, TimeSpan delay = default)
 {
     return(property
            .Skip(1)
            .Scan(new { Previous = 0, Current = property.Value },
                  (accumulator, newVal) => new { Previous = accumulator.Current, Current = newVal })
            .Select(pair =>
     {
         var direction = pair.Current > pair.Previous ? 1 : -1;
         return Observable.Interval(delay == default ? TimeSpan.FromMilliseconds(30) : delay)
         .Scan(pair.Previous, (accumulator, _) => accumulator + direction)
         .TakeWhile(val => val != pair.Current + direction);
     })
            .Switch()
            .StartWith(property.Value));
 }