From dfe18d11ff8d5bb295fec0b84d1ea4d07696c30e Mon Sep 17 00:00:00 2001 From: yellowisher Date: Sat, 8 May 2021 14:39:26 +0900 Subject: [PATCH] [DoTween]: call original complete callback as well --- .../DOTween/DOTweenAsyncExtensions.cs | 42 ++++++++++++------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/External/DOTween/DOTweenAsyncExtensions.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/External/DOTween/DOTweenAsyncExtensions.cs index ebe8aa4..28aacfc 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/External/DOTween/DOTweenAsyncExtensions.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/External/DOTween/DOTweenAsyncExtensions.cs @@ -143,8 +143,6 @@ namespace Cysharp.Threading.Tasks TaskPool.RegisterSizeGetter(typeof(TweenConfiguredSource), () => pool.Size); } - static readonly TweenCallback EmptyTweenCallback = () => { }; - readonly TweenCallback onCompleteCallbackDelegate; readonly TweenCallback onUpdateDelegate; @@ -155,6 +153,7 @@ namespace Cysharp.Threading.Tasks bool canceled; TweenCallback originalUpdateAction; + TweenCallback originalCompleteAction; UniTaskCompletionSourceCore core; TweenConfiguredSource() @@ -194,27 +193,38 @@ namespace Cysharp.Threading.Tasks switch (callbackType) { case CallbackType.Kill: + result.originalCompleteAction = tween.onKill; tween.onKill = result.onCompleteCallbackDelegate; break; case CallbackType.Complete: + result.originalCompleteAction = tween.onComplete; tween.onComplete = result.onCompleteCallbackDelegate; break; case CallbackType.Pause: + result.originalCompleteAction = tween.onPause; tween.onPause = result.onCompleteCallbackDelegate; break; case CallbackType.Play: + result.originalCompleteAction = tween.onPlay; tween.onPlay = result.onCompleteCallbackDelegate; break; case CallbackType.Rewind: + result.originalCompleteAction = tween.onRewind; tween.onRewind = result.onCompleteCallbackDelegate; break; case CallbackType.StepComplete: + result.originalCompleteAction = tween.onStepComplete; tween.onStepComplete = result.onCompleteCallbackDelegate; break; default: break; } + if (result.originalCompleteAction == result.onCompleteCallbackDelegate) + { + result.originalCompleteAction = null; + } + TaskTracker.TrackActiveTask(result, 3); token = result.core.Version; @@ -240,6 +250,7 @@ namespace Cysharp.Threading.Tasks } else { + originalCompleteAction?.Invoke(); core.TrySetResult(AsyncUnit.Default); } } @@ -285,26 +296,26 @@ namespace Cysharp.Threading.Tasks this.tween.Complete(true); break; case TweenCancelBehaviour.CancelAwait: - // replace to empty(avoid callback after Canceled(instance is returned to pool.) + // restore to original callback switch (callbackType) { case CallbackType.Kill: - tween.onKill = EmptyTweenCallback; + tween.onKill = originalCompleteAction; break; case CallbackType.Complete: - tween.onComplete = EmptyTweenCallback; + tween.onComplete = originalCompleteAction; break; case CallbackType.Pause: - tween.onPause = EmptyTweenCallback; + tween.onPause = originalCompleteAction; break; case CallbackType.Play: - tween.onPlay = EmptyTweenCallback; + tween.onPlay = originalCompleteAction; break; case CallbackType.Rewind: - tween.onRewind = EmptyTweenCallback; + tween.onRewind = originalCompleteAction; break; case CallbackType.StepComplete: - tween.onStepComplete = EmptyTweenCallback; + tween.onStepComplete = originalCompleteAction; break; default: break; @@ -386,22 +397,22 @@ namespace Cysharp.Threading.Tasks switch (callbackType) { case CallbackType.Kill: - tween.onKill = null; + tween.onKill = originalCompleteAction; break; case CallbackType.Complete: - tween.onComplete = null; + tween.onComplete = originalCompleteAction; break; case CallbackType.Pause: - tween.onPause = null; + tween.onPause = originalCompleteAction; break; case CallbackType.Play: - tween.onPlay = null; + tween.onPlay = originalCompleteAction; break; case CallbackType.Rewind: - tween.onRewind = null; + tween.onRewind = originalCompleteAction; break; case CallbackType.StepComplete: - tween.onStepComplete = null; + tween.onStepComplete = originalCompleteAction; break; default: break; @@ -410,6 +421,7 @@ namespace Cysharp.Threading.Tasks tween = default; cancellationToken = default; originalUpdateAction = default; + originalCompleteAction = default; return pool.TryPush(this); } }