[DoTween]: call original complete callback as well

master
yellowisher 2021-05-08 14:39:26 +09:00
parent 958a8e11ab
commit dfe18d11ff
1 changed files with 27 additions and 15 deletions

View File

@ -143,8 +143,6 @@ namespace Cysharp.Threading.Tasks
TaskPool.RegisterSizeGetter(typeof(TweenConfiguredSource), () => pool.Size); TaskPool.RegisterSizeGetter(typeof(TweenConfiguredSource), () => pool.Size);
} }
static readonly TweenCallback EmptyTweenCallback = () => { };
readonly TweenCallback onCompleteCallbackDelegate; readonly TweenCallback onCompleteCallbackDelegate;
readonly TweenCallback onUpdateDelegate; readonly TweenCallback onUpdateDelegate;
@ -155,6 +153,7 @@ namespace Cysharp.Threading.Tasks
bool canceled; bool canceled;
TweenCallback originalUpdateAction; TweenCallback originalUpdateAction;
TweenCallback originalCompleteAction;
UniTaskCompletionSourceCore<AsyncUnit> core; UniTaskCompletionSourceCore<AsyncUnit> core;
TweenConfiguredSource() TweenConfiguredSource()
@ -194,27 +193,38 @@ namespace Cysharp.Threading.Tasks
switch (callbackType) switch (callbackType)
{ {
case CallbackType.Kill: case CallbackType.Kill:
result.originalCompleteAction = tween.onKill;
tween.onKill = result.onCompleteCallbackDelegate; tween.onKill = result.onCompleteCallbackDelegate;
break; break;
case CallbackType.Complete: case CallbackType.Complete:
result.originalCompleteAction = tween.onComplete;
tween.onComplete = result.onCompleteCallbackDelegate; tween.onComplete = result.onCompleteCallbackDelegate;
break; break;
case CallbackType.Pause: case CallbackType.Pause:
result.originalCompleteAction = tween.onPause;
tween.onPause = result.onCompleteCallbackDelegate; tween.onPause = result.onCompleteCallbackDelegate;
break; break;
case CallbackType.Play: case CallbackType.Play:
result.originalCompleteAction = tween.onPlay;
tween.onPlay = result.onCompleteCallbackDelegate; tween.onPlay = result.onCompleteCallbackDelegate;
break; break;
case CallbackType.Rewind: case CallbackType.Rewind:
result.originalCompleteAction = tween.onRewind;
tween.onRewind = result.onCompleteCallbackDelegate; tween.onRewind = result.onCompleteCallbackDelegate;
break; break;
case CallbackType.StepComplete: case CallbackType.StepComplete:
result.originalCompleteAction = tween.onStepComplete;
tween.onStepComplete = result.onCompleteCallbackDelegate; tween.onStepComplete = result.onCompleteCallbackDelegate;
break; break;
default: default:
break; break;
} }
if (result.originalCompleteAction == result.onCompleteCallbackDelegate)
{
result.originalCompleteAction = null;
}
TaskTracker.TrackActiveTask(result, 3); TaskTracker.TrackActiveTask(result, 3);
token = result.core.Version; token = result.core.Version;
@ -240,6 +250,7 @@ namespace Cysharp.Threading.Tasks
} }
else else
{ {
originalCompleteAction?.Invoke();
core.TrySetResult(AsyncUnit.Default); core.TrySetResult(AsyncUnit.Default);
} }
} }
@ -285,26 +296,26 @@ namespace Cysharp.Threading.Tasks
this.tween.Complete(true); this.tween.Complete(true);
break; break;
case TweenCancelBehaviour.CancelAwait: case TweenCancelBehaviour.CancelAwait:
// replace to empty(avoid callback after Canceled(instance is returned to pool.) // restore to original callback
switch (callbackType) switch (callbackType)
{ {
case CallbackType.Kill: case CallbackType.Kill:
tween.onKill = EmptyTweenCallback; tween.onKill = originalCompleteAction;
break; break;
case CallbackType.Complete: case CallbackType.Complete:
tween.onComplete = EmptyTweenCallback; tween.onComplete = originalCompleteAction;
break; break;
case CallbackType.Pause: case CallbackType.Pause:
tween.onPause = EmptyTweenCallback; tween.onPause = originalCompleteAction;
break; break;
case CallbackType.Play: case CallbackType.Play:
tween.onPlay = EmptyTweenCallback; tween.onPlay = originalCompleteAction;
break; break;
case CallbackType.Rewind: case CallbackType.Rewind:
tween.onRewind = EmptyTweenCallback; tween.onRewind = originalCompleteAction;
break; break;
case CallbackType.StepComplete: case CallbackType.StepComplete:
tween.onStepComplete = EmptyTweenCallback; tween.onStepComplete = originalCompleteAction;
break; break;
default: default:
break; break;
@ -386,22 +397,22 @@ namespace Cysharp.Threading.Tasks
switch (callbackType) switch (callbackType)
{ {
case CallbackType.Kill: case CallbackType.Kill:
tween.onKill = null; tween.onKill = originalCompleteAction;
break; break;
case CallbackType.Complete: case CallbackType.Complete:
tween.onComplete = null; tween.onComplete = originalCompleteAction;
break; break;
case CallbackType.Pause: case CallbackType.Pause:
tween.onPause = null; tween.onPause = originalCompleteAction;
break; break;
case CallbackType.Play: case CallbackType.Play:
tween.onPlay = null; tween.onPlay = originalCompleteAction;
break; break;
case CallbackType.Rewind: case CallbackType.Rewind:
tween.onRewind = null; tween.onRewind = originalCompleteAction;
break; break;
case CallbackType.StepComplete: case CallbackType.StepComplete:
tween.onStepComplete = null; tween.onStepComplete = originalCompleteAction;
break; break;
default: default:
break; break;
@ -410,6 +421,7 @@ namespace Cysharp.Threading.Tasks
tween = default; tween = default;
cancellationToken = default; cancellationToken = default;
originalUpdateAction = default; originalUpdateAction = default;
originalCompleteAction = default;
return pool.TryPush(this); return pool.TryPush(this);
} }
} }