-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sequence.cs
135 lines (122 loc) · 3.88 KB
/
Sequence.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using System;
using System.Collections.Generic;
using FlaxEngine;
namespace FTween
{
public class Sequence : FTweener
{
public Sequence() : base(0){
}
public override FTweener Reverse(bool val)
{
Debug.LogWarning("You cant reverse a sequence");
return this;
}
internal override void SetupSpeedBased()
{
Debug.LogWarning("Sequence cant be speedBased");
}
public class SeqTween
{
public float time;
public FTweener tween;
public SeqTween(float time, FTweener tween)
{
this.time = time;
this.tween = tween;
}
}
List<SeqTween> tweens = new List<SeqTween>();
float lastTweenInsertTime;
public Sequence Append(FTweener tween)
{
return Insert(tween, duration);
}
public Sequence Insert(FTweener tween)
{
return Insert(tween, lastTweenInsertTime);
}
public Sequence Insert(FTweener tween, float time)
{
if(tween.loops != 0)
{
Debug.LogWarning("You cant have loop tween in sequence, setting tween loops to 0");
tween.loops = 0;
}
duration = Mathf.Max(duration, time + (tween.duration * tween.timeScale * timeScale) + tween.startDelay);
lastTweenInsertTime = time;
tween.parentSeq = this;
tweens.Add(new SeqTween(time, tween));
return this;
}
public Sequence AppendCallback(Action onDone)
{
return Append(new FCallback(onDone));
}
public Sequence InsertCallback(Action onDone)
{
return Insert(new FCallback(onDone));
}
public Sequence InsertCallback(Action onDone, float time)
{
return Insert(new FCallback(onDone), time);
}
public override void ResetCurrentLoop()
{
base.ResetCurrentLoop();
foreach (SeqTween seqTween in tweens)
{
seqTween.tween.Reset();
}
}
internal override void update(float delta)
{
timeFromStart += delta * timeScale;
float relativeTime = timeFromStart - startDelay;
if (relativeTime > 0 && !isComplete)
{
foreach (SeqTween seqTween in tweens)
{
if(relativeTime > seqTween.time)
{
if (!seqTween.tween.setup)
seqTween.tween.Setup();
seqTween.tween.update(delta * timeScale);
}
}
}
if (relativeTime >= duration && !isComplete)
{
if (loops != 0)
{
loops--;
try
{
onLoopComplete?.Invoke();
}
catch (Exception e)
{
Debug.Log("Error has been thrown during invoke of onLoopComplete of tween: " + e.Message);
Debug.Log(e.StackTrace);
}
ResetCurrentLoop();
}
else
{
try
{
onComplete?.Invoke();
}
catch (Exception e)
{
Debug.Log("Error has been thrown during invoke of onComplete of tween: " + e.Message);
Debug.Log(e.StackTrace);
}
_isComplete = true;
if (parentSeq == null)
Kill();
}
}
}
}
}