6
6
/// </summary>
7
7
public abstract class Tween
8
8
{
9
+ /// <summary>
10
+ /// A set of configuration flags available for a tween.
11
+ /// </summary>
12
+ [ System . Flags ]
13
+ internal enum Flag
14
+ {
15
+ None = 0 ,
16
+ Reversed = 1 << 0 ,
17
+ Snapping = 1 << 1 ,
18
+ Recyclable = 1 << 2 ,
19
+ AutoStart = 1 << 3 ,
20
+ AutoKill = 1 << 4 ,
21
+ }
22
+
9
23
/// <summary>
10
24
/// An identifier that can be used to distinguish the tween from others.
11
25
/// This is not explicitly required nor is it necessarily unique. The id
@@ -20,17 +34,17 @@ public abstract class Tween
20
34
/// </summary>
21
35
internal int sceneIndex = - 1 ;
22
36
23
- /// <summary>
24
- /// The template type used by the tween, if relevant.
25
- /// </summary>
26
- internal System . Type template ;
27
-
28
37
/// <summary>
29
38
/// The type of tween, used internally for managing and recycling
30
39
/// tweens.
31
40
/// </summary>
32
41
internal TweenType type ;
33
42
43
+ /// <summary>
44
+ /// The template type used by the tween, if relevant.
45
+ /// </summary>
46
+ internal System . Type template ;
47
+
34
48
/// <summary>
35
49
/// The internal state of the tween as it relates to the lifeycle and
36
50
/// management of the tween.
@@ -117,31 +131,56 @@ public abstract class Tween
117
131
/// </summary>
118
132
public int iterations { get ; internal set ; }
119
133
134
+ /// <summary>
135
+ /// The configuration flags set on the tween.
136
+ /// </summary>
137
+ internal Flag flags = 0 ;
138
+
120
139
/// <summary>
121
140
/// Animates from the end value to the start value as opposed to
122
141
/// animating from the start value to the end value like normal.
123
142
/// </summary>
124
- public bool reversed = false ;
143
+ public bool reversed
144
+ {
145
+ get => GetFlag ( Flag . Reversed ) ;
146
+ set => SetFlag ( Flag . Reversed , value ) ;
147
+ }
125
148
126
149
/// <summary>
127
150
/// Smoothly snaps all interpolated values to integers.
128
151
/// </summary>
129
- public bool snapping = false ;
152
+ public bool snapping
153
+ {
154
+ get => GetFlag ( Flag . Snapping ) ;
155
+ set => SetFlag ( Flag . Snapping , value ) ;
156
+ }
130
157
131
158
/// <summary>
132
159
/// Keeps the tween in memory to be re-used after being killed.
133
160
/// </summary>
134
- public bool recyclable = Tweening . defaultRecyclable ;
161
+ public bool recyclable
162
+ {
163
+ get => GetFlag ( Flag . Recyclable ) ;
164
+ set => SetFlag ( Flag . Recyclable , value ) ;
165
+ }
135
166
136
167
/// <summary>
137
168
/// Automatically starts the tween after being created.
138
169
/// </summary>
139
- public bool autoStart = Tweening . defaultAutoStart ;
170
+ public bool autoStart
171
+ {
172
+ get => GetFlag ( Flag . AutoStart ) ;
173
+ set => SetFlag ( Flag . AutoStart , value ) ;
174
+ }
140
175
141
176
/// <summary>
142
177
/// Automatically kills the tween after being completed.
143
178
/// </summary>
144
- public bool autoKill = Tweening . defaultAutoKill ;
179
+ public bool autoKill
180
+ {
181
+ get => GetFlag ( Flag . AutoKill ) ;
182
+ set => SetFlag ( Flag . AutoKill , value ) ;
183
+ }
145
184
146
185
/// <summary>
147
186
/// The callback invoked every time the tween is updated, i.e., any time
@@ -179,6 +218,7 @@ public abstract class Tween
179
218
/// </summary>
180
219
internal Tween ( )
181
220
{
221
+ Reset ( ) ;
182
222
TweenManager . Instance . Track ( this ) ;
183
223
}
184
224
@@ -410,7 +450,6 @@ internal void Reset()
410
450
this . internalState = InternalTweenState . Queued ;
411
451
412
452
this . ease = Tweening . defaultEase ;
413
-
414
453
this . duration = Tweening . defaultDuration ;
415
454
this . elapsed = 0.0f ;
416
455
this . delay = Tweening . defaultDelay ;
@@ -420,9 +459,9 @@ internal void Reset()
420
459
this . loopType = LoopType . Restart ;
421
460
this . iterations = 0 ;
422
461
462
+ this . flags = 0 ;
423
463
this . reversed = false ;
424
464
this . snapping = false ;
425
-
426
465
this . autoStart = Tweening . defaultAutoStart ;
427
466
this . autoKill = Tweening . defaultAutoKill ;
428
467
this . recyclable = Tweening . defaultRecyclable ;
@@ -437,6 +476,20 @@ internal void Reset()
437
476
OnReset ( ) ;
438
477
}
439
478
479
+ internal bool GetFlag ( Flag flag )
480
+ {
481
+ return this . flags . HasFlag ( flag ) ;
482
+ }
483
+
484
+ internal void SetFlag ( Flag flag , bool on )
485
+ {
486
+ if ( on ) {
487
+ this . flags |= flag ;
488
+ } else {
489
+ this . flags &= ~ flag ;
490
+ }
491
+ }
492
+
440
493
protected virtual bool IsFinished ( ) => this . elapsed >= this . duration ;
441
494
protected virtual void OnUpdate ( ) { }
442
495
protected virtual void OnStart ( ) { }
0 commit comments