-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSequence.cs
More file actions
105 lines (94 loc) · 2.58 KB
/
Sequence.cs
File metadata and controls
105 lines (94 loc) · 2.58 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System.Collections.Generic;
namespace Tween
{
public class Sequence : TweenBase
{
private List<TweenBase> tweens = new List<TweenBase>();
private int currentIndex = 0;
private int loopCount;
private int currentLoop;
private bool yoyo;
public Sequence(string id = null, bool useUnscaledTime = false)
{
Id = id;
UseUnscaledTime = useUnscaledTime;
}
public Sequence Append(TweenBase tween)
{
tweens.Add(tween);
return this;
}
public Sequence SetLoop(int count, bool yoyo = false)
{
loopCount = count;
this.yoyo = yoyo;
return this;
}
public override void Pause()
{
base.Pause();
if (currentIndex < tweens.Count)
{
tweens[currentIndex].Pause();
}
}
public override void Resume()
{
base.Resume();
if (currentIndex < tweens.Count)
{
tweens[currentIndex].Resume();
}
}
public override void Reverse()
{
if (currentIndex < tweens.Count)
{
tweens[currentIndex].Reverse();
}
}
public override void Update(float scaledDt, float unscaledDt)
{
if (IsCompleted || IsDisposed || IsPaused) return;
if (currentIndex >= tweens.Count)
{
if (loopCount == -1 || currentLoop < loopCount - 1)
{
currentLoop++;
currentIndex = 0;
if (yoyo)
{
tweens.Reverse();
}
foreach (var tween in tweens)
{
tween.IsCompleted = false;
tween.Resume();
}
}
else
{
IsCompleted = true;
}
return;
}
tweens[currentIndex].Update(scaledDt, unscaledDt);
if (tweens[currentIndex].IsCompleted)
{
currentIndex++;
}
}
public override void Dispose()
{
if (!IsDisposed)
{
base.Dispose();
foreach (var tween in tweens)
{
tween.Dispose();
}
tweens.Clear();
}
}
}
}