@@ -195,80 +195,12 @@ internal void Update(float deltaTime)
195195 /// </summary>
196196 public void Play ( )
197197 {
198- if ( this . state . CanTransition ( TweenState . Playing ) ) {
199- TransitionToPlaying ( this . state ) ;
198+ if ( ! this . state . CanTransition ( TweenState . Playing ) ) {
199+ return ;
200200 }
201- }
202-
203- /// <summary>
204- /// Stops the tween if currently being played.
205- /// </summary>
206- public void Stop ( )
207- {
208- if ( this . state . CanTransition ( TweenState . Stopped ) ) {
209- TransitionToStopped ( ) ;
210- }
211- }
212-
213- /// <summary>
214- /// Completes the tween, jumping to the end value.
215- /// </summary>
216- public void Complete ( )
217- {
218- if ( this . state . CanTransition ( TweenState . Complete ) ) {
219- TransitionToComplete ( ) ;
220- }
221- }
222201
223- /// <summary>
224- /// Kills the tween in its place, preventing any further state changes
225- /// or changes to the parameter being animated.
226- /// </summary>
227- public void Kill ( )
228- {
229- if ( this . state . CanTransition ( TweenState . Killed ) ) {
230- TransitionToKilled ( ) ;
231- }
232- }
202+ TweenState previousState = this . state ;
233203
234- /// <summary>
235- /// Restarts the tween as along as it has not been killed.
236- /// </summary>
237- public void Restart ( )
238- {
239- Stop ( ) ;
240- Play ( ) ;
241- }
242-
243- /// <summary>
244- /// Resets all properties of the tween back to their default values.
245- /// </summary>
246- internal void Reset ( )
247- {
248- this . id = - 1 ;
249- this . state = TweenState . Ready ;
250- this . internalState = InternalTweenState . Queued ;
251- this . ease = Settings . defaultEase ;
252- this . duration = Settings . defaultDuration ;
253- this . elapsed = 0.0f ;
254- this . delay = Settings . defaultDelay ;
255- this . delayElapsed = 0.0f ;
256- this . reversed = false ;
257- this . autoStart = Settings . defaultAutoStart ;
258- this . autoKill = Settings . defaultAutoKill ;
259- this . recyclable = Settings . defaultRecyclable ;
260-
261- this . onUpdate = null ;
262- this . onStart = null ;
263- this . onStop = null ;
264- this . onComplete = null ;
265- this . onKill = null ;
266-
267- OnReset ( ) ;
268- }
269-
270- private void TransitionToPlaying ( TweenState previousState )
271- {
272204 this . state = TweenState . Playing ;
273205 this . internalState = InternalTweenState . Active ;
274206
@@ -290,8 +222,15 @@ private void TransitionToPlaying(TweenState previousState)
290222 }
291223 }
292224
293- private void TransitionToStopped ( )
225+ /// <summary>
226+ /// Stops the tween if currently being played.
227+ /// </summary>
228+ public void Stop ( )
294229 {
230+ if ( ! this . state . CanTransition ( TweenState . Stopped ) ) {
231+ return ;
232+ }
233+
295234 this . state = TweenState . Stopped ;
296235
297236 OnStop ( ) ;
@@ -301,8 +240,15 @@ private void TransitionToStopped()
301240 }
302241 }
303242
304- private void TransitionToComplete ( )
243+ /// <summary>
244+ /// Completes the tween, jumping to the end value.
245+ /// </summary>
246+ public void Complete ( )
305247 {
248+ if ( ! this . state . CanTransition ( TweenState . Complete ) ) {
249+ return ;
250+ }
251+
306252 this . state = TweenState . Complete ;
307253 this . elapsed = this . duration ;
308254 this . delayElapsed = this . delay ;
@@ -319,8 +265,16 @@ private void TransitionToComplete()
319265 }
320266 }
321267
322- private void TransitionToKilled ( )
268+ /// <summary>
269+ /// Kills the tween in its place, preventing any further state changes
270+ /// or changes to the parameter being animated.
271+ /// </summary>
272+ public void Kill ( )
323273 {
274+ if ( ! this . state . CanTransition ( TweenState . Killed ) ) {
275+ return ;
276+ }
277+
324278 this . state = TweenState . Killed ;
325279 this . internalState = InternalTweenState . Dequeued ;
326280
@@ -337,6 +291,42 @@ private void TransitionToKilled()
337291 this . onComplete = null ;
338292 }
339293
294+ /// <summary>
295+ /// Restarts the tween as along as it has not been killed.
296+ /// </summary>
297+ public void Restart ( )
298+ {
299+ Stop ( ) ;
300+ Play ( ) ;
301+ }
302+
303+ /// <summary>
304+ /// Resets all properties of the tween back to their default values.
305+ /// </summary>
306+ internal void Reset ( )
307+ {
308+ this . id = - 1 ;
309+ this . state = TweenState . Ready ;
310+ this . internalState = InternalTweenState . Queued ;
311+ this . ease = Settings . defaultEase ;
312+ this . duration = Settings . defaultDuration ;
313+ this . elapsed = 0.0f ;
314+ this . delay = Settings . defaultDelay ;
315+ this . delayElapsed = 0.0f ;
316+ this . reversed = false ;
317+ this . autoStart = Settings . defaultAutoStart ;
318+ this . autoKill = Settings . defaultAutoKill ;
319+ this . recyclable = Settings . defaultRecyclable ;
320+
321+ this . onUpdate = null ;
322+ this . onStart = null ;
323+ this . onStop = null ;
324+ this . onComplete = null ;
325+ this . onKill = null ;
326+
327+ OnReset ( ) ;
328+ }
329+
340330 protected virtual void OnUpdate ( ) { }
341331 protected virtual void OnStart ( ) { }
342332 protected virtual void OnStop ( ) { }
0 commit comments