-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDualAnimationT.cs
53 lines (46 loc) · 1.8 KB
/
DualAnimationT.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
namespace BrainbeanApps.ValueAnimation
{
/// <summary>
/// Implements the EaseInOut animation using EaseIn and EaseOut animations.
/// </summary>
public class DualAnimation<T> : BaseAnimation<T>, IValueAnimation<T>
where T : struct, IComparable
{
/// <summary>
/// The first animation.
/// </summary>
public readonly ValueAnimation<T> FirstAnimation;
/// <summary>
/// The second animation.
/// </summary>
public readonly ValueAnimation<T> SecondAnimation;
public DualAnimation(ValueAnimation<T> firstAnimation, ValueAnimation<T> secondAnimation)
: this(ValueAnimation.ValueOperations.For<T>(), firstAnimation, secondAnimation)
{
}
public DualAnimation(IValueOperations<T> valueOperations, ValueAnimation<T> firstAnimation,
ValueAnimation<T> secondAnimation)
: base(valueOperations)
{
if (firstAnimation == null)
throw new ArgumentNullException();
if (secondAnimation == null)
throw new ArgumentNullException();
FirstAnimation = firstAnimation;
SecondAnimation = secondAnimation;
}
public T GetValue(float currentTime, float duration, T initialValue, T deltaValue)
{
var halfDuration = 0.5f * duration;
var halfDelta = ValueOperations.ScaleByFactor(deltaValue, 0.5f);
if (currentTime < halfDuration)
return FirstAnimation(currentTime, halfDuration, initialValue, halfDelta);
else
{
return SecondAnimation(currentTime - halfDuration, halfDuration,
ValueOperations.Add(initialValue, halfDelta), halfDelta);
}
}
}
}