Merge pull request #280 from yellowisher/master
[DoTween]: fix "AwaitFor~" extensions ignore original callbackmaster
commit
ee2fd3e91d
|
@ -16,14 +16,14 @@ namespace Cysharp.Threading.Tasks
|
||||||
Kill,
|
Kill,
|
||||||
KillWithCompleteCallback,
|
KillWithCompleteCallback,
|
||||||
Complete,
|
Complete,
|
||||||
CompleteWithSeqeunceCallback,
|
CompleteWithSequenceCallback,
|
||||||
CancelAwait,
|
CancelAwait,
|
||||||
|
|
||||||
// AndCancelAwait
|
// AndCancelAwait
|
||||||
KillAndCancelAwait,
|
KillAndCancelAwait,
|
||||||
KillWithCompleteCallbackAndCancelAwait,
|
KillWithCompleteCallbackAndCancelAwait,
|
||||||
CompleteAndCancelAwait,
|
CompleteAndCancelAwait,
|
||||||
CompleteWithSeqeunceCallbackAndCancelAwait
|
CompleteWithSequenceCallbackAndCancelAwait
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class DOTweenAsyncExtensions
|
public static class DOTweenAsyncExtensions
|
||||||
|
@ -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;
|
||||||
|
@ -228,7 +238,7 @@ namespace Cysharp.Threading.Tasks
|
||||||
if (this.cancelBehaviour == TweenCancelBehaviour.KillAndCancelAwait
|
if (this.cancelBehaviour == TweenCancelBehaviour.KillAndCancelAwait
|
||||||
|| this.cancelBehaviour == TweenCancelBehaviour.KillWithCompleteCallbackAndCancelAwait
|
|| this.cancelBehaviour == TweenCancelBehaviour.KillWithCompleteCallbackAndCancelAwait
|
||||||
|| this.cancelBehaviour == TweenCancelBehaviour.CompleteAndCancelAwait
|
|| this.cancelBehaviour == TweenCancelBehaviour.CompleteAndCancelAwait
|
||||||
|| this.cancelBehaviour == TweenCancelBehaviour.CompleteWithSeqeunceCallbackAndCancelAwait
|
|| this.cancelBehaviour == TweenCancelBehaviour.CompleteWithSequenceCallbackAndCancelAwait
|
||||||
|| this.cancelBehaviour == TweenCancelBehaviour.CancelAwait)
|
|| this.cancelBehaviour == TweenCancelBehaviour.CancelAwait)
|
||||||
{
|
{
|
||||||
canceled = true;
|
canceled = true;
|
||||||
|
@ -240,6 +250,7 @@ namespace Cysharp.Threading.Tasks
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
originalCompleteAction?.Invoke();
|
||||||
core.TrySetResult(AsyncUnit.Default);
|
core.TrySetResult(AsyncUnit.Default);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -277,34 +288,34 @@ namespace Cysharp.Threading.Tasks
|
||||||
this.canceled = true;
|
this.canceled = true;
|
||||||
this.tween.Complete(false);
|
this.tween.Complete(false);
|
||||||
break;
|
break;
|
||||||
case TweenCancelBehaviour.CompleteWithSeqeunceCallback:
|
case TweenCancelBehaviour.CompleteWithSequenceCallback:
|
||||||
this.tween.Complete(true);
|
this.tween.Complete(true);
|
||||||
break;
|
break;
|
||||||
case TweenCancelBehaviour.CompleteWithSeqeunceCallbackAndCancelAwait:
|
case TweenCancelBehaviour.CompleteWithSequenceCallbackAndCancelAwait:
|
||||||
this.canceled = true;
|
this.canceled = true;
|
||||||
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;
|
||||||
|
@ -339,10 +350,10 @@ namespace Cysharp.Threading.Tasks
|
||||||
case TweenCancelBehaviour.CompleteAndCancelAwait:
|
case TweenCancelBehaviour.CompleteAndCancelAwait:
|
||||||
tween.Complete(false);
|
tween.Complete(false);
|
||||||
break;
|
break;
|
||||||
case TweenCancelBehaviour.CompleteWithSeqeunceCallback:
|
case TweenCancelBehaviour.CompleteWithSequenceCallback:
|
||||||
tween.Complete(true);
|
tween.Complete(true);
|
||||||
break;
|
break;
|
||||||
case TweenCancelBehaviour.CompleteWithSeqeunceCallbackAndCancelAwait:
|
case TweenCancelBehaviour.CompleteWithSequenceCallbackAndCancelAwait:
|
||||||
tween.Complete(true);
|
tween.Complete(true);
|
||||||
break;
|
break;
|
||||||
case TweenCancelBehaviour.CancelAwait:
|
case TweenCancelBehaviour.CancelAwait:
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue