66 /// </summary>
77 public abstract class Tween
88 {
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+
923 /// <summary>
1024 /// An identifier that can be used to distinguish the tween from others.
1125 /// This is not explicitly required nor is it necessarily unique. The id
@@ -20,17 +34,17 @@ public abstract class Tween
2034 /// </summary>
2135 internal int sceneIndex = - 1 ;
2236
23- /// <summary>
24- /// The template type used by the tween, if relevant.
25- /// </summary>
26- internal System . Type template ;
27-
2837 /// <summary>
2938 /// The type of tween, used internally for managing and recycling
3039 /// tweens.
3140 /// </summary>
3241 internal TweenType type ;
3342
43+ /// <summary>
44+ /// The template type used by the tween, if relevant.
45+ /// </summary>
46+ internal System . Type template ;
47+
3448 /// <summary>
3549 /// The internal state of the tween as it relates to the lifeycle and
3650 /// management of the tween.
@@ -117,31 +131,56 @@ public abstract class Tween
117131 /// </summary>
118132 public int iterations { get ; internal set ; }
119133
134+ /// <summary>
135+ /// The configuration flags set on the tween.
136+ /// </summary>
137+ internal Flag flags = 0 ;
138+
120139 /// <summary>
121140 /// Animates from the end value to the start value as opposed to
122141 /// animating from the start value to the end value like normal.
123142 /// </summary>
124- public bool reversed = false ;
143+ public bool reversed
144+ {
145+ get => GetFlag ( Flag . Reversed ) ;
146+ set => SetFlag ( Flag . Reversed , value ) ;
147+ }
125148
126149 /// <summary>
127150 /// Smoothly snaps all interpolated values to integers.
128151 /// </summary>
129- public bool snapping = false ;
152+ public bool snapping
153+ {
154+ get => GetFlag ( Flag . Snapping ) ;
155+ set => SetFlag ( Flag . Snapping , value ) ;
156+ }
130157
131158 /// <summary>
132159 /// Keeps the tween in memory to be re-used after being killed.
133160 /// </summary>
134- public bool recyclable = Tweening . defaultRecyclable ;
161+ public bool recyclable
162+ {
163+ get => GetFlag ( Flag . Recyclable ) ;
164+ set => SetFlag ( Flag . Recyclable , value ) ;
165+ }
135166
136167 /// <summary>
137168 /// Automatically starts the tween after being created.
138169 /// </summary>
139- public bool autoStart = Tweening . defaultAutoStart ;
170+ public bool autoStart
171+ {
172+ get => GetFlag ( Flag . AutoStart ) ;
173+ set => SetFlag ( Flag . AutoStart , value ) ;
174+ }
140175
141176 /// <summary>
142177 /// Automatically kills the tween after being completed.
143178 /// </summary>
144- public bool autoKill = Tweening . defaultAutoKill ;
179+ public bool autoKill
180+ {
181+ get => GetFlag ( Flag . AutoKill ) ;
182+ set => SetFlag ( Flag . AutoKill , value ) ;
183+ }
145184
146185 /// <summary>
147186 /// The callback invoked every time the tween is updated, i.e., any time
@@ -179,6 +218,7 @@ public abstract class Tween
179218 /// </summary>
180219 internal Tween ( )
181220 {
221+ Reset ( ) ;
182222 TweenManager . Instance . Track ( this ) ;
183223 }
184224
@@ -410,7 +450,6 @@ internal void Reset()
410450 this . internalState = InternalTweenState . Queued ;
411451
412452 this . ease = Tweening . defaultEase ;
413-
414453 this . duration = Tweening . defaultDuration ;
415454 this . elapsed = 0.0f ;
416455 this . delay = Tweening . defaultDelay ;
@@ -420,9 +459,9 @@ internal void Reset()
420459 this . loopType = LoopType . Restart ;
421460 this . iterations = 0 ;
422461
462+ this . flags = 0 ;
423463 this . reversed = false ;
424464 this . snapping = false ;
425-
426465 this . autoStart = Tweening . defaultAutoStart ;
427466 this . autoKill = Tweening . defaultAutoKill ;
428467 this . recyclable = Tweening . defaultRecyclable ;
@@ -437,6 +476,20 @@ internal void Reset()
437476 OnReset ( ) ;
438477 }
439478
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+
440493 protected virtual bool IsFinished ( ) => this . elapsed >= this . duration ;
441494 protected virtual void OnUpdate ( ) { }
442495 protected virtual void OnStart ( ) { }
0 commit comments