コード例 #1
0
 /// <summary>
 /// Manages tracking the progress of an animation, running a callback with the information.
 /// Returns a lifetime that ends when the animation has expired.
 /// </summary>
 public static Lifetime AnimateWith(this Animation animation, TimeSpan duration, AnimationCallback callback, Lifetime constraint = default(Lifetime))
 {
     var remaining = duration;
     var life = constraint.CreateDependentSource();
     animation.StepActions.Add(
         step => {
             remaining -= step.TimeStep;
             if (remaining >= TimeSpan.Zero) {
                 callback(step, 1 - remaining.TotalSeconds / duration.TotalSeconds, duration - remaining);
             } else {
                 life.EndLifetime();
             }
         },
         life.Lifetime);
     return life.Lifetime;
 }