-
Notifications
You must be signed in to change notification settings - Fork 0
/
TweenSequence.cs
95 lines (75 loc) · 2.51 KB
/
TweenSequence.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
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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Boing {
public class TweenSequence : AbstractTweenable {
List<ITweenable> tweenList = new List<ITweenable>();
int currentTweenIndex = 0;
Action<TweenSequence> completionHandler;
public int TweenCount { get { return tweenList.Count; } }
#region ITweenable
public override void Start () {
if (tweenList.Count > 0) {
tweenList[0].Start();
}
base.Start();
}
public override bool Update () {
if (isPaused) {
return false;
}
if (currentTweenIndex >= tweenList.Count) {
return true;
}
ITweenable tween = tweenList[currentTweenIndex];
if (tween.Update()) {
currentTweenIndex++;
if (currentTweenIndex == tweenList.Count) {
if (completionHandler != null) {
completionHandler(this);
}
isCurrentlyManagedBySynTween = false;
return true;
}
else {
tweenList[currentTweenIndex].Start();
}
}
return false;
}
public override void RecycleSelf () {
for (int i = 0; i < tweenList.Count; i++) {
tweenList[i].RecycleSelf();
}
tweenList.Clear();
}
public override void Stop (bool shouldComplete = false, bool shouldCompleteImmediately = false) {
currentTweenIndex = tweenList.Count;
}
#endregion
#region ITweenControl
public IEnumerator WaitForCompletion() {
while(currentTweenIndex < tweenList.Count) {
yield return null;
}
}
#endregion
#region Tween Sequence Management
public TweenSequence AppendTween(ITweenable tween) {
if (tween is ITweenable) {
tween.Resume();
tweenList.Add(tween as ITweenable);
}
else {
Debug.LogError("Cannot add a tween to a sequence that does not implement ITweenable.");
}
return this;
}
public TweenSequence SetCompletionHandler(Action<TweenSequence> handler) {
completionHandler = handler;
return this;
}
#endregion
}
}