/// <inheritdoc/> public TimeSpan?GetAnimationTime(TimeSpan time) { // Get the effective start, end and duration of the clip. TimeSpan clipStart, clipEnd, clipLength; GetClip(out clipStart, out clipEnd, out clipLength); // ----- Delay time -= Delay; if (time < TimeSpan.Zero) { // The animation has not started. return(null); } // ----- Speed time = new TimeSpan((long)(time.Ticks * (double)Speed)); // ----- Duration TimeSpan duration = Duration ?? clipLength; // ----- FillBehavior if (time > duration) { if (FillBehavior == FillBehavior.Stop) { // The animation has stopped. return(null); } // The animation holds the last value. Debug.Assert(FillBehavior == FillBehavior.Hold); time = duration; } // ----- Adjust animation time to play/loop clip from original timeline. time = clipStart + ClipOffset + time; AnimationHelper.LoopParameter(time, clipStart, clipEnd, LoopBehavior, out time); // ----- Reverse if (IsClipReversed) { time = clipEnd - (time - clipStart); } return(time); }
private void GetValueCore(TimeSpan time, ref T defaultSource, ref T defaultTarget, ref T result) { if (Animation == null) { Traits.Copy(ref defaultSource, ref result); return; } TimeSpan clipStart, clipEnd, clipLength; GetClip(out clipStart, out clipEnd, out clipLength); // Correct time parameter. time = clipStart + ClipOffset + time; TimeSpan loopedTime; bool hasCycleOffset = AnimationHelper.LoopParameter(time, clipStart, clipEnd, LoopBehavior, out loopedTime); // ----- Reverse if (IsClipReversed) { loopedTime = clipEnd - (loopedTime - clipStart); } if (!hasCycleOffset) { // Get animation value. Animation.GetValue(loopedTime, ref defaultSource, ref defaultTarget, ref result); } else { // Animation with cycle offset. var traits = Traits; // 'defaultSource', 'defaultTarget' and 'result' may be the same instance! We need to // ensure that the source and target values are not overwritten by GetValue(). // --> Use local variable to get animation value. T value, startValue, endValue, cycleOffset; traits.Create(ref defaultSource, out value); traits.Create(ref defaultSource, out startValue); traits.Create(ref defaultSource, out endValue); traits.Create(ref defaultSource, out cycleOffset); // Get animation value. Animation.GetValue(loopedTime, ref defaultSource, ref defaultTarget, ref value); // Apply cycle offset. Animation.GetValue(clipStart, ref defaultSource, ref defaultTarget, ref startValue); Animation.GetValue(clipEnd, ref defaultSource, ref defaultTarget, ref endValue); if (IsClipReversed) { MathHelper.Swap(ref startValue, ref endValue); } AnimationHelper.GetCycleOffset(time, clipStart, clipEnd, ref startValue, ref endValue, traits, LoopBehavior, ref cycleOffset); traits.Add(ref value, ref cycleOffset, ref result); traits.Recycle(ref cycleOffset); traits.Recycle(ref endValue); traits.Recycle(ref startValue); traits.Recycle(ref value); } }