@@ -163,11 +163,7 @@ internal void Update(float deltaTime)
163
163
{
164
164
if ( this . IsPlaying )
165
165
{
166
- if ( this . elapsed >= this . duration )
167
- {
168
- Complete ( ) ;
169
- }
170
- else if ( ! this . IsDelayed )
166
+ if ( ! this . IsDelayed )
171
167
{
172
168
this . elapsed += deltaTime ;
173
169
@@ -177,10 +173,21 @@ internal void Update(float deltaTime)
177
173
if ( this . onUpdate != null ) {
178
174
this . onUpdate . Invoke ( ) ;
179
175
}
176
+
177
+ if ( CanComplete ( ) ) {
178
+ Complete ( ) ;
179
+ }
180
180
}
181
181
else
182
182
{
183
183
this . delayElapsed += deltaTime ;
184
+
185
+ // Start the tween once the delay is complete and only if
186
+ // the elapsed time is zero which indicates it has never
187
+ // been updated yet
188
+ if ( this . elapsed == 0 && this . delayElapsed >= this . delay ) {
189
+ Start ( ) ;
190
+ }
184
191
}
185
192
}
186
193
else if ( this . state == TweenState . Ready && this . autoStart )
@@ -213,15 +220,26 @@ public void Play()
213
220
this . elapsed = 0.0f ;
214
221
this . delayElapsed = 0.0f ;
215
222
216
- OnStart ( ) ;
217
- Animate ( ) ;
218
-
219
- if ( this . onStart != null ) {
220
- this . onStart . Invoke ( ) ;
223
+ // Start right away if there is no delay
224
+ if ( ! this . IsDelayed ) {
225
+ Start ( ) ;
221
226
}
222
227
}
223
228
}
224
229
230
+ /// <summary>
231
+ /// Starts the tween for the first time.
232
+ /// </summary>
233
+ private void Start ( )
234
+ {
235
+ OnStart ( ) ;
236
+ Animate ( ) ;
237
+
238
+ if ( this . onStart != null ) {
239
+ this . onStart . Invoke ( ) ;
240
+ }
241
+ }
242
+
225
243
/// <summary>
226
244
/// Stops the tween if currently being played.
227
245
/// </summary>
@@ -327,6 +345,7 @@ internal void Reset()
327
345
OnReset ( ) ;
328
346
}
329
347
348
+ protected virtual bool CanComplete ( ) => this . elapsed >= this . duration ;
330
349
protected virtual void OnUpdate ( ) { }
331
350
protected virtual void OnStart ( ) { }
332
351
protected virtual void OnStop ( ) { }
0 commit comments