diff --git a/Packages/NativeWebSocket.dll b/Packages/NativeWebSocket.dll index ce5f6191..fb71b828 100644 Binary files a/Packages/NativeWebSocket.dll and b/Packages/NativeWebSocket.dll differ diff --git a/Packages/NativeWebSocket.dll.meta b/Packages/NativeWebSocket.dll.meta index c1282b47..9ca4eead 100644 --- a/Packages/NativeWebSocket.dll.meta +++ b/Packages/NativeWebSocket.dll.meta @@ -4,7 +4,8 @@ PluginImporter: externalObjects: {} serializedVersion: 2 iconMap: {} - executionOrder: {} + executionOrder: + WebSocketDispatcher: -100 defineConstraints: [] isPreloaded: 0 isOverridable: 0 diff --git a/Packages/Solana.Unity.Rpc.dll b/Packages/Solana.Unity.Rpc.dll index cd3f6dcb..f4d2b4b0 100644 Binary files a/Packages/Solana.Unity.Rpc.dll and b/Packages/Solana.Unity.Rpc.dll differ diff --git a/Runtime/Plugins/UniTask/Editor.meta b/Runtime/Plugins/UniTask/Editor.meta index 579b2db2..55e810b6 100644 --- a/Runtime/Plugins/UniTask/Editor.meta +++ b/Runtime/Plugins/UniTask/Editor.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 20258684eba20467096e6f5e29c3c27a +guid: 00957b1ea0bfd4e7e8c7c9a8ce63aef4 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Runtime/Plugins/UniTask/Editor/SplitterGUILayout.cs.meta b/Runtime/Plugins/UniTask/Editor/SplitterGUILayout.cs.meta index 378d6c33..4d718f4e 100644 --- a/Runtime/Plugins/UniTask/Editor/SplitterGUILayout.cs.meta +++ b/Runtime/Plugins/UniTask/Editor/SplitterGUILayout.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 757c9c5807884460b90a4a4589ef3e69 +guid: 40ef2e46f900131419e869398a8d3c9d MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Editor/UniTask.Editor.asmdef.meta b/Runtime/Plugins/UniTask/Editor/UniTask.Editor.asmdef.meta index b0383bfc..821b87b7 100644 --- a/Runtime/Plugins/UniTask/Editor/UniTask.Editor.asmdef.meta +++ b/Runtime/Plugins/UniTask/Editor/UniTask.Editor.asmdef.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 6a68f3363dee742f5bddb0649a21f17b +guid: 4129704b5a1a13841ba16f230bf24a57 AssemblyDefinitionImporter: externalObjects: {} userData: diff --git a/Runtime/Plugins/UniTask/Editor/UniTaskTrackerTreeView.cs.meta b/Runtime/Plugins/UniTask/Editor/UniTaskTrackerTreeView.cs.meta index fe57a358..9b34d7b9 100644 --- a/Runtime/Plugins/UniTask/Editor/UniTaskTrackerTreeView.cs.meta +++ b/Runtime/Plugins/UniTask/Editor/UniTaskTrackerTreeView.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: ada1f4f0677ee44e78b7b9cc73338dca +guid: 52e2d973a2156674e8c1c9433ed031f7 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Editor/UniTaskTrackerWindow.cs.meta b/Runtime/Plugins/UniTask/Editor/UniTaskTrackerWindow.cs.meta index 103ec8d3..ba1b7045 100644 --- a/Runtime/Plugins/UniTask/Editor/UniTaskTrackerWindow.cs.meta +++ b/Runtime/Plugins/UniTask/Editor/UniTaskTrackerWindow.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 4ffa85870fcdc4a2eb34f5a517172a13 +guid: 5bee3e3860e37484aa3b861bf76d129f MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime.meta b/Runtime/Plugins/UniTask/Runtime.meta index 8ca4ec06..a7e2184c 100644 --- a/Runtime/Plugins/UniTask/Runtime.meta +++ b/Runtime/Plugins/UniTask/Runtime.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: be6d6d7e41ee44cbe91dee1ca9591886 +guid: b224bae2cf96242429c852ebcccc8efa folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Runtime/Plugins/UniTask/Runtime/AsyncLazy.cs.meta b/Runtime/Plugins/UniTask/Runtime/AsyncLazy.cs.meta index 051d7961..554d1628 100644 --- a/Runtime/Plugins/UniTask/Runtime/AsyncLazy.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/AsyncLazy.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 6ac6f88263ced4ef2aa09dd3b1d929e8 +guid: 01d1404ca421466419a7db7340ff5e77 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/AsyncReactiveProperty.cs.meta b/Runtime/Plugins/UniTask/Runtime/AsyncReactiveProperty.cs.meta index 106174af..d64e3cff 100644 --- a/Runtime/Plugins/UniTask/Runtime/AsyncReactiveProperty.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/AsyncReactiveProperty.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: d2720eb6d626b4176b7fc2c6c8ca28cb +guid: 8ef320b87f537ee4fb2282e765dc6166 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/AsyncUnit.cs.meta b/Runtime/Plugins/UniTask/Runtime/AsyncUnit.cs.meta index f1c94748..e0ee1329 100644 --- a/Runtime/Plugins/UniTask/Runtime/AsyncUnit.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/AsyncUnit.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 7f8f9d4bb69fa4f29beb3677a6dacd19 +guid: 4f95ac245430d304bb5128d13b6becc8 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/CancellationTokenEqualityComparer.cs.meta b/Runtime/Plugins/UniTask/Runtime/CancellationTokenEqualityComparer.cs.meta index 772dcbf9..a4fe3fd9 100644 --- a/Runtime/Plugins/UniTask/Runtime/CancellationTokenEqualityComparer.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/CancellationTokenEqualityComparer.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 78fe21b1b4ff246e6bc5287bea9bd762 +guid: 7d739f510b125b74fa7290ac4335e46e MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/CancellationTokenExtensions.cs.meta b/Runtime/Plugins/UniTask/Runtime/CancellationTokenExtensions.cs.meta index 05ba103a..28a69586 100644 --- a/Runtime/Plugins/UniTask/Runtime/CancellationTokenExtensions.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/CancellationTokenExtensions.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 9930b5aa613dd4feab81c81d3e04d2ff +guid: 4be7209f04146bd45ac5ee775a5f7c26 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/CancellationTokenSourceExtensions.cs.meta b/Runtime/Plugins/UniTask/Runtime/CancellationTokenSourceExtensions.cs.meta index 0b0d1daf..fd09fe4b 100644 --- a/Runtime/Plugins/UniTask/Runtime/CancellationTokenSourceExtensions.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/CancellationTokenSourceExtensions.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 810bc09d6065e427eb5466711c202148 +guid: 22d85d07f1e70ab42a7a4c25bd65e661 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Channel.cs.meta b/Runtime/Plugins/UniTask/Runtime/Channel.cs.meta index 9c2fc683..32edb9c0 100644 --- a/Runtime/Plugins/UniTask/Runtime/Channel.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Channel.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 92e7a1cc41a8f4f3db5ee42658e8a4c8 +guid: 5ceb3107bbdd1f14eb39091273798360 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/CompilerServices.meta b/Runtime/Plugins/UniTask/Runtime/CompilerServices.meta index 5c74e492..ab25ff95 100644 --- a/Runtime/Plugins/UniTask/Runtime/CompilerServices.meta +++ b/Runtime/Plugins/UniTask/Runtime/CompilerServices.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 1728867db4cd04431ae783e464fd1ce5 +guid: 93c23b040306c4ab89735ba8fb5e1a05 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Runtime/Plugins/UniTask/Runtime/CompilerServices/AsyncMethodBuilderAttribute.cs.meta b/Runtime/Plugins/UniTask/Runtime/CompilerServices/AsyncMethodBuilderAttribute.cs.meta index 5c08f53f..19961dfb 100644 --- a/Runtime/Plugins/UniTask/Runtime/CompilerServices/AsyncMethodBuilderAttribute.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/CompilerServices/AsyncMethodBuilderAttribute.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 3a1e7504c88f6413bae2594091642b8c +guid: 02ce354d37b10454e8376062f7cbe57a MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/CompilerServices/AsyncUniTaskMethodBuilder.cs.meta b/Runtime/Plugins/UniTask/Runtime/CompilerServices/AsyncUniTaskMethodBuilder.cs.meta index 04f5b093..ad43cfcf 100644 --- a/Runtime/Plugins/UniTask/Runtime/CompilerServices/AsyncUniTaskMethodBuilder.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/CompilerServices/AsyncUniTaskMethodBuilder.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 9b51da797ef2a43e2b96a17b02113fe9 +guid: 68d72a45afdec574ebc26e7de2c38330 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/CompilerServices/AsyncUniTaskVoidMethodBuilder.cs.meta b/Runtime/Plugins/UniTask/Runtime/CompilerServices/AsyncUniTaskVoidMethodBuilder.cs.meta index 72cdedac..9bcc50e0 100644 --- a/Runtime/Plugins/UniTask/Runtime/CompilerServices/AsyncUniTaskVoidMethodBuilder.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/CompilerServices/AsyncUniTaskVoidMethodBuilder.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: a0c856c8e72e24007be4a4a1645a6318 +guid: e891aaac17b933a47a9d7fa3b8e1226f MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/CompilerServices/StateMachineRunner.cs.meta b/Runtime/Plugins/UniTask/Runtime/CompilerServices/StateMachineRunner.cs.meta index b6e8ecfc..2cb82e08 100644 --- a/Runtime/Plugins/UniTask/Runtime/CompilerServices/StateMachineRunner.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/CompilerServices/StateMachineRunner.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: e2e94e59d752448ee89d2ff4d0f11ace +guid: 98649642833cabf44a9dc060ce4c84a1 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/EnumerableAsyncExtensions.cs.meta b/Runtime/Plugins/UniTask/Runtime/EnumerableAsyncExtensions.cs.meta index 70e26df3..d2e49304 100644 --- a/Runtime/Plugins/UniTask/Runtime/EnumerableAsyncExtensions.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/EnumerableAsyncExtensions.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 9365cf5a5094e475f9b5730d06a4aaf7 +guid: ff50260d74bd54c4b92cf99895549445 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/EnumeratorAsyncExtensions.cs.meta b/Runtime/Plugins/UniTask/Runtime/EnumeratorAsyncExtensions.cs.meta index c9e4c738..a07b336d 100644 --- a/Runtime/Plugins/UniTask/Runtime/EnumeratorAsyncExtensions.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/EnumeratorAsyncExtensions.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 189ff75a1d1a04c909861ea11153799a +guid: bc661232f11e4a741af54ba1c175d5ee MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/ExceptionExtensions.cs.meta b/Runtime/Plugins/UniTask/Runtime/ExceptionExtensions.cs.meta index 02f4d3b9..98330016 100644 --- a/Runtime/Plugins/UniTask/Runtime/ExceptionExtensions.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/ExceptionExtensions.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: a88bc0733bfb2466aa80faacddcefda6 +guid: 930800098504c0d46958ce23a0495202 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/External.meta b/Runtime/Plugins/UniTask/Runtime/External.meta index 98b3f820..fc582e6f 100644 --- a/Runtime/Plugins/UniTask/Runtime/External.meta +++ b/Runtime/Plugins/UniTask/Runtime/External.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 299b15dca66cf48d5928bdca8776f741 +guid: 2ca1bcb72294c4fa9a81473cb24e7201 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Runtime/Plugins/UniTask/Runtime/External/Addressables.meta b/Runtime/Plugins/UniTask/Runtime/External/Addressables.meta index 617e0806..d9f899da 100644 --- a/Runtime/Plugins/UniTask/Runtime/External/Addressables.meta +++ b/Runtime/Plugins/UniTask/Runtime/External/Addressables.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 1fea76f24c2454f92ae690ce47c7e9db +guid: a269b9a4ab6134332b74afc342e9ccfa folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Runtime/Plugins/UniTask/Runtime/External/Addressables/AddressablesAsyncExtensions.cs b/Runtime/Plugins/UniTask/Runtime/External/Addressables/AddressablesAsyncExtensions.cs index f321bdba..a0ca8a1f 100644 --- a/Runtime/Plugins/UniTask/Runtime/External/Addressables/AddressablesAsyncExtensions.cs +++ b/Runtime/Plugins/UniTask/Runtime/External/Addressables/AddressablesAsyncExtensions.cs @@ -25,7 +25,12 @@ public static UniTask WithCancellation(this AsyncOperationHandle handle, Cancell return ToUniTask(handle, cancellationToken: cancellationToken); } - public static UniTask ToUniTask(this AsyncOperationHandle handle, IProgress progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) + public static UniTask WithCancellation(this AsyncOperationHandle handle, CancellationToken cancellationToken, bool cancelImmediately) + { + return ToUniTask(handle, cancellationToken: cancellationToken, cancelImmediately: cancelImmediately); + } + + public static UniTask ToUniTask(this AsyncOperationHandle handle, IProgress progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false) { if (cancellationToken.IsCancellationRequested) return UniTask.FromCanceled(cancellationToken); @@ -44,7 +49,7 @@ public static UniTask WithCancellation(this AsyncOperationHandle handle, Cancell return UniTask.CompletedTask; } - return new UniTask(AsyncOperationHandleConfiguredSource.Create(handle, timing, progress, cancellationToken, out var token), token); + return new UniTask(AsyncOperationHandleConfiguredSource.Create(handle, timing, progress, cancellationToken, cancelImmediately, out var token), token); } public struct AsyncOperationHandleAwaiter : ICriticalNotifyCompletion @@ -106,6 +111,7 @@ static AsyncOperationHandleConfiguredSource() readonly Action continuationAction; AsyncOperationHandle handle; CancellationToken cancellationToken; + CancellationTokenRegistration cancellationTokenRegistration; IProgress progress; bool completed; @@ -116,7 +122,7 @@ static AsyncOperationHandleConfiguredSource() continuationAction = Continuation; } - public static IUniTaskSource Create(AsyncOperationHandle handle, PlayerLoopTiming timing, IProgress progress, CancellationToken cancellationToken, out short token) + public static IUniTaskSource Create(AsyncOperationHandle handle, PlayerLoopTiming timing, IProgress progress, CancellationToken cancellationToken, bool cancelImmediately, out short token) { if (cancellationToken.IsCancellationRequested) { @@ -132,6 +138,15 @@ public static IUniTaskSource Create(AsyncOperationHandle handle, PlayerLoopTimin result.progress = progress; result.cancellationToken = cancellationToken; result.completed = false; + + if (cancelImmediately && cancellationToken.CanBeCanceled) + { + result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => + { + var promise = (AsyncOperationHandleConfiguredSource)state; + promise.core.TrySetCanceled(promise.cancellationToken); + }, result); + } TaskTracker.TrackActiveTask(result, 3); @@ -219,6 +234,7 @@ bool TryReturn() handle = default; progress = default; cancellationToken = default; + cancellationTokenRegistration.Dispose(); return pool.TryPush(this); } } @@ -237,7 +253,12 @@ public static UniTask WithCancellation(this AsyncOperationHandle handle return ToUniTask(handle, cancellationToken: cancellationToken); } - public static UniTask ToUniTask(this AsyncOperationHandle handle, IProgress progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) + public static UniTask WithCancellation(this AsyncOperationHandle handle, CancellationToken cancellationToken, bool cancelImmediately) + { + return ToUniTask(handle, cancellationToken: cancellationToken, cancelImmediately: cancelImmediately); + } + + public static UniTask ToUniTask(this AsyncOperationHandle handle, IProgress progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false) { if (cancellationToken.IsCancellationRequested) return UniTask.FromCanceled(cancellationToken); @@ -255,7 +276,7 @@ public static UniTask WithCancellation(this AsyncOperationHandle handle return UniTask.FromResult(handle.Result); } - return new UniTask(AsyncOperationHandleConfiguredSource.Create(handle, timing, progress, cancellationToken, out var token), token); + return new UniTask(AsyncOperationHandleConfiguredSource.Create(handle, timing, progress, cancellationToken, cancelImmediately, out var token), token); } sealed class AsyncOperationHandleConfiguredSource : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode> @@ -272,6 +293,7 @@ static AsyncOperationHandleConfiguredSource() readonly Action> continuationAction; AsyncOperationHandle handle; CancellationToken cancellationToken; + CancellationTokenRegistration cancellationTokenRegistration; IProgress progress; bool completed; @@ -282,7 +304,7 @@ static AsyncOperationHandleConfiguredSource() continuationAction = Continuation; } - public static IUniTaskSource Create(AsyncOperationHandle handle, PlayerLoopTiming timing, IProgress progress, CancellationToken cancellationToken, out short token) + public static IUniTaskSource Create(AsyncOperationHandle handle, PlayerLoopTiming timing, IProgress progress, CancellationToken cancellationToken, bool cancelImmediately, out short token) { if (cancellationToken.IsCancellationRequested) { @@ -298,6 +320,15 @@ public static IUniTaskSource Create(AsyncOperationHandle handle, PlayerLoo result.cancellationToken = cancellationToken; result.completed = false; result.progress = progress; + + if (cancelImmediately && cancellationToken.CanBeCanceled) + { + result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => + { + var promise = (AsyncOperationHandleConfiguredSource)state; + promise.core.TrySetCanceled(promise.cancellationToken); + }, result); + } TaskTracker.TrackActiveTask(result, 3); @@ -390,6 +421,7 @@ bool TryReturn() handle = default; progress = default; cancellationToken = default; + cancellationTokenRegistration.Dispose(); return pool.TryPush(this); } } diff --git a/Runtime/Plugins/UniTask/Runtime/External/Addressables/AddressablesAsyncExtensions.cs.meta b/Runtime/Plugins/UniTask/Runtime/External/Addressables/AddressablesAsyncExtensions.cs.meta index 6ba66a3d..6927930d 100644 --- a/Runtime/Plugins/UniTask/Runtime/External/Addressables/AddressablesAsyncExtensions.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/External/Addressables/AddressablesAsyncExtensions.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: aa87456ab4bfb49dd86a9e8d43369166 +guid: 3dc6441f9094f354b931dc3c79fb99e5 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/External/Addressables/UniTask.Addressables.asmdef.meta b/Runtime/Plugins/UniTask/Runtime/External/Addressables/UniTask.Addressables.asmdef.meta index 3a779038..b0178c4a 100644 --- a/Runtime/Plugins/UniTask/Runtime/External/Addressables/UniTask.Addressables.asmdef.meta +++ b/Runtime/Plugins/UniTask/Runtime/External/Addressables/UniTask.Addressables.asmdef.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: deab4bec1c51f4a7b9066fa7d61fea7c +guid: 593a5b492d29ac6448b1ebf7f035ef33 AssemblyDefinitionImporter: externalObjects: {} userData: diff --git a/Runtime/Plugins/UniTask/Runtime/External/DOTween.meta b/Runtime/Plugins/UniTask/Runtime/External/DOTween.meta index 9fac58de..d1fe3f4e 100644 --- a/Runtime/Plugins/UniTask/Runtime/External/DOTween.meta +++ b/Runtime/Plugins/UniTask/Runtime/External/DOTween.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: e4bf632f7899340fcb6a98ddea28d866 +guid: e9044e6516f78424f9ce47f4ad5790aa folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Runtime/Plugins/UniTask/Runtime/External/DOTween/DOTweenAsyncExtensions.cs b/Runtime/Plugins/UniTask/Runtime/External/DOTween/DOTweenAsyncExtensions.cs index 80ae27c0..ba783672 100644 --- a/Runtime/Plugins/UniTask/Runtime/External/DOTween/DOTweenAsyncExtensions.cs +++ b/Runtime/Plugins/UniTask/Runtime/External/DOTween/DOTweenAsyncExtensions.cs @@ -144,22 +144,20 @@ static TweenConfiguredSource() } readonly TweenCallback onCompleteCallbackDelegate; - readonly TweenCallback onUpdateDelegate; Tween tween; TweenCancelBehaviour cancelBehaviour; CancellationToken cancellationToken; + CancellationTokenRegistration cancellationRegistration; CallbackType callbackType; bool canceled; - TweenCallback originalUpdateAction; TweenCallback originalCompleteAction; UniTaskCompletionSourceCore core; TweenConfiguredSource() { onCompleteCallbackDelegate = OnCompleteCallbackDelegate; - onUpdateDelegate = OnUpdate; } public static IUniTaskSource Create(Tween tween, TweenCancelBehaviour cancelBehaviour, CancellationToken cancellationToken, CallbackType callbackType, out short token) @@ -179,17 +177,8 @@ public static IUniTaskSource Create(Tween tween, TweenCancelBehaviour cancelBeha result.cancelBehaviour = cancelBehaviour; result.cancellationToken = cancellationToken; result.callbackType = callbackType; - - result.originalUpdateAction = tween.onUpdate; result.canceled = false; - if (result.originalUpdateAction == result.onUpdateDelegate) - { - result.originalUpdateAction = null; - } - - tween.onUpdate = result.onUpdateDelegate; - switch (callbackType) { case CallbackType.Kill: @@ -225,6 +214,50 @@ public static IUniTaskSource Create(Tween tween, TweenCancelBehaviour cancelBeha result.originalCompleteAction = null; } + if (cancellationToken.CanBeCanceled) + { + result.cancellationRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(x => + { + var source = (TweenConfiguredSource)x; + switch (source.cancelBehaviour) + { + case TweenCancelBehaviour.Kill: + default: + source.tween.Kill(false); + break; + case TweenCancelBehaviour.KillAndCancelAwait: + source.canceled = true; + source.tween.Kill(false); + break; + case TweenCancelBehaviour.KillWithCompleteCallback: + source.tween.Kill(true); + break; + case TweenCancelBehaviour.KillWithCompleteCallbackAndCancelAwait: + source.canceled = true; + source.tween.Kill(true); + break; + case TweenCancelBehaviour.Complete: + source.tween.Complete(false); + break; + case TweenCancelBehaviour.CompleteAndCancelAwait: + source.canceled = true; + source.tween.Complete(false); + break; + case TweenCancelBehaviour.CompleteWithSequenceCallback: + source.tween.Complete(true); + break; + case TweenCancelBehaviour.CompleteWithSequenceCallbackAndCancelAwait: + source.canceled = true; + source.tween.Complete(true); + break; + case TweenCancelBehaviour.CancelAwait: + source.RestoreOriginalCallback(); + source.core.TrySetCanceled(source.cancellationToken); + break; + } + }, result); + } + TaskTracker.TrackActiveTask(result, 3); token = result.core.Version; @@ -255,77 +288,6 @@ void OnCompleteCallbackDelegate() } } - void OnUpdate() - { - originalUpdateAction?.Invoke(); - - if (!cancellationToken.IsCancellationRequested) - { - return; - } - - switch (this.cancelBehaviour) - { - case TweenCancelBehaviour.Kill: - default: - this.tween.Kill(false); - break; - case TweenCancelBehaviour.KillAndCancelAwait: - this.canceled = true; - this.tween.Kill(false); - break; - case TweenCancelBehaviour.KillWithCompleteCallback: - this.tween.Kill(true); - break; - case TweenCancelBehaviour.KillWithCompleteCallbackAndCancelAwait: - this.canceled = true; - this.tween.Kill(true); - break; - case TweenCancelBehaviour.Complete: - this.tween.Complete(false); - break; - case TweenCancelBehaviour.CompleteAndCancelAwait: - this.canceled = true; - this.tween.Complete(false); - break; - case TweenCancelBehaviour.CompleteWithSequenceCallback: - this.tween.Complete(true); - break; - case TweenCancelBehaviour.CompleteWithSequenceCallbackAndCancelAwait: - this.canceled = true; - this.tween.Complete(true); - break; - case TweenCancelBehaviour.CancelAwait: - // restore to original callback - switch (callbackType) - { - case CallbackType.Kill: - tween.onKill = originalCompleteAction; - break; - case CallbackType.Complete: - tween.onComplete = originalCompleteAction; - break; - case CallbackType.Pause: - tween.onPause = originalCompleteAction; - break; - case CallbackType.Play: - tween.onPlay = originalCompleteAction; - break; - case CallbackType.Rewind: - tween.onRewind = originalCompleteAction; - break; - case CallbackType.StepComplete: - tween.onStepComplete = originalCompleteAction; - break; - default: - break; - } - - this.core.TrySetCanceled(this.cancellationToken); - break; - } - } - static void DoCancelBeforeCreate(Tween tween, TweenCancelBehaviour tweenCancelBehaviour) { @@ -392,8 +354,18 @@ bool TryReturn() { TaskTracker.RemoveTracking(this); core.Reset(); - tween.onUpdate = originalUpdateAction; + cancellationRegistration.Dispose(); + + RestoreOriginalCallback(); + + tween = default; + cancellationToken = default; + originalCompleteAction = default; + return pool.TryPush(this); + } + void RestoreOriginalCallback() + { switch (callbackType) { case CallbackType.Kill: @@ -417,12 +389,6 @@ bool TryReturn() default: break; } - - tween = default; - cancellationToken = default; - originalUpdateAction = default; - originalCompleteAction = default; - return pool.TryPush(this); } } } diff --git a/Runtime/Plugins/UniTask/Runtime/External/DOTween/DOTweenAsyncExtensions.cs.meta b/Runtime/Plugins/UniTask/Runtime/External/DOTween/DOTweenAsyncExtensions.cs.meta index 02ef2c6f..63131b04 100644 --- a/Runtime/Plugins/UniTask/Runtime/External/DOTween/DOTweenAsyncExtensions.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/External/DOTween/DOTweenAsyncExtensions.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 723feb5764c154d8d9d988aadd60476b +guid: 1f448d5bc5b232e4f98d89d5d1832e8e MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/External/DOTween/UniTask.DOTween.asmdef.meta b/Runtime/Plugins/UniTask/Runtime/External/DOTween/UniTask.DOTween.asmdef.meta index 88006aa4..427fe290 100644 --- a/Runtime/Plugins/UniTask/Runtime/External/DOTween/UniTask.DOTween.asmdef.meta +++ b/Runtime/Plugins/UniTask/Runtime/External/DOTween/UniTask.DOTween.asmdef.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 379adf41f5598409f83ca2525715f2b6 +guid: 029c1c1b674aaae47a6841a0b89ad80e AssemblyDefinitionImporter: externalObjects: {} userData: diff --git a/Runtime/Plugins/UniTask/Runtime/External/TextMeshPro.meta b/Runtime/Plugins/UniTask/Runtime/External/TextMeshPro.meta index 985e64ec..f3b281ce 100644 --- a/Runtime/Plugins/UniTask/Runtime/External/TextMeshPro.meta +++ b/Runtime/Plugins/UniTask/Runtime/External/TextMeshPro.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 32d987b0837f846999638807bbb58ad7 +guid: 3000d56e152ee4f8490e21e4ca34665e folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Runtime/Plugins/UniTask/Runtime/External/TextMeshPro/TextMeshProAsyncExtensions.InputField.cs.meta b/Runtime/Plugins/UniTask/Runtime/External/TextMeshPro/TextMeshProAsyncExtensions.InputField.cs.meta index 0c4607ff..2e39d2e8 100644 --- a/Runtime/Plugins/UniTask/Runtime/External/TextMeshPro/TextMeshProAsyncExtensions.InputField.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/External/TextMeshPro/TextMeshProAsyncExtensions.InputField.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: e24fd13ef7bfc4e9785edcb4c0c2b2dd +guid: 79f4f2475e0b2c44e97ed1dee760627b MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/External/TextMeshPro/TextMeshProAsyncExtensions.cs.meta b/Runtime/Plugins/UniTask/Runtime/External/TextMeshPro/TextMeshProAsyncExtensions.cs.meta index cca2e100..752d125c 100644 --- a/Runtime/Plugins/UniTask/Runtime/External/TextMeshPro/TextMeshProAsyncExtensions.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/External/TextMeshPro/TextMeshProAsyncExtensions.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: fac613b8b991f43bd95c7ecfecc2f6d9 +guid: b6ba480edafb67d4e91bb10feb64fae5 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/External/TextMeshPro/UniTask.TextMeshPro.asmdef.meta b/Runtime/Plugins/UniTask/Runtime/External/TextMeshPro/UniTask.TextMeshPro.asmdef.meta index 757ed7ec..4b59831d 100644 --- a/Runtime/Plugins/UniTask/Runtime/External/TextMeshPro/UniTask.TextMeshPro.asmdef.meta +++ b/Runtime/Plugins/UniTask/Runtime/External/TextMeshPro/UniTask.TextMeshPro.asmdef.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: bcddff3237d2a436f882a861852d9c98 +guid: dc47925d1a5fa2946bdd37746b2b5d48 AssemblyDefinitionImporter: externalObjects: {} userData: diff --git a/Runtime/Plugins/UniTask/Runtime/IUniTaskAsyncEnumerable.cs.meta b/Runtime/Plugins/UniTask/Runtime/IUniTaskAsyncEnumerable.cs.meta index 2fd9670f..12f0fe52 100644 --- a/Runtime/Plugins/UniTask/Runtime/IUniTaskAsyncEnumerable.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/IUniTaskAsyncEnumerable.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 24706c0b3bec34a238248bae410e40fa +guid: b20cf9f02ac585948a4372fa4ee06504 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/IUniTaskSource.cs.meta b/Runtime/Plugins/UniTask/Runtime/IUniTaskSource.cs.meta index fef67791..b225d1c7 100644 --- a/Runtime/Plugins/UniTask/Runtime/IUniTaskSource.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/IUniTaskSource.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 30d8064206fcf4c78a681f3b6c839af1 +guid: 3e4d023d8404ab742b5e808c98097c3c MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Internal.meta b/Runtime/Plugins/UniTask/Runtime/Internal.meta index 226b2002..98434369 100644 --- a/Runtime/Plugins/UniTask/Runtime/Internal.meta +++ b/Runtime/Plugins/UniTask/Runtime/Internal.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: deb6f0bc7f6024b5e81fa6597ba49f28 +guid: 9b8cd81208e344aed87c9a42137698e7 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Runtime/Plugins/UniTask/Runtime/Internal/ArrayPool.cs.meta b/Runtime/Plugins/UniTask/Runtime/Internal/ArrayPool.cs.meta index ec017dda..693816cc 100644 --- a/Runtime/Plugins/UniTask/Runtime/Internal/ArrayPool.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Internal/ArrayPool.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 2e4c55bf990ad4ec5b25ac79ce3d6f19 +guid: f83ebad81fb89fb4882331616ca6d248 timeCreated: 1532361008 licenseType: Free MonoImporter: diff --git a/Runtime/Plugins/UniTask/Runtime/Internal/ArrayPoolUtil.cs.meta b/Runtime/Plugins/UniTask/Runtime/Internal/ArrayPoolUtil.cs.meta index b8ad02db..e06ec652 100644 --- a/Runtime/Plugins/UniTask/Runtime/Internal/ArrayPoolUtil.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Internal/ArrayPoolUtil.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 1762575501ca24b709ef7e688582f07d +guid: 424cc208fb61d4e448b08fcfa0eee25e timeCreated: 1532361007 licenseType: Free MonoImporter: diff --git a/Runtime/Plugins/UniTask/Runtime/Internal/ArrayUtil.cs.meta b/Runtime/Plugins/UniTask/Runtime/Internal/ArrayUtil.cs.meta index 249f5d07..645fc4ed 100644 --- a/Runtime/Plugins/UniTask/Runtime/Internal/ArrayUtil.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Internal/ArrayUtil.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 9eb7f2d9267334fdc83db5350e5ef381 +guid: 23146a82ec99f2542a87971c8d3d7988 timeCreated: 1532361007 licenseType: Free MonoImporter: diff --git a/Runtime/Plugins/UniTask/Runtime/Internal/ContinuationQueue.cs.meta b/Runtime/Plugins/UniTask/Runtime/Internal/ContinuationQueue.cs.meta index 71d88d18..b04e5418 100644 --- a/Runtime/Plugins/UniTask/Runtime/Internal/ContinuationQueue.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Internal/ContinuationQueue.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 611d628808ef044f9a31f764220aa570 +guid: f66c32454e50f2546b17deadc80a4c77 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Internal/DiagnosticsExtensions.cs.meta b/Runtime/Plugins/UniTask/Runtime/Internal/DiagnosticsExtensions.cs.meta index ec39c1d4..6c1f06c2 100644 --- a/Runtime/Plugins/UniTask/Runtime/Internal/DiagnosticsExtensions.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Internal/DiagnosticsExtensions.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: aed102a50ce6047e5957707b637e721e +guid: f80fb1c9ed4c99447be1b0a47a8d980b MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Internal/Error.cs b/Runtime/Plugins/UniTask/Runtime/Internal/Error.cs index 5c7bc93b..9664491e 100644 --- a/Runtime/Plugins/UniTask/Runtime/Internal/Error.cs +++ b/Runtime/Plugins/UniTask/Runtime/Internal/Error.cs @@ -39,7 +39,7 @@ public static Exception MoreThanOneElement() } [MethodImpl(MethodImplOptions.NoInlining)] - public static void ThrowArgumentException(string message) + public static void ThrowArgumentException(string message) { throw new ArgumentException(message); } diff --git a/Runtime/Plugins/UniTask/Runtime/Internal/Error.cs.meta b/Runtime/Plugins/UniTask/Runtime/Internal/Error.cs.meta index f8ded3c7..2e5d219a 100644 --- a/Runtime/Plugins/UniTask/Runtime/Internal/Error.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Internal/Error.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: db3f01de5a2d14623ae6c1da4ef54cb4 +guid: 5f39f495294d4604b8082202faf98554 timeCreated: 1532361007 licenseType: Free MonoImporter: diff --git a/Runtime/Plugins/UniTask/Runtime/Internal/MinimumQueue.cs.meta b/Runtime/Plugins/UniTask/Runtime/Internal/MinimumQueue.cs.meta index 99910884..dc067367 100644 --- a/Runtime/Plugins/UniTask/Runtime/Internal/MinimumQueue.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Internal/MinimumQueue.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: b81a153d6449d43baaf38a3fbf2ff64a +guid: 7d63add489ccc99498114d79702b904d MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Internal/PlayerLoopRunner.cs.meta b/Runtime/Plugins/UniTask/Runtime/Internal/PlayerLoopRunner.cs.meta index c24b6c54..603dbc93 100644 --- a/Runtime/Plugins/UniTask/Runtime/Internal/PlayerLoopRunner.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Internal/PlayerLoopRunner.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 18e9b12463d6b46b081d270376b2eae5 +guid: 340c6d420bb4f484aa8683415ea92571 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Internal/PooledDelegate.cs.meta b/Runtime/Plugins/UniTask/Runtime/Internal/PooledDelegate.cs.meta index 2c728d74..7f92aff4 100644 --- a/Runtime/Plugins/UniTask/Runtime/Internal/PooledDelegate.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Internal/PooledDelegate.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 08245a2cfb5c44e718f5b24dc14eb798 +guid: 8932579438742fa40b010edd412dbfba MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Internal/RuntimeHelpersAbstraction.cs.meta b/Runtime/Plugins/UniTask/Runtime/Internal/RuntimeHelpersAbstraction.cs.meta index 37ea0133..42543911 100644 --- a/Runtime/Plugins/UniTask/Runtime/Internal/RuntimeHelpersAbstraction.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Internal/RuntimeHelpersAbstraction.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 2b1eb460262b74130ad0e71d632b34dd +guid: 94975e4d4e0c0ea4ba787d3872ce9bb4 timeCreated: 1532361007 licenseType: Free MonoImporter: diff --git a/Runtime/Plugins/UniTask/Runtime/Internal/StatePool.cs.meta b/Runtime/Plugins/UniTask/Runtime/Internal/StatePool.cs.meta index ebad65f6..6779aa1e 100644 --- a/Runtime/Plugins/UniTask/Runtime/Internal/StatePool.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Internal/StatePool.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 59c18854b71e14a02b801240afb7206b +guid: 60cdf0bcaea36b444a7ae7263ae7598f MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Internal/TaskTracker.cs.meta b/Runtime/Plugins/UniTask/Runtime/Internal/TaskTracker.cs.meta index 366de860..5563bf78 100644 --- a/Runtime/Plugins/UniTask/Runtime/Internal/TaskTracker.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Internal/TaskTracker.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 4e995db5acdeb4dcb8083f2c3e1f8d1b +guid: a203c73eb4ccdbb44bddfd82d38fdda9 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Internal/UnityEqualityComparer.cs.meta b/Runtime/Plugins/UniTask/Runtime/Internal/UnityEqualityComparer.cs.meta index 57ae8a6b..79eb04f6 100644 --- a/Runtime/Plugins/UniTask/Runtime/Internal/UnityEqualityComparer.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Internal/UnityEqualityComparer.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: a746f255a4f4b413cbdf3c8d339056b1 +guid: ebaaf14253c9cfb47b23283218ff9b67 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Internal/UnityWebRequestExtensions.cs.meta b/Runtime/Plugins/UniTask/Runtime/Internal/UnityWebRequestExtensions.cs.meta index 80ac856c..54bd2eb5 100644 --- a/Runtime/Plugins/UniTask/Runtime/Internal/UnityWebRequestExtensions.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Internal/UnityWebRequestExtensions.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: a29b6d6e34dae462b916d824000955de +guid: 111ba0e639de1d7428af6c823ead4918 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Internal/ValueStopwatch.cs.meta b/Runtime/Plugins/UniTask/Runtime/Internal/ValueStopwatch.cs.meta index 12e6ba16..b7c6b09c 100644 --- a/Runtime/Plugins/UniTask/Runtime/Internal/ValueStopwatch.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Internal/ValueStopwatch.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 176a55bc1c42140c9890c7d0e1b9c9dd +guid: f16fb466974ad034c8732c79c7fd67ea MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Internal/WeakDictionary.cs.meta b/Runtime/Plugins/UniTask/Runtime/Internal/WeakDictionary.cs.meta index f552ec77..9dc1672a 100644 --- a/Runtime/Plugins/UniTask/Runtime/Internal/WeakDictionary.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Internal/WeakDictionary.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 4b58d363fe90b4a8ca04afd3a10934ef +guid: 6c78563864409714593226af59bcb6f3 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq.meta b/Runtime/Plugins/UniTask/Runtime/Linq.meta index 17962c41..84c6b809 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 49c52f5b7b3c145a2b7e9148b51771a1 +guid: 16e777c0358454462bac054378120a6b folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Aggregate.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Aggregate.cs.meta index 1bb87889..837df4a9 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Aggregate.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Aggregate.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: fa9a14e95f1484a2d90d4f7f8491800e +guid: 5dc68c05a4228c643937f6ebd185bcca MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/All.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/All.cs.meta index d69ee70b..d378ff0e 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/All.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/All.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: eaf904b22414c4fbdb39d74246aee47b +guid: 7271437e0033af2448b600ee248924dd MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Any.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Any.cs.meta index d19f524c..1070bcc8 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Any.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Any.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: dd542510044d6414cbdfae0bc4bb0f1a +guid: e2b2e65745263994fbe34f3e0ec8eb12 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/AppendPrepend.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/AppendPrepend.cs.meta index 3ad9dc0b..6d2ee046 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/AppendPrepend.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/AppendPrepend.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 505bef489ec554ad0973ee93c446b305 +guid: 3268ec424b8055f45aa2a26d17c80468 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/AsUniTaskAsyncEnumerable.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/AsUniTaskAsyncEnumerable.cs.meta index 30058bb8..90f6207c 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/AsUniTaskAsyncEnumerable.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/AsUniTaskAsyncEnumerable.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: bc8583baaeda445c9b7898899e94e911 +guid: 69866e262589ea643bbc62a1d696077a MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/AsyncEnumeratorBase.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/AsyncEnumeratorBase.cs.meta index d3a3f41b..a4e96dc0 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/AsyncEnumeratorBase.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/AsyncEnumeratorBase.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 1bda87df02af740f3a54c10463e0aaf0 +guid: 01ba1d3b17e13fb4c95740131c7e6e19 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Average.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Average.cs.meta index ff37945d..8f60dfc5 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Average.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Average.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: a7c6cd0051ef143f986abc47b37a0760 +guid: 58499f95012fb3c47bb7bcbc5862e562 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Buffer.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Buffer.cs.meta index 1f4d0841..e7154e4d 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Buffer.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Buffer.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 873316a95d2c8424d8950328d32684fc +guid: 951310243334a3148a7872977cb31c5c MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Cast.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Cast.cs.meta index 6f302567..913b043c 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Cast.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Cast.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: eb968bbccf79d46878380c36bb08c45b +guid: edebeae8b61352b428abe9ce8f3fc71a MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/CombineLatest.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/CombineLatest.cs.meta index 448f206a..4e8b1c34 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/CombineLatest.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/CombineLatest.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 46f7a2abd48224fd0939e595500ade2e +guid: 6cb07f6e88287e34d9b9301a572284a5 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Concat.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Concat.cs.meta index 9da3d067..6bfcf318 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Concat.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Concat.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: abb661f299c144fc0a5f98c51ab16493 +guid: 7cb9e19c449127a459851a135ce7d527 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Contains.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Contains.cs.meta index e8d3ae62..9bd414b3 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Contains.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Contains.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: aec551cf769b443cc85b7752a88cde33 +guid: 36ab06d30f3223048b4f676e05431a7f MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Count.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Count.cs.meta index a36c40b0..35db3324 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Count.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Count.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 432afad2af1cc4b6fbb7d369bc296314 +guid: e606d38eed688574bb2ba89d983cc9bb MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Create.cs b/Runtime/Plugins/UniTask/Runtime/Linq/Create.cs index 61b7afd3..fa34774a 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Create.cs +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Create.cs @@ -52,6 +52,7 @@ public _Create(Func, CancellationToken, UniTask> create, Cancell public UniTask DisposeAsync() { TaskTracker.RemoveTracking(this); + writer.Dispose(); return default; } @@ -127,7 +128,7 @@ public void SetResult(T value) } } - sealed class AsyncWriter : IUniTaskSource, IAsyncWriter + sealed class AsyncWriter : IUniTaskSource, IAsyncWriter, IDisposable { readonly _Create enumerator; @@ -137,6 +138,15 @@ public AsyncWriter(_Create enumerator) { this.enumerator = enumerator; } + + public void Dispose() + { + var status = core.GetStatus(core.Version); + if (status == UniTaskStatus.Pending) + { + core.TrySetCanceled(); + } + } public void GetResult(short token) { diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Create.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Create.cs.meta index 32e3de91..5aba456f 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Create.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Create.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 510ed9b9c8bb146dba31f52d4777d517 +guid: 0202f723469f93945afa063bfb440d15 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/DefaultIfEmpty.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/DefaultIfEmpty.cs.meta index c4923431..5aa59939 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/DefaultIfEmpty.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/DefaultIfEmpty.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 3b099d406639b4f8eb92e4e001e11f0f +guid: 19e437c039ad7e1478dbce1779ef8660 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Distinct.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Distinct.cs.meta index b677c3dc..61804b7f 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Distinct.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Distinct.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 835dfcda4f86c42928b16b8912ddedbe +guid: 8f09903be66e5d943b243d7c19cb3811 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/DistinctUntilChanged.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/DistinctUntilChanged.cs.meta index 61ce6e74..84cddf8d 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/DistinctUntilChanged.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/DistinctUntilChanged.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 5705cb2b14bb24792bd585334797e143 +guid: 0351f6767df7e644b935d4d599968162 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Do.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Do.cs.meta index 6091c31c..766bbb5f 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Do.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Do.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: b82c105749c7c4ac7bc2ff861c90f292 +guid: dd83c8e12dedf75409b829b93146d130 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/ElementAt.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/ElementAt.cs.meta index 33838d24..fb0850b6 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/ElementAt.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/ElementAt.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 63b84e9a00c96452ab1eb85d3fd357ea +guid: c835bd2dd8555234c8919c7b8ef3b69a MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Empty.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Empty.cs.meta index 8114a5fa..bfa577ac 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Empty.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Empty.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 5fa012cfc8578411fa2dcedffc464fb9 +guid: 4fa123ad6258abb4184721b719a13810 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Except.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Except.cs.meta index 7e4e9f1c..f61a1aab 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Except.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Except.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 083be680d35c940188ba825cd85116a6 +guid: 38c1c4129f59dcb49a5b864eaf4ec63c MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/First.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/First.cs.meta index 463cdd98..6924307a 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/First.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/First.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 1f512525f32364c539fc525dce70b111 +guid: 417946e97e9eed84db6f840f57037ca6 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/ForEach.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/ForEach.cs.meta index 3c520a45..53177562 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/ForEach.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/ForEach.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 28e73d3585f3c49b88a59ecdfde8ed1f +guid: ca8d7f8177ba16140920af405aea3fd4 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/GroupBy.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/GroupBy.cs.meta index 72d87686..14897018 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/GroupBy.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/GroupBy.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 7f8a59d6f12a7465f850194b9663ce68 +guid: a2de80df1cc8a1240ab0ee7badd334d0 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/GroupJoin.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/GroupJoin.cs.meta index 3785e0e4..f171ed19 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/GroupJoin.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/GroupJoin.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: f0a3252eeddbf4415acc771696b3e548 +guid: 7bf7759d03bf3f64190d3ae83b182c2c MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Intersect.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Intersect.cs.meta index 434bc31f..28cf8e30 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Intersect.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Intersect.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: a3d1fe9a183174198947f7ac05f972a1 +guid: 93999a70f5d57134bbe971f3e988c4f2 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Join.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Join.cs.meta index eef7d470..3ab1015a 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Join.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Join.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 24997b01ff0234c2cb8d642fd10dcc21 +guid: dc4ff8cb6d7c9a64896f2f082124d6b3 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Last.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Last.cs.meta index 3112d2ab..edfa124a 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Last.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Last.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 5c639f428fc2a4dc894df3e20caecad6 +guid: a0ccc93be1387fa4a975f06310127c11 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/LongCount.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/LongCount.cs.meta index 414b5856..862c2bcf 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/LongCount.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/LongCount.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: a0288a67a79f347f084e17ae0af821fb +guid: 198b39e58ced3ab4f97ccbe0916787d5 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Max.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Max.cs.meta index 25a071e4..2125edf6 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Max.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Max.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 8242bb34fd368426cac760f0d2958712 +guid: 5c8a118a6b664c441820b8a87d7f6e28 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Merge.cs b/Runtime/Plugins/UniTask/Runtime/Linq/Merge.cs new file mode 100644 index 00000000..d4ea969a --- /dev/null +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Merge.cs @@ -0,0 +1,232 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using Cysharp.Threading.Tasks.Internal; + +namespace Cysharp.Threading.Tasks.Linq +{ + public static partial class UniTaskAsyncEnumerable + { + public static IUniTaskAsyncEnumerable Merge(this IUniTaskAsyncEnumerable first, IUniTaskAsyncEnumerable second) + { + Error.ThrowArgumentNullException(first, nameof(first)); + Error.ThrowArgumentNullException(second, nameof(second)); + + return new Merge(new [] { first, second }); + } + + public static IUniTaskAsyncEnumerable Merge(this IUniTaskAsyncEnumerable first, IUniTaskAsyncEnumerable second, IUniTaskAsyncEnumerable third) + { + Error.ThrowArgumentNullException(first, nameof(first)); + Error.ThrowArgumentNullException(second, nameof(second)); + Error.ThrowArgumentNullException(third, nameof(third)); + + return new Merge(new[] { first, second, third }); + } + + public static IUniTaskAsyncEnumerable Merge(this IEnumerable> sources) + { + return new Merge(sources.ToArray()); + } + + public static IUniTaskAsyncEnumerable Merge(params IUniTaskAsyncEnumerable[] sources) + { + return new Merge(sources); + } + } + + internal sealed class Merge : IUniTaskAsyncEnumerable + { + readonly IUniTaskAsyncEnumerable[] sources; + + public Merge(IUniTaskAsyncEnumerable[] sources) + { + if (sources.Length <= 0) + { + Error.ThrowArgumentException("No source async enumerable to merge"); + } + this.sources = sources; + } + + public IUniTaskAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) + => new _Merge(sources, cancellationToken); + + enum MergeSourceState + { + Pending, + Running, + Completed, + } + + sealed class _Merge : MoveNextSource, IUniTaskAsyncEnumerator + { + static readonly Action GetResultAtAction = GetResultAt; + + readonly int length; + readonly IUniTaskAsyncEnumerator[] enumerators; + readonly MergeSourceState[] states; + readonly Queue<(T, Exception, bool)> queuedResult = new Queue<(T, Exception, bool)>(); + readonly CancellationToken cancellationToken; + + int moveNextCompleted; + + public T Current { get; private set; } + + public _Merge(IUniTaskAsyncEnumerable[] sources, CancellationToken cancellationToken) + { + this.cancellationToken = cancellationToken; + length = sources.Length; + states = ArrayPool.Shared.Rent(length); + enumerators = ArrayPool>.Shared.Rent(length); + for (var i = 0; i < length; i++) + { + enumerators[i] = sources[i].GetAsyncEnumerator(cancellationToken); + states[i] = (int)MergeSourceState.Pending;; + } + } + + public UniTask MoveNextAsync() + { + cancellationToken.ThrowIfCancellationRequested(); + completionSource.Reset(); + Interlocked.Exchange(ref moveNextCompleted, 0); + + if (HasQueuedResult() && Interlocked.CompareExchange(ref moveNextCompleted, 1, 0) == 0) + { + (T, Exception, bool) value; + lock (states) + { + value = queuedResult.Dequeue(); + } + var resultValue = value.Item1; + var exception = value.Item2; + var hasNext = value.Item3; + if (exception != null) + { + completionSource.TrySetException(exception); + } + else + { + Current = resultValue; + completionSource.TrySetResult(hasNext); + } + return new UniTask(this, completionSource.Version); + } + + for (var i = 0; i < length; i++) + { + lock (states) + { + if (states[i] == MergeSourceState.Pending) + { + states[i] = MergeSourceState.Running; + } + else + { + continue; + } + } + var awaiter = enumerators[i].MoveNextAsync().GetAwaiter(); + if (awaiter.IsCompleted) + { + GetResultAt(i, awaiter); + } + else + { + awaiter.SourceOnCompleted(GetResultAtAction, StateTuple.Create(this, i, awaiter)); + } + } + return new UniTask(this, completionSource.Version); + } + + public async UniTask DisposeAsync() + { + for (var i = 0; i < length; i++) + { + await enumerators[i].DisposeAsync(); + } + + ArrayPool.Shared.Return(states, true); + ArrayPool>.Shared.Return(enumerators, true); + } + + static void GetResultAt(object state) + { + using (var tuple = (StateTuple<_Merge, int, UniTask.Awaiter>)state) + { + tuple.Item1.GetResultAt(tuple.Item2, tuple.Item3); + } + } + + void GetResultAt(int index, UniTask.Awaiter awaiter) + { + bool hasNext; + bool completedAll; + try + { + hasNext = awaiter.GetResult(); + } + catch (Exception ex) + { + if (Interlocked.CompareExchange(ref moveNextCompleted, 1, 0) == 0) + { + completionSource.TrySetException(ex); + } + else + { + lock (states) + { + queuedResult.Enqueue((default, ex, default)); + } + } + return; + } + + lock (states) + { + states[index] = hasNext ? MergeSourceState.Pending : MergeSourceState.Completed; + completedAll = !hasNext && IsCompletedAll(); + } + if (hasNext || completedAll) + { + if (Interlocked.CompareExchange(ref moveNextCompleted, 1, 0) == 0) + { + Current = enumerators[index].Current; + completionSource.TrySetResult(!completedAll); + } + else + { + lock (states) + { + queuedResult.Enqueue((enumerators[index].Current, null, !completedAll)); + } + } + } + } + + bool HasQueuedResult() + { + lock (states) + { + return queuedResult.Count > 0; + } + } + + bool IsCompletedAll() + { + lock (states) + { + for (var i = 0; i < length; i++) + { + if (states[i] != MergeSourceState.Completed) + { + return false; + } + } + } + return true; + } + } + } +} \ No newline at end of file diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Merge.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Merge.cs.meta new file mode 100644 index 00000000..2f671f4c --- /dev/null +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Merge.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ca56812f160c45d0bacb4339819edf1a +timeCreated: 1694133666 \ No newline at end of file diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Min.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Min.cs.meta index fa2ef2ca..91378dc9 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Min.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Min.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: c732c699b2e784cfbadc52cbd46e755e +guid: 57ac9da21d3457849a8e45548290a508 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/MinMax.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/MinMax.cs.meta index 3480d4f5..3856b65f 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/MinMax.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/MinMax.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: c977f90f8d35143deb73d606bcd0d70f +guid: 2d6da02d9ab970e4999daf7147d98e36 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Never.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Never.cs.meta index ae2c7a81..ba9d358c 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Never.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Never.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: cdf187809f6294bf4a60b021cfd31a67 +guid: 8b307c3d3be71a94da251564bcdefa3d MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/OfType.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/OfType.cs.meta index 63488435..6ace53fd 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/OfType.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/OfType.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 72c99a00c5e7c4090b6979e9145574a5 +guid: 111ffe87a7d700442a9ef5af554b252c MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/OrderBy.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/OrderBy.cs.meta index 07683d45..5c6b3e4a 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/OrderBy.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/OrderBy.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 96859dbdd7ebb40c4af2d95774ff0d27 +guid: 413883ceff8546143bdf200aafa4b8f7 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Pairwise.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Pairwise.cs.meta index 7654caef..727b8cf4 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Pairwise.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Pairwise.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: c2cc7af39f78243048442cd5f3d7dd44 +guid: cddbf051d2a88f549986c468b23214af MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Publish.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Publish.cs.meta index 5fcc2506..f3a81ba3 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Publish.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Publish.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: f2b23922dd92948819b85841ad2a53f8 +guid: 93c684d1e88c09d4e89b79437d97b810 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Queue.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Queue.cs.meta index 7f5df690..35f3fab2 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Queue.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Queue.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 0420b0019e39b43ae95a7a9cca19a9cb +guid: b7ea1bcf9dbebb042bc99c7816249e02 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Range.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Range.cs.meta index 646a94be..36272fcf 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Range.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Range.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 931cceefbded043f0a363f72a9d8c328 +guid: d826418a813498648b10542d0a5fb173 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Repeat.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Repeat.cs.meta index dd7de0b0..693d5790 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Repeat.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Repeat.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: e738c31144f45401a8c2564020afe8a3 +guid: 3819a3925165a674d80ee848c8600379 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Return.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Return.cs.meta index 0c3308db..ad264d0d 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Return.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Return.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 920a9f7713eed4e63b60504a9d37ec78 +guid: 4313cd8ecf705e44f9064ce46e293c2c MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Reverse.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Reverse.cs.meta index e4a40ee3..4a28306a 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Reverse.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Reverse.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 8fbec1f19945644a098cb1115f725ba9 +guid: b2769e65c729b4f4ca6af9826d9c7b90 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Select.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Select.cs.meta index ef861863..476e9723 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Select.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Select.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 6fe3e07e3aeef41a380675a8441a64d2 +guid: dc68e598ca44a134b988dfaf5e53bfba MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/SelectMany.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/SelectMany.cs.meta index ac8e9d0b..a8dbbaf6 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/SelectMany.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/SelectMany.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 3ade0bdc8c41646c299ee2f677e93a7f +guid: d81862f0eb12680479ccaaf2ac319d24 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/SequenceEqual.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/SequenceEqual.cs.meta index 71cdffea..ee2b75c2 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/SequenceEqual.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/SequenceEqual.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 9c1bc70e42d1b4448a699eb7bcc1ffeb +guid: b382772aba6128842928cdb6b2e034b0 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Single.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Single.cs.meta index 028d8e69..c053dfd7 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Single.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Single.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 5348c0bf7ce21443abf80dcc379b8771 +guid: 1bcd3928b90472e43a3a92c3ba708967 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Skip.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Skip.cs.meta index f8401f2b..25ad847b 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Skip.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Skip.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: a48593544b06c44f1ba3cd54eb98997e +guid: 9c46b6c7dce0cb049a73c81084c75154 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/SkipLast.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/SkipLast.cs.meta index 11f8438b..06b1ede4 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/SkipLast.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/SkipLast.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: c14d8909af6f843a6b22f274b3a45772 +guid: df1d7f44d4fe7754f972c9e0b6fa72d5 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/SkipUntil.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/SkipUntil.cs.meta index 85c9d039..0772ed01 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/SkipUntil.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/SkipUntil.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: c4d07b784b6e046d8a5b87d527468627 +guid: de932d79c8d9f3841a066d05ff29edc9 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/SkipUntilCanceled.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/SkipUntilCanceled.cs.meta index 37bd7870..9f67181d 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/SkipUntilCanceled.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/SkipUntilCanceled.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 63e3641a21cb848e4af02b6046a4dfd1 +guid: 4b1a778aef7150d47b93a49aa1bc34ae MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/SkipWhile.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/SkipWhile.cs.meta index 0e965d94..f2b210a9 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/SkipWhile.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/SkipWhile.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 9a869ffb7f35640b4ab54139d133ae79 +guid: 0b74b9fe361bf7148b51a29c8b2561e8 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Subscribe.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Subscribe.cs.meta index e058fe00..ea835671 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Subscribe.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Subscribe.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: ce37c72d03ed34261b9d57b8c550101b +guid: 263479eb04c189741931fc0e2f615c2d MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Sum.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Sum.cs.meta index 9e7c655a..5331e349 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Sum.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Sum.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: e3329dc74cbc645dabc41210cc54da5d +guid: 4149754066a21a341be58c04357061f6 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Take.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Take.cs.meta index 11379c8e..1cc91ab0 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Take.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Take.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 1aea02ca2d431470ebdbfa6e289c36c0 +guid: 42f02cb84e5875b488304755d0e1383d MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/TakeLast.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/TakeLast.cs.meta index 1e657ec0..d80037f4 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/TakeLast.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/TakeLast.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 3464752ce0c584bf4bd8db4fd7254471 +guid: 510aa9fd35b45fc40bcdb7e59f01fd1b MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/TakeUntil.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/TakeUntil.cs.meta index 89592876..44cf63e1 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/TakeUntil.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/TakeUntil.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: e8393d34d923f48e7b42f37ee258dcbf +guid: 12bda324162f15349afefc2c152ac07f MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/TakeUntilCanceled.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/TakeUntilCanceled.cs.meta index 7f17b861..4a89be54 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/TakeUntilCanceled.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/TakeUntilCanceled.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: cb558a30cd9cc4ac9be8b1ee451455ab +guid: e82f498cf3a1df04cbf646773fc11319 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/TakeWhile.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/TakeWhile.cs.meta index 1c151a12..f2173d59 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/TakeWhile.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/TakeWhile.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: b9546b37ff0184808b03b0baa0ef1ab6 +guid: bca55adabcc4b3141b50b8b09634f764 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Throw.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Throw.cs.meta index 65cf6a73..c768ef1e 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Throw.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Throw.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 4bff3e6ac05994e5eb727e09146dde25 +guid: 9d05a7d4f4161e549b4789e1022baae8 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/ToArray.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/ToArray.cs.meta index 7e4ad85c..679d61c9 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/ToArray.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/ToArray.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 2636dd420810741a994a9d66e82fe6bd +guid: debb010bbb1622e43b94fe70ec0133dd MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/ToDictionary.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/ToDictionary.cs.meta index 3f594861..4deed194 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/ToDictionary.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/ToDictionary.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: c751fb258afbb4fedbd45baa7060480a +guid: 03b109b1fe1f2df46aa56ffb26747654 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/ToHashSet.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/ToHashSet.cs.meta index bd59827c..8d3c4af2 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/ToHashSet.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/ToHashSet.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 7a30ba92292214aacae975c7151d2803 +guid: 7a3e552113af96e4986805ec3c4fc80a MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/ToList.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/ToList.cs.meta index 942b0c11..4f093738 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/ToList.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/ToList.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: e9ea08239c8f548268af240ee2e6adef +guid: 3859c1b31e81d9b44b282e7d97e11635 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/ToLookup.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/ToLookup.cs.meta index ad707a89..7dd8ecd6 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/ToLookup.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/ToLookup.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 6bbc7a186e1064c07abef0983b0cc27b +guid: 57da22563bcd6ca4aaf256d941de5cb0 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/ToObservable.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/ToObservable.cs.meta index c1240c6f..44d917e3 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/ToObservable.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/ToObservable.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 59348a3a80b03416e914f28a298d85d5 +guid: b4f6f48a532188e4c80b7ebe69aea3a8 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/ToUniTaskAsyncEnumerable.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/ToUniTaskAsyncEnumerable.cs.meta index 7f4f91e9..45fd3b08 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/ToUniTaskAsyncEnumerable.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/ToUniTaskAsyncEnumerable.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 82bd0d2a1244f4c6497fd021caf940c8 +guid: d7192de2a0581ec4db62962cc1404af5 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/UniTask.Linq.asmdef.meta b/Runtime/Plugins/UniTask/Runtime/Linq/UniTask.Linq.asmdef.meta index 5422d111..1c85d19e 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/UniTask.Linq.asmdef.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/UniTask.Linq.asmdef.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 8920186e22a12415392e832bf77aad0a +guid: 5c01796d064528144a599661eaab93a6 AssemblyDefinitionImporter: externalObjects: {} userData: diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Union.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Union.cs.meta index 741314c2..1d9c7adb 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Union.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Union.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 94f726d8d96fb430fae93453be8c9ea9 +guid: ae57a55bdeba98b4f8ff234d98d7dd76 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/UnityExtensions.meta b/Runtime/Plugins/UniTask/Runtime/Linq/UnityExtensions.meta index 1e0f4577..fd5b8fef 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/UnityExtensions.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/UnityExtensions.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 971afa354d7b04bd1970813cf2924613 +guid: f082b6b4912784efd9c3e7911c4968a8 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/UnityExtensions/EveryUpdate.cs b/Runtime/Plugins/UniTask/Runtime/Linq/UnityExtensions/EveryUpdate.cs index 585fff96..8f091100 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/UnityExtensions/EveryUpdate.cs +++ b/Runtime/Plugins/UniTask/Runtime/Linq/UnityExtensions/EveryUpdate.cs @@ -4,38 +4,50 @@ namespace Cysharp.Threading.Tasks.Linq { public static partial class UniTaskAsyncEnumerable { - public static IUniTaskAsyncEnumerable EveryUpdate(PlayerLoopTiming updateTiming = PlayerLoopTiming.Update) + public static IUniTaskAsyncEnumerable EveryUpdate(PlayerLoopTiming updateTiming = PlayerLoopTiming.Update, bool cancelImmediately = false) { - return new EveryUpdate(updateTiming); + return new EveryUpdate(updateTiming, cancelImmediately); } } internal class EveryUpdate : IUniTaskAsyncEnumerable { readonly PlayerLoopTiming updateTiming; + readonly bool cancelImmediately; - public EveryUpdate(PlayerLoopTiming updateTiming) + public EveryUpdate(PlayerLoopTiming updateTiming, bool cancelImmediately) { this.updateTiming = updateTiming; + this.cancelImmediately = cancelImmediately; } public IUniTaskAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) { - return new _EveryUpdate(updateTiming, cancellationToken); + return new _EveryUpdate(updateTiming, cancellationToken, cancelImmediately); } class _EveryUpdate : MoveNextSource, IUniTaskAsyncEnumerator, IPlayerLoopItem { readonly PlayerLoopTiming updateTiming; - CancellationToken cancellationToken; + readonly CancellationToken cancellationToken; + readonly CancellationTokenRegistration cancellationTokenRegistration; bool disposed; - public _EveryUpdate(PlayerLoopTiming updateTiming, CancellationToken cancellationToken) + public _EveryUpdate(PlayerLoopTiming updateTiming, CancellationToken cancellationToken, bool cancelImmediately) { this.updateTiming = updateTiming; this.cancellationToken = cancellationToken; + if (cancelImmediately && cancellationToken.CanBeCanceled) + { + cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => + { + var source = (_EveryUpdate)state; + source.completionSource.TrySetCanceled(source.cancellationToken); + }, this); + } + TaskTracker.TrackActiveTask(this, 2); PlayerLoopHelper.AddAction(updateTiming, this); } @@ -44,10 +56,14 @@ public _EveryUpdate(PlayerLoopTiming updateTiming, CancellationToken cancellatio public UniTask MoveNextAsync() { - // return false instead of throw - if (disposed || cancellationToken.IsCancellationRequested) return CompletedTasks.False; - + if (disposed) return CompletedTasks.False; + completionSource.Reset(); + + if (cancellationToken.IsCancellationRequested) + { + completionSource.TrySetCanceled(cancellationToken); + } return new UniTask(this, completionSource.Version); } @@ -55,6 +71,7 @@ public UniTask DisposeAsync() { if (!disposed) { + cancellationTokenRegistration.Dispose(); disposed = true; TaskTracker.RemoveTracking(this); } @@ -63,7 +80,13 @@ public UniTask DisposeAsync() public bool MoveNext() { - if (disposed || cancellationToken.IsCancellationRequested) + if (cancellationToken.IsCancellationRequested) + { + completionSource.TrySetCanceled(cancellationToken); + return false; + } + + if (disposed) { completionSource.TrySetResult(false); return false; diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/UnityExtensions/EveryUpdate.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/UnityExtensions/EveryUpdate.cs.meta index a934722d..6336e0e3 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/UnityExtensions/EveryUpdate.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/UnityExtensions/EveryUpdate.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 4549ba713316245a7aabc9a4df9a9828 +guid: 00520eb52e49b5b4e8d9870d6ff1aced MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/UnityExtensions/EveryValueChanged.cs b/Runtime/Plugins/UniTask/Runtime/Linq/UnityExtensions/EveryValueChanged.cs index f678e7aa..ef5739c7 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/UnityExtensions/EveryValueChanged.cs +++ b/Runtime/Plugins/UniTask/Runtime/Linq/UnityExtensions/EveryValueChanged.cs @@ -7,7 +7,7 @@ namespace Cysharp.Threading.Tasks.Linq { public static partial class UniTaskAsyncEnumerable { - public static IUniTaskAsyncEnumerable EveryValueChanged(TTarget target, Func propertySelector, PlayerLoopTiming monitorTiming = PlayerLoopTiming.Update, IEqualityComparer equalityComparer = null) + public static IUniTaskAsyncEnumerable EveryValueChanged(TTarget target, Func propertySelector, PlayerLoopTiming monitorTiming = PlayerLoopTiming.Update, IEqualityComparer equalityComparer = null, bool cancelImmediately = false) where TTarget : class { var unityObject = target as UnityEngine.Object; @@ -15,11 +15,11 @@ public static IUniTaskAsyncEnumerable EveryValueChanged(target, propertySelector, equalityComparer ?? UnityEqualityComparer.GetDefault(), monitorTiming); + return new EveryValueChangedUnityObject(target, propertySelector, equalityComparer ?? UnityEqualityComparer.GetDefault(), monitorTiming, cancelImmediately); } else { - return new EveryValueChangedStandardObject(target, propertySelector, equalityComparer ?? UnityEqualityComparer.GetDefault(), monitorTiming); + return new EveryValueChangedStandardObject(target, propertySelector, equalityComparer ?? UnityEqualityComparer.GetDefault(), monitorTiming, cancelImmediately); } } } @@ -30,18 +30,20 @@ internal sealed class EveryValueChangedUnityObject : IUniTas readonly Func propertySelector; readonly IEqualityComparer equalityComparer; readonly PlayerLoopTiming monitorTiming; + readonly bool cancelImmediately; - public EveryValueChangedUnityObject(TTarget target, Func propertySelector, IEqualityComparer equalityComparer, PlayerLoopTiming monitorTiming) + public EveryValueChangedUnityObject(TTarget target, Func propertySelector, IEqualityComparer equalityComparer, PlayerLoopTiming monitorTiming, bool cancelImmediately) { this.target = target; this.propertySelector = propertySelector; this.equalityComparer = equalityComparer; this.monitorTiming = monitorTiming; + this.cancelImmediately = cancelImmediately; } public IUniTaskAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) { - return new _EveryValueChanged(target, propertySelector, equalityComparer, monitorTiming, cancellationToken); + return new _EveryValueChanged(target, propertySelector, equalityComparer, monitorTiming, cancellationToken, cancelImmediately); } sealed class _EveryValueChanged : MoveNextSource, IUniTaskAsyncEnumerator, IPlayerLoopItem @@ -50,13 +52,14 @@ sealed class _EveryValueChanged : MoveNextSource, IUniTaskAsyncEnumerator equalityComparer; readonly Func propertySelector; - CancellationToken cancellationToken; + readonly CancellationToken cancellationToken; + readonly CancellationTokenRegistration cancellationTokenRegistration; bool first; TProperty currentValue; bool disposed; - public _EveryValueChanged(TTarget target, Func propertySelector, IEqualityComparer equalityComparer, PlayerLoopTiming monitorTiming, CancellationToken cancellationToken) + public _EveryValueChanged(TTarget target, Func propertySelector, IEqualityComparer equalityComparer, PlayerLoopTiming monitorTiming, CancellationToken cancellationToken, bool cancelImmediately) { this.target = target; this.targetAsUnityObject = target as UnityEngine.Object; @@ -64,6 +67,16 @@ public _EveryValueChanged(TTarget target, Func propertySelec this.equalityComparer = equalityComparer; this.cancellationToken = cancellationToken; this.first = true; + + if (cancelImmediately && cancellationToken.CanBeCanceled) + { + cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => + { + var source = (_EveryValueChanged)state; + source.completionSource.TrySetCanceled(source.cancellationToken); + }, this); + } + TaskTracker.TrackActiveTask(this, 2); PlayerLoopHelper.AddAction(monitorTiming, this); } @@ -72,8 +85,15 @@ public _EveryValueChanged(TTarget target, Func propertySelec public UniTask MoveNextAsync() { - // return false instead of throw - if (disposed || cancellationToken.IsCancellationRequested) return CompletedTasks.False; + if (disposed) return CompletedTasks.False; + + completionSource.Reset(); + + if (cancellationToken.IsCancellationRequested) + { + completionSource.TrySetCanceled(cancellationToken); + return new UniTask(this, completionSource.Version); + } if (first) { @@ -86,7 +106,6 @@ public UniTask MoveNextAsync() return CompletedTasks.True; } - completionSource.Reset(); return new UniTask(this, completionSource.Version); } @@ -94,6 +113,7 @@ public UniTask DisposeAsync() { if (!disposed) { + cancellationTokenRegistration.Dispose(); disposed = true; TaskTracker.RemoveTracking(this); } @@ -102,13 +122,18 @@ public UniTask DisposeAsync() public bool MoveNext() { - if (disposed || cancellationToken.IsCancellationRequested || targetAsUnityObject == null) // destroyed = cancel. + if (disposed || targetAsUnityObject == null) { completionSource.TrySetResult(false); DisposeAsync().Forget(); return false; } - + + if (cancellationToken.IsCancellationRequested) + { + completionSource.TrySetCanceled(cancellationToken); + return false; + } TProperty nextValue = default(TProperty); try { @@ -139,18 +164,20 @@ internal sealed class EveryValueChangedStandardObject : IUni readonly Func propertySelector; readonly IEqualityComparer equalityComparer; readonly PlayerLoopTiming monitorTiming; + readonly bool cancelImmediately; - public EveryValueChangedStandardObject(TTarget target, Func propertySelector, IEqualityComparer equalityComparer, PlayerLoopTiming monitorTiming) + public EveryValueChangedStandardObject(TTarget target, Func propertySelector, IEqualityComparer equalityComparer, PlayerLoopTiming monitorTiming, bool cancelImmediately) { this.target = new WeakReference(target, false); this.propertySelector = propertySelector; this.equalityComparer = equalityComparer; this.monitorTiming = monitorTiming; + this.cancelImmediately = cancelImmediately; } public IUniTaskAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) { - return new _EveryValueChanged(target, propertySelector, equalityComparer, monitorTiming, cancellationToken); + return new _EveryValueChanged(target, propertySelector, equalityComparer, monitorTiming, cancellationToken, cancelImmediately); } sealed class _EveryValueChanged : MoveNextSource, IUniTaskAsyncEnumerator, IPlayerLoopItem @@ -158,19 +185,30 @@ sealed class _EveryValueChanged : MoveNextSource, IUniTaskAsyncEnumerator target; readonly IEqualityComparer equalityComparer; readonly Func propertySelector; - CancellationToken cancellationToken; + readonly CancellationToken cancellationToken; + readonly CancellationTokenRegistration cancellationTokenRegistration; bool first; TProperty currentValue; bool disposed; - public _EveryValueChanged(WeakReference target, Func propertySelector, IEqualityComparer equalityComparer, PlayerLoopTiming monitorTiming, CancellationToken cancellationToken) + public _EveryValueChanged(WeakReference target, Func propertySelector, IEqualityComparer equalityComparer, PlayerLoopTiming monitorTiming, CancellationToken cancellationToken, bool cancelImmediately) { this.target = target; this.propertySelector = propertySelector; this.equalityComparer = equalityComparer; this.cancellationToken = cancellationToken; this.first = true; + + if (cancelImmediately && cancellationToken.CanBeCanceled) + { + cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => + { + var source = (_EveryValueChanged)state; + source.completionSource.TrySetCanceled(source.cancellationToken); + }, this); + } + TaskTracker.TrackActiveTask(this, 2); PlayerLoopHelper.AddAction(monitorTiming, this); } @@ -179,8 +217,16 @@ public _EveryValueChanged(WeakReference target, Func MoveNextAsync() { - if (disposed || cancellationToken.IsCancellationRequested) return CompletedTasks.False; + if (disposed) return CompletedTasks.False; + completionSource.Reset(); + + if (cancellationToken.IsCancellationRequested) + { + completionSource.TrySetCanceled(cancellationToken); + return new UniTask(this, completionSource.Version); + } + if (first) { first = false; @@ -192,7 +238,6 @@ public UniTask MoveNextAsync() return CompletedTasks.True; } - completionSource.Reset(); return new UniTask(this, completionSource.Version); } @@ -200,6 +245,7 @@ public UniTask DisposeAsync() { if (!disposed) { + cancellationTokenRegistration.Dispose(); disposed = true; TaskTracker.RemoveTracking(this); } @@ -208,13 +254,19 @@ public UniTask DisposeAsync() public bool MoveNext() { - if (disposed || cancellationToken.IsCancellationRequested || !target.TryGetTarget(out var t)) + if (disposed || !target.TryGetTarget(out var t)) { completionSource.TrySetResult(false); DisposeAsync().Forget(); return false; } + if (cancellationToken.IsCancellationRequested) + { + completionSource.TrySetCanceled(cancellationToken); + return false; + } + TProperty nextValue = default(TProperty); try { diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/UnityExtensions/EveryValueChanged.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/UnityExtensions/EveryValueChanged.cs.meta index bf818159..9d2be702 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/UnityExtensions/EveryValueChanged.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/UnityExtensions/EveryValueChanged.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: a6291ccb8ffb24a43b2213e3fadf26cb +guid: 1ec39f1c41c305344854782c935ad354 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/UnityExtensions/Timer.cs b/Runtime/Plugins/UniTask/Runtime/Linq/UnityExtensions/Timer.cs index 53ecfcd7..b8aabf23 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/UnityExtensions/Timer.cs +++ b/Runtime/Plugins/UniTask/Runtime/Linq/UnityExtensions/Timer.cs @@ -6,32 +6,32 @@ namespace Cysharp.Threading.Tasks.Linq { public static partial class UniTaskAsyncEnumerable { - public static IUniTaskAsyncEnumerable Timer(TimeSpan dueTime, PlayerLoopTiming updateTiming = PlayerLoopTiming.Update, bool ignoreTimeScale = false) + public static IUniTaskAsyncEnumerable Timer(TimeSpan dueTime, PlayerLoopTiming updateTiming = PlayerLoopTiming.Update, bool ignoreTimeScale = false, bool cancelImmediately = false) { - return new Timer(dueTime, null, updateTiming, ignoreTimeScale); + return new Timer(dueTime, null, updateTiming, ignoreTimeScale, cancelImmediately); } - public static IUniTaskAsyncEnumerable Timer(TimeSpan dueTime, TimeSpan period, PlayerLoopTiming updateTiming = PlayerLoopTiming.Update, bool ignoreTimeScale = false) + public static IUniTaskAsyncEnumerable Timer(TimeSpan dueTime, TimeSpan period, PlayerLoopTiming updateTiming = PlayerLoopTiming.Update, bool ignoreTimeScale = false, bool cancelImmediately = false) { - return new Timer(dueTime, period, updateTiming, ignoreTimeScale); + return new Timer(dueTime, period, updateTiming, ignoreTimeScale, cancelImmediately); } - public static IUniTaskAsyncEnumerable Interval(TimeSpan period, PlayerLoopTiming updateTiming = PlayerLoopTiming.Update, bool ignoreTimeScale = false) + public static IUniTaskAsyncEnumerable Interval(TimeSpan period, PlayerLoopTiming updateTiming = PlayerLoopTiming.Update, bool ignoreTimeScale = false, bool cancelImmediately = false) { - return new Timer(period, period, updateTiming, ignoreTimeScale); + return new Timer(period, period, updateTiming, ignoreTimeScale, cancelImmediately); } - public static IUniTaskAsyncEnumerable TimerFrame(int dueTimeFrameCount, PlayerLoopTiming updateTiming = PlayerLoopTiming.Update) + public static IUniTaskAsyncEnumerable TimerFrame(int dueTimeFrameCount, PlayerLoopTiming updateTiming = PlayerLoopTiming.Update, bool cancelImmediately = false) { if (dueTimeFrameCount < 0) { throw new ArgumentOutOfRangeException("Delay does not allow minus delayFrameCount. dueTimeFrameCount:" + dueTimeFrameCount); } - return new TimerFrame(dueTimeFrameCount, null, updateTiming); + return new TimerFrame(dueTimeFrameCount, null, updateTiming, cancelImmediately); } - public static IUniTaskAsyncEnumerable TimerFrame(int dueTimeFrameCount, int periodFrameCount, PlayerLoopTiming updateTiming = PlayerLoopTiming.Update) + public static IUniTaskAsyncEnumerable TimerFrame(int dueTimeFrameCount, int periodFrameCount, PlayerLoopTiming updateTiming = PlayerLoopTiming.Update, bool cancelImmediately = false) { if (dueTimeFrameCount < 0) { @@ -42,16 +42,16 @@ public static IUniTaskAsyncEnumerable TimerFrame(int dueTimeFrameCoun throw new ArgumentOutOfRangeException("Delay does not allow minus periodFrameCount. periodFrameCount:" + dueTimeFrameCount); } - return new TimerFrame(dueTimeFrameCount, periodFrameCount, updateTiming); + return new TimerFrame(dueTimeFrameCount, periodFrameCount, updateTiming, cancelImmediately); } - public static IUniTaskAsyncEnumerable IntervalFrame(int intervalFrameCount, PlayerLoopTiming updateTiming = PlayerLoopTiming.Update) + public static IUniTaskAsyncEnumerable IntervalFrame(int intervalFrameCount, PlayerLoopTiming updateTiming = PlayerLoopTiming.Update, bool cancelImmediately = false) { if (intervalFrameCount < 0) { throw new ArgumentOutOfRangeException("Delay does not allow minus intervalFrameCount. intervalFrameCount:" + intervalFrameCount); } - return new TimerFrame(intervalFrameCount, intervalFrameCount, updateTiming); + return new TimerFrame(intervalFrameCount, intervalFrameCount, updateTiming, cancelImmediately); } } @@ -61,18 +61,20 @@ internal class Timer : IUniTaskAsyncEnumerable readonly TimeSpan dueTime; readonly TimeSpan? period; readonly bool ignoreTimeScale; + readonly bool cancelImmediately; - public Timer(TimeSpan dueTime, TimeSpan? period, PlayerLoopTiming updateTiming, bool ignoreTimeScale) + public Timer(TimeSpan dueTime, TimeSpan? period, PlayerLoopTiming updateTiming, bool ignoreTimeScale, bool cancelImmediately) { this.updateTiming = updateTiming; this.dueTime = dueTime; this.period = period; this.ignoreTimeScale = ignoreTimeScale; + this.cancelImmediately = cancelImmediately; } public IUniTaskAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) { - return new _Timer(dueTime, period, updateTiming, ignoreTimeScale, cancellationToken); + return new _Timer(dueTime, period, updateTiming, ignoreTimeScale, cancellationToken, cancelImmediately); } class _Timer : MoveNextSource, IUniTaskAsyncEnumerator, IPlayerLoopItem @@ -81,7 +83,8 @@ class _Timer : MoveNextSource, IUniTaskAsyncEnumerator, IPlayerLoopIt readonly float? period; readonly PlayerLoopTiming updateTiming; readonly bool ignoreTimeScale; - CancellationToken cancellationToken; + readonly CancellationToken cancellationToken; + readonly CancellationTokenRegistration cancellationTokenRegistration; int initialFrame; float elapsed; @@ -89,7 +92,7 @@ class _Timer : MoveNextSource, IUniTaskAsyncEnumerator, IPlayerLoopIt bool completed; bool disposed; - public _Timer(TimeSpan dueTime, TimeSpan? period, PlayerLoopTiming updateTiming, bool ignoreTimeScale, CancellationToken cancellationToken) + public _Timer(TimeSpan dueTime, TimeSpan? period, PlayerLoopTiming updateTiming, bool ignoreTimeScale, CancellationToken cancellationToken, bool cancelImmediately) { this.dueTime = (float)dueTime.TotalSeconds; this.period = (period == null) ? null : (float?)period.Value.TotalSeconds; @@ -105,6 +108,16 @@ public _Timer(TimeSpan dueTime, TimeSpan? period, PlayerLoopTiming updateTiming, this.updateTiming = updateTiming; this.ignoreTimeScale = ignoreTimeScale; this.cancellationToken = cancellationToken; + + if (cancelImmediately && cancellationToken.CanBeCanceled) + { + cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => + { + var source = (_Timer)state; + source.completionSource.TrySetCanceled(source.cancellationToken); + }, this); + } + TaskTracker.TrackActiveTask(this, 2); PlayerLoopHelper.AddAction(updateTiming, this); } @@ -114,12 +127,16 @@ public _Timer(TimeSpan dueTime, TimeSpan? period, PlayerLoopTiming updateTiming, public UniTask MoveNextAsync() { // return false instead of throw - if (disposed || cancellationToken.IsCancellationRequested || completed) return CompletedTasks.False; + if (disposed || completed) return CompletedTasks.False; // reset value here. this.elapsed = 0; completionSource.Reset(); + if (cancellationToken.IsCancellationRequested) + { + completionSource.TrySetCanceled(cancellationToken); + } return new UniTask(this, completionSource.Version); } @@ -127,6 +144,7 @@ public UniTask DisposeAsync() { if (!disposed) { + cancellationTokenRegistration.Dispose(); disposed = true; TaskTracker.RemoveTracking(this); } @@ -135,11 +153,16 @@ public UniTask DisposeAsync() public bool MoveNext() { - if (disposed || cancellationToken.IsCancellationRequested) + if (disposed) { completionSource.TrySetResult(false); return false; } + if (cancellationToken.IsCancellationRequested) + { + completionSource.TrySetCanceled(cancellationToken); + return false; + } if (dueTimePhase) { @@ -187,24 +210,27 @@ internal class TimerFrame : IUniTaskAsyncEnumerable readonly PlayerLoopTiming updateTiming; readonly int dueTimeFrameCount; readonly int? periodFrameCount; + readonly bool cancelImmediately; - public TimerFrame(int dueTimeFrameCount, int? periodFrameCount, PlayerLoopTiming updateTiming) + public TimerFrame(int dueTimeFrameCount, int? periodFrameCount, PlayerLoopTiming updateTiming, bool cancelImmediately) { this.updateTiming = updateTiming; this.dueTimeFrameCount = dueTimeFrameCount; this.periodFrameCount = periodFrameCount; + this.cancelImmediately = cancelImmediately; } public IUniTaskAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) { - return new _TimerFrame(dueTimeFrameCount, periodFrameCount, updateTiming, cancellationToken); + return new _TimerFrame(dueTimeFrameCount, periodFrameCount, updateTiming, cancellationToken, cancelImmediately); } class _TimerFrame : MoveNextSource, IUniTaskAsyncEnumerator, IPlayerLoopItem { readonly int dueTimeFrameCount; readonly int? periodFrameCount; - CancellationToken cancellationToken; + readonly CancellationToken cancellationToken; + readonly CancellationTokenRegistration cancellationTokenRegistration; int initialFrame; int currentFrame; @@ -212,7 +238,7 @@ class _TimerFrame : MoveNextSource, IUniTaskAsyncEnumerator, IPlayerL bool completed; bool disposed; - public _TimerFrame(int dueTimeFrameCount, int? periodFrameCount, PlayerLoopTiming updateTiming, CancellationToken cancellationToken) + public _TimerFrame(int dueTimeFrameCount, int? periodFrameCount, PlayerLoopTiming updateTiming, CancellationToken cancellationToken, bool cancelImmediately) { if (dueTimeFrameCount <= 0) dueTimeFrameCount = 0; if (periodFrameCount != null) @@ -225,6 +251,15 @@ public _TimerFrame(int dueTimeFrameCount, int? periodFrameCount, PlayerLoopTimin this.dueTimeFrameCount = dueTimeFrameCount; this.periodFrameCount = periodFrameCount; this.cancellationToken = cancellationToken; + + if (cancelImmediately && cancellationToken.CanBeCanceled) + { + cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => + { + var source = (_TimerFrame)state; + source.completionSource.TrySetCanceled(source.cancellationToken); + }, this); + } TaskTracker.TrackActiveTask(this, 2); PlayerLoopHelper.AddAction(updateTiming, this); @@ -234,13 +269,15 @@ public _TimerFrame(int dueTimeFrameCount, int? periodFrameCount, PlayerLoopTimin public UniTask MoveNextAsync() { - // return false instead of throw - if (disposed || cancellationToken.IsCancellationRequested || completed) return CompletedTasks.False; + if (disposed || completed) return CompletedTasks.False; + if (cancellationToken.IsCancellationRequested) + { + completionSource.TrySetCanceled(cancellationToken); + } // reset value here. this.currentFrame = 0; - completionSource.Reset(); return new UniTask(this, completionSource.Version); } @@ -249,6 +286,7 @@ public UniTask DisposeAsync() { if (!disposed) { + cancellationTokenRegistration.Dispose(); disposed = true; TaskTracker.RemoveTracking(this); } @@ -257,7 +295,12 @@ public UniTask DisposeAsync() public bool MoveNext() { - if (disposed || cancellationToken.IsCancellationRequested) + if (cancellationToken.IsCancellationRequested) + { + completionSource.TrySetCanceled(cancellationToken); + return false; + } + if (disposed) { completionSource.TrySetResult(false); return false; diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/UnityExtensions/Timer.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/UnityExtensions/Timer.cs.meta index 3c33c901..aa790c52 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/UnityExtensions/Timer.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/UnityExtensions/Timer.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 460eb5b7189dc4a588551fda0c843c0c +guid: 382caacde439855418709c641e4d7b04 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Where.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Where.cs.meta index f584c667..7e503375 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Where.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Where.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 457c94394bc9f491db1be409ee79f287 +guid: d882a3238d9535e4e8ce1ad3291eb7fb MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Linq/Zip.cs.meta b/Runtime/Plugins/UniTask/Runtime/Linq/Zip.cs.meta index f416ff8a..bf121637 100644 --- a/Runtime/Plugins/UniTask/Runtime/Linq/Zip.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Linq/Zip.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: b9b9752e634e54cc5afd46a1fc51a3d9 +guid: acc1acff153e347418f0f30b1c535994 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/MoveNextSource.cs.meta b/Runtime/Plugins/UniTask/Runtime/MoveNextSource.cs.meta index 070f59f6..60a0908c 100644 --- a/Runtime/Plugins/UniTask/Runtime/MoveNextSource.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/MoveNextSource.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 1811eecca84d64d8983a39c97280f9bc +guid: dc4c5dc2a5f246e4f8df44cab735826c MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/PlayerLoopHelper.cs b/Runtime/Plugins/UniTask/Runtime/PlayerLoopHelper.cs index 538fc011..b17375e7 100644 --- a/Runtime/Plugins/UniTask/Runtime/PlayerLoopHelper.cs +++ b/Runtime/Plugins/UniTask/Runtime/PlayerLoopHelper.cs @@ -285,7 +285,11 @@ static PlayerLoopSystem[] InsertUniTaskSynchronizationContext(PlayerLoopSystem l return dest.ToArray(); } - [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] +#if UNITY_2020_1_OR_NEWER + [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)] +#else + [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] +#endif static void Init() { // capture default(unity) sync-context. diff --git a/Runtime/Plugins/UniTask/Runtime/PlayerLoopHelper.cs.meta b/Runtime/Plugins/UniTask/Runtime/PlayerLoopHelper.cs.meta index 5e86f03a..2487ef77 100644 --- a/Runtime/Plugins/UniTask/Runtime/PlayerLoopHelper.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/PlayerLoopHelper.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 0335b2962570642c08350dd404b38a2f +guid: 15fb5b85042f19640b973ce651795aca MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/PlayerLoopTimer.cs.meta b/Runtime/Plugins/UniTask/Runtime/PlayerLoopTimer.cs.meta index b74a0194..eb2b50a0 100644 --- a/Runtime/Plugins/UniTask/Runtime/PlayerLoopTimer.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/PlayerLoopTimer.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: dbf62f3671ef04635b86e0104dfd213d +guid: 57095a17fdca7ee4380450910afc7f26 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Progress.cs.meta b/Runtime/Plugins/UniTask/Runtime/Progress.cs.meta index 36b3139d..f0e1f197 100644 --- a/Runtime/Plugins/UniTask/Runtime/Progress.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Progress.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 04161c0a234964051abc7e7d5b778583 +guid: e3377e2ae934ed54fb8fd5388e2d9eb9 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/TaskPool.cs.meta b/Runtime/Plugins/UniTask/Runtime/TaskPool.cs.meta index 28d66192..94c78058 100644 --- a/Runtime/Plugins/UniTask/Runtime/TaskPool.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/TaskPool.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: aaba7ea0d91764bbcb11576ba96da45d +guid: 19f4e6575150765449cc99f25f06f25f MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/TimeoutController.cs.meta b/Runtime/Plugins/UniTask/Runtime/TimeoutController.cs.meta index 4fd2a3d8..4f3d16d9 100644 --- a/Runtime/Plugins/UniTask/Runtime/TimeoutController.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/TimeoutController.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 02f3e48b6c74a4180b0a07409b0a02b3 +guid: 6347ab34d2db6d744a654e8d62d96b96 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/TriggerEvent.cs b/Runtime/Plugins/UniTask/Runtime/TriggerEvent.cs index 503e9db9..0b817fe3 100644 --- a/Runtime/Plugins/UniTask/Runtime/TriggerEvent.cs +++ b/Runtime/Plugins/UniTask/Runtime/TriggerEvent.cs @@ -20,8 +20,6 @@ public struct TriggerEvent { ITriggerHandler head; // head.prev is last ITriggerHandler iteratingHead; - - bool preserveRemoveSelf; ITriggerHandler iteratingNode; void LogError(Exception ex) @@ -55,18 +53,9 @@ public void SetResult(T value) Remove(h); } - if (preserveRemoveSelf) - { - preserveRemoveSelf = false; - iteratingNode = null; - var next = h.Next; - Remove(h); - h = next; - } - else - { - h = h.Next; - } + // If `h` itself is removed by OnNext, h.Next is null. + // Therefore, instead of looking at h.Next, the `iteratingNode` reference itself is replaced. + h = h == iteratingNode ? h.Next : iteratingNode; } iteratingNode = null; @@ -97,9 +86,8 @@ public void SetCanceled(CancellationToken cancellationToken) LogError(ex); } - preserveRemoveSelf = false; + var next = h == iteratingNode ? h.Next : iteratingNode; iteratingNode = null; - var next = h.Next; Remove(h); h = next; } @@ -132,9 +120,8 @@ public void SetCompleted() LogError(ex); } - preserveRemoveSelf = false; + var next = h == iteratingNode ? h.Next : iteratingNode; iteratingNode = null; - var next = h.Next; Remove(h); h = next; } @@ -167,9 +154,8 @@ public void SetError(Exception exception) LogError(ex); } - preserveRemoveSelf = false; + var next = h == iteratingNode ? h.Next : iteratingNode; iteratingNode = null; - var next = h.Next; Remove(h); h = next; } @@ -241,71 +227,65 @@ public void Remove(ITriggerHandler handler) { if (handler == null) throw new ArgumentNullException(nameof(handler)); - if (iteratingNode != null && iteratingNode == handler) + var prev = handler.Prev; + var next = handler.Next; + + if (next != null) { - // if remove self, reserve remove self after invoke completed. - preserveRemoveSelf = true; + next.Prev = prev; } - else + + if (handler == head) + { + head = next; + } + // when handler is head, prev indicate last so don't use it. + else if (prev != null) { - var prev = handler.Prev; - var next = handler.Next; + prev.Next = next; + } - if (next != null) - { - next.Prev = prev; - } + if (handler == iteratingNode) + { + iteratingNode = next; + } + if (handler == iteratingHead) + { + iteratingHead = next; + } - if (handler == head) - { - head = next; - } - else if (handler == iteratingHead) - { - iteratingHead = next; - } - else + if (head != null) + { + if (head.Prev == handler) { - // when handler is head, prev indicate last so don't use it. - if (prev != null) + if (prev != head) { - prev.Next = next; + head.Prev = prev; } - } - - if (head != null) - { - if (head.Prev == handler) + else { - if (prev != head) - { - head.Prev = prev; - } - else - { - head.Prev = null; - } + head.Prev = null; } } + } - if (iteratingHead != null) + if (iteratingHead != null) + { + if (iteratingHead.Prev == handler) { - if (iteratingHead.Prev == handler) + if (prev != iteratingHead.Prev) { - if (prev != iteratingHead.Prev) - { - iteratingHead.Prev = prev; - } - else - { - iteratingHead.Prev = null; - } + iteratingHead.Prev = prev; + } + else + { + iteratingHead.Prev = null; } } - - handler.Prev = null; - handler.Next = null; } + + handler.Prev = null; + handler.Next = null; } } } diff --git a/Runtime/Plugins/UniTask/Runtime/TriggerEvent.cs.meta b/Runtime/Plugins/UniTask/Runtime/TriggerEvent.cs.meta index c2cda166..bbd47af7 100644 --- a/Runtime/Plugins/UniTask/Runtime/TriggerEvent.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/TriggerEvent.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 4a568cd293fdc48cea7ea41c3dab708b +guid: f68b22bb8f66f5c4885f9bd3c4fc43ed MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Triggers.meta b/Runtime/Plugins/UniTask/Runtime/Triggers.meta index 9f3dddb8..3087ef85 100644 --- a/Runtime/Plugins/UniTask/Runtime/Triggers.meta +++ b/Runtime/Plugins/UniTask/Runtime/Triggers.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 422b273127a234d6399566b951b43a56 +guid: c6c24fa00de584994bf5bb4216e65ff6 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Runtime/Plugins/UniTask/Runtime/Triggers/AsyncAwakeTrigger.cs.meta b/Runtime/Plugins/UniTask/Runtime/Triggers/AsyncAwakeTrigger.cs.meta index e3692f89..097fdb61 100644 --- a/Runtime/Plugins/UniTask/Runtime/Triggers/AsyncAwakeTrigger.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Triggers/AsyncAwakeTrigger.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 5d33c47137bd3493cbe7b1ad985f8986 +guid: ef2840a2586894741a0ae211b8fd669b MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Triggers/AsyncDestroyTrigger.cs b/Runtime/Plugins/UniTask/Runtime/Triggers/AsyncDestroyTrigger.cs index 811f9770..77c92859 100644 --- a/Runtime/Plugins/UniTask/Runtime/Triggers/AsyncDestroyTrigger.cs +++ b/Runtime/Plugins/UniTask/Runtime/Triggers/AsyncDestroyTrigger.cs @@ -32,13 +32,11 @@ public CancellationToken CancellationToken if (cancellationTokenSource == null) { cancellationTokenSource = new CancellationTokenSource(); + if (!awakeCalled) + { + PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, new AwakeMonitor(this)); + } } - - if (!awakeCalled) - { - PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, new AwakeMonitor(this)); - } - return cancellationTokenSource.Token; } } @@ -83,7 +81,7 @@ public AwakeMonitor(AsyncDestroyTrigger trigger) public bool MoveNext() { - if (trigger.called) return false; + if (trigger.called || trigger.awakeCalled) return false; if (trigger == null) { trigger.OnDestroy(); diff --git a/Runtime/Plugins/UniTask/Runtime/Triggers/AsyncDestroyTrigger.cs.meta b/Runtime/Plugins/UniTask/Runtime/Triggers/AsyncDestroyTrigger.cs.meta index 935bb9ab..64500494 100644 --- a/Runtime/Plugins/UniTask/Runtime/Triggers/AsyncDestroyTrigger.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Triggers/AsyncDestroyTrigger.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 5742c60a067f74e869a953a7a4b4c639 +guid: f4afdcb1cbadf954ba8b1cf465429e17 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Triggers/AsyncStartTrigger.cs.meta b/Runtime/Plugins/UniTask/Runtime/Triggers/AsyncStartTrigger.cs.meta index 07d2564c..9ef06e8e 100644 --- a/Runtime/Plugins/UniTask/Runtime/Triggers/AsyncStartTrigger.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Triggers/AsyncStartTrigger.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 878774edbea43412a9f1952e9ac8e744 +guid: b4fd0f75e54ec3d4fbcb7fc65b11646b MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Triggers/AsyncTriggerBase.cs.meta b/Runtime/Plugins/UniTask/Runtime/Triggers/AsyncTriggerBase.cs.meta index eec82c77..e101ea2d 100644 --- a/Runtime/Plugins/UniTask/Runtime/Triggers/AsyncTriggerBase.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Triggers/AsyncTriggerBase.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 8d8ae9697a29647f49513a8269f5586f +guid: 2c0c2bcee832c6641b25949c412f020f MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Triggers/AsyncTriggerExtensions.cs.meta b/Runtime/Plugins/UniTask/Runtime/Triggers/AsyncTriggerExtensions.cs.meta index f2b868b7..348783dd 100644 --- a/Runtime/Plugins/UniTask/Runtime/Triggers/AsyncTriggerExtensions.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Triggers/AsyncTriggerExtensions.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: bc578ccda545b42898d2c5c1bad796dd +guid: 59b61dbea1562a84fb7a38ae0a0a0f88 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/Triggers/MonoBehaviourMessagesTriggers.cs.meta b/Runtime/Plugins/UniTask/Runtime/Triggers/MonoBehaviourMessagesTriggers.cs.meta index 93eeb5b8..82aa6792 100644 --- a/Runtime/Plugins/UniTask/Runtime/Triggers/MonoBehaviourMessagesTriggers.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/Triggers/MonoBehaviourMessagesTriggers.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 4e87de873462e4425b245b507c3174df +guid: c30655636c35c3d4da44064af3d2d9a7 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/UniTask.Bridge.cs.meta b/Runtime/Plugins/UniTask/Runtime/UniTask.Bridge.cs.meta index 63cd0dd8..6f8da804 100644 --- a/Runtime/Plugins/UniTask/Runtime/UniTask.Bridge.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/UniTask.Bridge.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 56a7b2c90e2a44dc59d5550017d66488 +guid: bd6beac8e0ebd264e9ba246c39429c72 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/UniTask.Delay.cs b/Runtime/Plugins/UniTask/Runtime/UniTask.Delay.cs index 0986c005..7f02a1a1 100644 --- a/Runtime/Plugins/UniTask/Runtime/UniTask.Delay.cs +++ b/Runtime/Plugins/UniTask/Runtime/UniTask.Delay.cs @@ -33,14 +33,14 @@ public static YieldAwaitable Yield(PlayerLoopTiming timing) return new YieldAwaitable(timing); } - public static UniTask Yield(CancellationToken cancellationToken) + public static UniTask Yield(CancellationToken cancellationToken, bool cancelImmediately = false) { - return new UniTask(YieldPromise.Create(PlayerLoopTiming.Update, cancellationToken, out var token), token); + return new UniTask(YieldPromise.Create(PlayerLoopTiming.Update, cancellationToken, cancelImmediately, out var token), token); } - public static UniTask Yield(PlayerLoopTiming timing, CancellationToken cancellationToken) + public static UniTask Yield(PlayerLoopTiming timing, CancellationToken cancellationToken, bool cancelImmediately = false) { - return new UniTask(YieldPromise.Create(timing, cancellationToken, out var token), token); + return new UniTask(YieldPromise.Create(timing, cancellationToken, cancelImmediately, out var token), token); } /// @@ -48,7 +48,7 @@ public static UniTask Yield(PlayerLoopTiming timing, CancellationToken cancellat /// public static UniTask NextFrame() { - return new UniTask(NextFramePromise.Create(PlayerLoopTiming.Update, CancellationToken.None, out var token), token); + return new UniTask(NextFramePromise.Create(PlayerLoopTiming.Update, CancellationToken.None, false, out var token), token); } /// @@ -56,25 +56,31 @@ public static UniTask NextFrame() /// public static UniTask NextFrame(PlayerLoopTiming timing) { - return new UniTask(NextFramePromise.Create(timing, CancellationToken.None, out var token), token); + return new UniTask(NextFramePromise.Create(timing, CancellationToken.None, false, out var token), token); } /// /// Similar as UniTask.Yield but guaranteed run on next frame. /// - public static UniTask NextFrame(CancellationToken cancellationToken) + public static UniTask NextFrame(CancellationToken cancellationToken, bool cancelImmediately = false) { - return new UniTask(NextFramePromise.Create(PlayerLoopTiming.Update, cancellationToken, out var token), token); + return new UniTask(NextFramePromise.Create(PlayerLoopTiming.Update, cancellationToken, cancelImmediately, out var token), token); } /// /// Similar as UniTask.Yield but guaranteed run on next frame. /// - public static UniTask NextFrame(PlayerLoopTiming timing, CancellationToken cancellationToken) + public static UniTask NextFrame(PlayerLoopTiming timing, CancellationToken cancellationToken, bool cancelImmediately = false) { - return new UniTask(NextFramePromise.Create(timing, cancellationToken, out var token), token); + return new UniTask(NextFramePromise.Create(timing, cancellationToken, cancelImmediately, out var token), token); } +#if UNITY_2023_1_OR_NEWER + public static async UniTask WaitForEndOfFrame(CancellationToken cancellationToken = default) + { + await Awaitable.EndOfFrameAsync(cancellationToken); + } +#else [Obsolete("Use WaitForEndOfFrame(MonoBehaviour) instead or UniTask.Yield(PlayerLoopTiming.LastPostLateUpdate). Equivalent for coroutine's WaitForEndOfFrame requires MonoBehaviour(runner of Coroutine).")] public static YieldAwaitable WaitForEndOfFrame() { @@ -82,14 +88,21 @@ public static YieldAwaitable WaitForEndOfFrame() } [Obsolete("Use WaitForEndOfFrame(MonoBehaviour) instead or UniTask.Yield(PlayerLoopTiming.LastPostLateUpdate). Equivalent for coroutine's WaitForEndOfFrame requires MonoBehaviour(runner of Coroutine).")] - public static UniTask WaitForEndOfFrame(CancellationToken cancellationToken) + public static UniTask WaitForEndOfFrame(CancellationToken cancellationToken, bool cancelImmediately = false) + { + return UniTask.Yield(PlayerLoopTiming.LastPostLateUpdate, cancellationToken, cancelImmediately); + } +#endif + + public static UniTask WaitForEndOfFrame(MonoBehaviour coroutineRunner) { - return UniTask.Yield(PlayerLoopTiming.LastPostLateUpdate, cancellationToken); + var source = WaitForEndOfFramePromise.Create(coroutineRunner, CancellationToken.None, false, out var token); + return new UniTask(source, token); } - public static UniTask WaitForEndOfFrame(MonoBehaviour coroutineRunner, CancellationToken cancellationToken = default) + public static UniTask WaitForEndOfFrame(MonoBehaviour coroutineRunner, CancellationToken cancellationToken, bool cancelImmediately = false) { - var source = WaitForEndOfFramePromise.Create(coroutineRunner, cancellationToken, out var token); + var source = WaitForEndOfFramePromise.Create(coroutineRunner, cancellationToken, cancelImmediately, out var token); return new UniTask(source, token); } @@ -106,40 +119,50 @@ public static YieldAwaitable WaitForFixedUpdate() /// /// Same as UniTask.Yield(PlayerLoopTiming.LastFixedUpdate, cancellationToken). /// - public static UniTask WaitForFixedUpdate(CancellationToken cancellationToken) + public static UniTask WaitForFixedUpdate(CancellationToken cancellationToken, bool cancelImmediately = false) { - return UniTask.Yield(PlayerLoopTiming.LastFixedUpdate, cancellationToken); + return UniTask.Yield(PlayerLoopTiming.LastFixedUpdate, cancellationToken, cancelImmediately); } - public static UniTask DelayFrame(int delayFrameCount, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) + public static UniTask WaitForSeconds(float duration, bool ignoreTimeScale = false, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false) + { + return Delay(Mathf.RoundToInt(1000 * duration), ignoreTimeScale, delayTiming, cancellationToken, cancelImmediately); + } + + public static UniTask WaitForSeconds(int duration, bool ignoreTimeScale = false, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false) + { + return Delay(1000 * duration, ignoreTimeScale, delayTiming, cancellationToken, cancelImmediately); + } + + public static UniTask DelayFrame(int delayFrameCount, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false) { if (delayFrameCount < 0) { throw new ArgumentOutOfRangeException("Delay does not allow minus delayFrameCount. delayFrameCount:" + delayFrameCount); } - return new UniTask(DelayFramePromise.Create(delayFrameCount, delayTiming, cancellationToken, out var token), token); + return new UniTask(DelayFramePromise.Create(delayFrameCount, delayTiming, cancellationToken, cancelImmediately, out var token), token); } - public static UniTask Delay(int millisecondsDelay, bool ignoreTimeScale = false, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) + public static UniTask Delay(int millisecondsDelay, bool ignoreTimeScale = false, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false) { var delayTimeSpan = TimeSpan.FromMilliseconds(millisecondsDelay); - return Delay(delayTimeSpan, ignoreTimeScale, delayTiming, cancellationToken); + return Delay(delayTimeSpan, ignoreTimeScale, delayTiming, cancellationToken, cancelImmediately); } - public static UniTask Delay(TimeSpan delayTimeSpan, bool ignoreTimeScale = false, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) + public static UniTask Delay(TimeSpan delayTimeSpan, bool ignoreTimeScale = false, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false) { var delayType = ignoreTimeScale ? DelayType.UnscaledDeltaTime : DelayType.DeltaTime; - return Delay(delayTimeSpan, delayType, delayTiming, cancellationToken); + return Delay(delayTimeSpan, delayType, delayTiming, cancellationToken, cancelImmediately); } - public static UniTask Delay(int millisecondsDelay, DelayType delayType, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) + public static UniTask Delay(int millisecondsDelay, DelayType delayType, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false) { var delayTimeSpan = TimeSpan.FromMilliseconds(millisecondsDelay); - return Delay(delayTimeSpan, delayType, delayTiming, cancellationToken); + return Delay(delayTimeSpan, delayType, delayTiming, cancellationToken, cancelImmediately); } - public static UniTask Delay(TimeSpan delayTimeSpan, DelayType delayType, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) + public static UniTask Delay(TimeSpan delayTimeSpan, DelayType delayType, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false) { if (delayTimeSpan < TimeSpan.Zero) { @@ -158,16 +181,16 @@ public static UniTask WaitForFixedUpdate(CancellationToken cancellationToken) { case DelayType.UnscaledDeltaTime: { - return new UniTask(DelayIgnoreTimeScalePromise.Create(delayTimeSpan, delayTiming, cancellationToken, out var token), token); + return new UniTask(DelayIgnoreTimeScalePromise.Create(delayTimeSpan, delayTiming, cancellationToken, cancelImmediately, out var token), token); } case DelayType.Realtime: { - return new UniTask(DelayRealtimePromise.Create(delayTimeSpan, delayTiming, cancellationToken, out var token), token); + return new UniTask(DelayRealtimePromise.Create(delayTimeSpan, delayTiming, cancellationToken, cancelImmediately, out var token), token); } case DelayType.DeltaTime: default: { - return new UniTask(DelayPromise.Create(delayTimeSpan, delayTiming, cancellationToken, out var token), token); + return new UniTask(DelayPromise.Create(delayTimeSpan, delayTiming, cancellationToken, cancelImmediately, out var token), token); } } } @@ -184,13 +207,14 @@ static YieldPromise() } CancellationToken cancellationToken; + CancellationTokenRegistration cancellationTokenRegistration; UniTaskCompletionSourceCore core; YieldPromise() { } - public static IUniTaskSource Create(PlayerLoopTiming timing, CancellationToken cancellationToken, out short token) + public static IUniTaskSource Create(PlayerLoopTiming timing, CancellationToken cancellationToken, bool cancelImmediately, out short token) { if (cancellationToken.IsCancellationRequested) { @@ -202,8 +226,16 @@ public static IUniTaskSource Create(PlayerLoopTiming timing, CancellationToken c result = new YieldPromise(); } - result.cancellationToken = cancellationToken; + + if (cancelImmediately && cancellationToken.CanBeCanceled) + { + result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => + { + var promise = (YieldPromise)state; + promise.core.TrySetCanceled(promise.cancellationToken); + }, result); + } TaskTracker.TrackActiveTask(result, 3); @@ -257,6 +289,7 @@ bool TryReturn() TaskTracker.RemoveTracking(this); core.Reset(); cancellationToken = default; + cancellationTokenRegistration.Dispose(); return pool.TryPush(this); } } @@ -273,14 +306,15 @@ static NextFramePromise() } int frameCount; - CancellationToken cancellationToken; UniTaskCompletionSourceCore core; + CancellationToken cancellationToken; + CancellationTokenRegistration cancellationTokenRegistration; NextFramePromise() { } - public static IUniTaskSource Create(PlayerLoopTiming timing, CancellationToken cancellationToken, out short token) + public static IUniTaskSource Create(PlayerLoopTiming timing, CancellationToken cancellationToken, bool cancelImmediately, out short token) { if (cancellationToken.IsCancellationRequested) { @@ -295,6 +329,15 @@ public static IUniTaskSource Create(PlayerLoopTiming timing, CancellationToken c result.frameCount = PlayerLoopHelper.IsMainThread ? Time.frameCount : -1; result.cancellationToken = cancellationToken; + if (cancelImmediately && cancellationToken.CanBeCanceled) + { + result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => + { + var promise = (NextFramePromise)state; + promise.core.TrySetCanceled(promise.cancellationToken); + }, result); + } + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -352,6 +395,7 @@ bool TryReturn() TaskTracker.RemoveTracking(this); core.Reset(); cancellationToken = default; + cancellationTokenRegistration.Dispose(); return pool.TryPush(this); } } @@ -367,14 +411,15 @@ static WaitForEndOfFramePromise() TaskPool.RegisterSizeGetter(typeof(WaitForEndOfFramePromise), () => pool.Size); } - CancellationToken cancellationToken; UniTaskCompletionSourceCore core; + CancellationToken cancellationToken; + CancellationTokenRegistration cancellationTokenRegistration; WaitForEndOfFramePromise() { } - public static IUniTaskSource Create(MonoBehaviour coroutineRunner, CancellationToken cancellationToken, out short token) + public static IUniTaskSource Create(MonoBehaviour coroutineRunner, CancellationToken cancellationToken, bool cancelImmediately, out short token) { if (cancellationToken.IsCancellationRequested) { @@ -388,6 +433,15 @@ public static IUniTaskSource Create(MonoBehaviour coroutineRunner, CancellationT result.cancellationToken = cancellationToken; + if (cancelImmediately && cancellationToken.CanBeCanceled) + { + result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => + { + var promise = (WaitForEndOfFramePromise)state; + promise.core.TrySetCanceled(promise.cancellationToken); + }, result); + } + TaskTracker.TrackActiveTask(result, 3); coroutineRunner.StartCoroutine(result); @@ -429,6 +483,7 @@ bool TryReturn() core.Reset(); Reset(); // Reset Enumerator cancellationToken = default; + cancellationTokenRegistration.Dispose(); return pool.TryPush(this); } @@ -477,6 +532,7 @@ static DelayFramePromise() int initialFrame; int delayFrameCount; CancellationToken cancellationToken; + CancellationTokenRegistration cancellationTokenRegistration; int currentFrameCount; UniTaskCompletionSourceCore core; @@ -485,7 +541,7 @@ static DelayFramePromise() { } - public static IUniTaskSource Create(int delayFrameCount, PlayerLoopTiming timing, CancellationToken cancellationToken, out short token) + public static IUniTaskSource Create(int delayFrameCount, PlayerLoopTiming timing, CancellationToken cancellationToken, bool cancelImmediately, out short token) { if (cancellationToken.IsCancellationRequested) { @@ -501,6 +557,15 @@ public static IUniTaskSource Create(int delayFrameCount, PlayerLoopTiming timing result.cancellationToken = cancellationToken; result.initialFrame = PlayerLoopHelper.IsMainThread ? Time.frameCount : -1; + if (cancelImmediately && cancellationToken.CanBeCanceled) + { + result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => + { + var promise = (DelayFramePromise)state; + promise.core.TrySetCanceled(promise.cancellationToken); + }, result); + } + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -587,6 +652,7 @@ bool TryReturn() currentFrameCount = default; delayFrameCount = default; cancellationToken = default; + cancellationTokenRegistration.Dispose(); return pool.TryPush(this); } } @@ -606,6 +672,7 @@ static DelayPromise() float delayTimeSpan; float elapsed; CancellationToken cancellationToken; + CancellationTokenRegistration cancellationTokenRegistration; UniTaskCompletionSourceCore core; @@ -613,7 +680,7 @@ static DelayPromise() { } - public static IUniTaskSource Create(TimeSpan delayTimeSpan, PlayerLoopTiming timing, CancellationToken cancellationToken, out short token) + public static IUniTaskSource Create(TimeSpan delayTimeSpan, PlayerLoopTiming timing, CancellationToken cancellationToken, bool cancelImmediately, out short token) { if (cancellationToken.IsCancellationRequested) { @@ -630,6 +697,15 @@ public static IUniTaskSource Create(TimeSpan delayTimeSpan, PlayerLoopTiming tim result.cancellationToken = cancellationToken; result.initialFrame = PlayerLoopHelper.IsMainThread ? Time.frameCount : -1; + if (cancelImmediately && cancellationToken.CanBeCanceled) + { + result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => + { + var promise = (DelayPromise)state; + promise.core.TrySetCanceled(promise.cancellationToken); + }, result); + } + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -698,6 +774,7 @@ bool TryReturn() delayTimeSpan = default; elapsed = default; cancellationToken = default; + cancellationTokenRegistration.Dispose(); return pool.TryPush(this); } } @@ -717,6 +794,7 @@ static DelayIgnoreTimeScalePromise() float elapsed; int initialFrame; CancellationToken cancellationToken; + CancellationTokenRegistration cancellationTokenRegistration; UniTaskCompletionSourceCore core; @@ -724,7 +802,7 @@ static DelayIgnoreTimeScalePromise() { } - public static IUniTaskSource Create(TimeSpan delayFrameTimeSpan, PlayerLoopTiming timing, CancellationToken cancellationToken, out short token) + public static IUniTaskSource Create(TimeSpan delayFrameTimeSpan, PlayerLoopTiming timing, CancellationToken cancellationToken, bool cancelImmediately, out short token) { if (cancellationToken.IsCancellationRequested) { @@ -741,6 +819,15 @@ public static IUniTaskSource Create(TimeSpan delayFrameTimeSpan, PlayerLoopTimin result.initialFrame = PlayerLoopHelper.IsMainThread ? Time.frameCount : -1; result.cancellationToken = cancellationToken; + if (cancelImmediately && cancellationToken.CanBeCanceled) + { + result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => + { + var promise = (DelayIgnoreTimeScalePromise)state; + promise.core.TrySetCanceled(promise.cancellationToken); + }, result); + } + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -809,6 +896,7 @@ bool TryReturn() delayFrameTimeSpan = default; elapsed = default; cancellationToken = default; + cancellationTokenRegistration.Dispose(); return pool.TryPush(this); } } @@ -827,6 +915,7 @@ static DelayRealtimePromise() long delayTimeSpanTicks; ValueStopwatch stopwatch; CancellationToken cancellationToken; + CancellationTokenRegistration cancellationTokenRegistration; UniTaskCompletionSourceCore core; @@ -834,7 +923,7 @@ static DelayRealtimePromise() { } - public static IUniTaskSource Create(TimeSpan delayTimeSpan, PlayerLoopTiming timing, CancellationToken cancellationToken, out short token) + public static IUniTaskSource Create(TimeSpan delayTimeSpan, PlayerLoopTiming timing, CancellationToken cancellationToken, bool cancelImmediately, out short token) { if (cancellationToken.IsCancellationRequested) { @@ -850,6 +939,15 @@ public static IUniTaskSource Create(TimeSpan delayTimeSpan, PlayerLoopTiming tim result.delayTimeSpanTicks = delayTimeSpan.Ticks; result.cancellationToken = cancellationToken; + if (cancelImmediately && cancellationToken.CanBeCanceled) + { + result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => + { + var promise = (DelayRealtimePromise)state; + promise.core.TrySetCanceled(promise.cancellationToken); + }, result); + } + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -914,6 +1012,7 @@ bool TryReturn() core.Reset(); stopwatch = default; cancellationToken = default; + cancellationTokenRegistration.Dispose(); return pool.TryPush(this); } } diff --git a/Runtime/Plugins/UniTask/Runtime/UniTask.Delay.cs.meta b/Runtime/Plugins/UniTask/Runtime/UniTask.Delay.cs.meta index dff62d41..08ce5793 100644 --- a/Runtime/Plugins/UniTask/Runtime/UniTask.Delay.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/UniTask.Delay.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: d55b2a4c9807b44e7b55b6fa8b601acd +guid: ecff7972251de0848b2c0fa89bbd3489 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/UniTask.Factory.cs.meta b/Runtime/Plugins/UniTask/Runtime/UniTask.Factory.cs.meta index 75b4bf7c..31bc0c95 100644 --- a/Runtime/Plugins/UniTask/Runtime/UniTask.Factory.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/UniTask.Factory.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: b22a15a6a90f14c168eb3e7a50e1d827 +guid: 4e12b66d6b9bd7845b04a594cbe386b4 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/UniTask.Run.cs.meta b/Runtime/Plugins/UniTask/Runtime/UniTask.Run.cs.meta index 78f51b8f..9a780aea 100644 --- a/Runtime/Plugins/UniTask/Runtime/UniTask.Run.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/UniTask.Run.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: ba0a0d1cabe6e434ea6950417d672d14 +guid: 8473162fc285a5f44bcca90f7da073e7 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/UniTask.Threading.cs.meta b/Runtime/Plugins/UniTask/Runtime/UniTask.Threading.cs.meta index 820b5da2..fa512b8c 100644 --- a/Runtime/Plugins/UniTask/Runtime/UniTask.Threading.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/UniTask.Threading.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: e34794e5f3e714777a67a19b5c73be39 +guid: 4132ea600454134439fa2c7eb931b5e6 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/UniTask.WaitUntil.cs b/Runtime/Plugins/UniTask/Runtime/UniTask.WaitUntil.cs index 0a09fe09..b28a529e 100644 --- a/Runtime/Plugins/UniTask/Runtime/UniTask.WaitUntil.cs +++ b/Runtime/Plugins/UniTask/Runtime/UniTask.WaitUntil.cs @@ -9,30 +9,30 @@ namespace Cysharp.Threading.Tasks { public partial struct UniTask { - public static UniTask WaitUntil(Func predicate, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) + public static UniTask WaitUntil(Func predicate, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false) { - return new UniTask(WaitUntilPromise.Create(predicate, timing, cancellationToken, out var token), token); + return new UniTask(WaitUntilPromise.Create(predicate, timing, cancellationToken, cancelImmediately, out var token), token); } - public static UniTask WaitWhile(Func predicate, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) + public static UniTask WaitWhile(Func predicate, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false) { - return new UniTask(WaitWhilePromise.Create(predicate, timing, cancellationToken, out var token), token); + return new UniTask(WaitWhilePromise.Create(predicate, timing, cancellationToken, cancelImmediately, out var token), token); } - public static UniTask WaitUntilCanceled(CancellationToken cancellationToken, PlayerLoopTiming timing = PlayerLoopTiming.Update) + public static UniTask WaitUntilCanceled(CancellationToken cancellationToken, PlayerLoopTiming timing = PlayerLoopTiming.Update, bool completeImmediately = false) { - return new UniTask(WaitUntilCanceledPromise.Create(cancellationToken, timing, out var token), token); + return new UniTask(WaitUntilCanceledPromise.Create(cancellationToken, timing, completeImmediately, out var token), token); } - public static UniTask WaitUntilValueChanged(T target, Func monitorFunction, PlayerLoopTiming monitorTiming = PlayerLoopTiming.Update, IEqualityComparer equalityComparer = null, CancellationToken cancellationToken = default(CancellationToken)) + public static UniTask WaitUntilValueChanged(T target, Func monitorFunction, PlayerLoopTiming monitorTiming = PlayerLoopTiming.Update, IEqualityComparer equalityComparer = null, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false) where T : class { var unityObject = target as UnityEngine.Object; var isUnityObject = target is UnityEngine.Object; // don't use (unityObject == null) return new UniTask(isUnityObject - ? WaitUntilValueChangedUnityObjectPromise.Create(target, monitorFunction, equalityComparer, monitorTiming, cancellationToken, out var token) - : WaitUntilValueChangedStandardObjectPromise.Create(target, monitorFunction, equalityComparer, monitorTiming, cancellationToken, out token), token); + ? WaitUntilValueChangedUnityObjectPromise.Create(target, monitorFunction, equalityComparer, monitorTiming, cancellationToken, cancelImmediately, out var token) + : WaitUntilValueChangedStandardObjectPromise.Create(target, monitorFunction, equalityComparer, monitorTiming, cancellationToken, cancelImmediately, out token), token); } sealed class WaitUntilPromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode @@ -48,6 +48,7 @@ static WaitUntilPromise() Func predicate; CancellationToken cancellationToken; + CancellationTokenRegistration cancellationTokenRegistration; UniTaskCompletionSourceCore core; @@ -55,7 +56,7 @@ static WaitUntilPromise() { } - public static IUniTaskSource Create(Func predicate, PlayerLoopTiming timing, CancellationToken cancellationToken, out short token) + public static IUniTaskSource Create(Func predicate, PlayerLoopTiming timing, CancellationToken cancellationToken, bool cancelImmediately, out short token) { if (cancellationToken.IsCancellationRequested) { @@ -70,6 +71,15 @@ public static IUniTaskSource Create(Func predicate, PlayerLoopTiming timin result.predicate = predicate; result.cancellationToken = cancellationToken; + if (cancelImmediately && cancellationToken.CanBeCanceled) + { + result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => + { + var promise = (WaitUntilPromise)state; + promise.core.TrySetCanceled(promise.cancellationToken); + }, result); + } + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -136,6 +146,7 @@ bool TryReturn() core.Reset(); predicate = default; cancellationToken = default; + cancellationTokenRegistration.Dispose(); return pool.TryPush(this); } } @@ -153,6 +164,7 @@ static WaitWhilePromise() Func predicate; CancellationToken cancellationToken; + CancellationTokenRegistration cancellationTokenRegistration; UniTaskCompletionSourceCore core; @@ -160,7 +172,7 @@ static WaitWhilePromise() { } - public static IUniTaskSource Create(Func predicate, PlayerLoopTiming timing, CancellationToken cancellationToken, out short token) + public static IUniTaskSource Create(Func predicate, PlayerLoopTiming timing, CancellationToken cancellationToken, bool cancelImmediately, out short token) { if (cancellationToken.IsCancellationRequested) { @@ -174,6 +186,15 @@ public static IUniTaskSource Create(Func predicate, PlayerLoopTiming timin result.predicate = predicate; result.cancellationToken = cancellationToken; + + if (cancelImmediately && cancellationToken.CanBeCanceled) + { + result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => + { + var promise = (WaitWhilePromise)state; + promise.core.TrySetCanceled(promise.cancellationToken); + }, result); + } TaskTracker.TrackActiveTask(result, 3); @@ -241,6 +262,7 @@ bool TryReturn() core.Reset(); predicate = default; cancellationToken = default; + cancellationTokenRegistration.Dispose(); return pool.TryPush(this); } } @@ -257,6 +279,7 @@ static WaitUntilCanceledPromise() } CancellationToken cancellationToken; + CancellationTokenRegistration cancellationTokenRegistration; UniTaskCompletionSourceCore core; @@ -264,7 +287,7 @@ static WaitUntilCanceledPromise() { } - public static IUniTaskSource Create(CancellationToken cancellationToken, PlayerLoopTiming timing, out short token) + public static IUniTaskSource Create(CancellationToken cancellationToken, PlayerLoopTiming timing, bool completeImmediately, out short token) { if (cancellationToken.IsCancellationRequested) { @@ -278,6 +301,15 @@ public static IUniTaskSource Create(CancellationToken cancellationToken, PlayerL result.cancellationToken = cancellationToken; + if (completeImmediately && cancellationToken.CanBeCanceled) + { + result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => + { + var promise = (WaitUntilCanceledPromise)state; + promise.core.TrySetResult(null); + }, result); + } + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -329,6 +361,7 @@ bool TryReturn() TaskTracker.RemoveTracking(this); core.Reset(); cancellationToken = default; + cancellationTokenRegistration.Dispose(); return pool.TryPush(this); } } @@ -351,6 +384,7 @@ static WaitUntilValueChangedUnityObjectPromise() Func monitorFunction; IEqualityComparer equalityComparer; CancellationToken cancellationToken; + CancellationTokenRegistration cancellationTokenRegistration; UniTaskCompletionSourceCore core; @@ -358,7 +392,7 @@ static WaitUntilValueChangedUnityObjectPromise() { } - public static IUniTaskSource Create(T target, Func monitorFunction, IEqualityComparer equalityComparer, PlayerLoopTiming timing, CancellationToken cancellationToken, out short token) + public static IUniTaskSource Create(T target, Func monitorFunction, IEqualityComparer equalityComparer, PlayerLoopTiming timing, CancellationToken cancellationToken, bool cancelImmediately, out short token) { if (cancellationToken.IsCancellationRequested) { @@ -376,6 +410,15 @@ public static IUniTaskSource Create(T target, Func monitorFunction, IEq result.currentValue = monitorFunction(target); result.equalityComparer = equalityComparer ?? UnityEqualityComparer.GetDefault(); result.cancellationToken = cancellationToken; + + if (cancelImmediately && cancellationToken.CanBeCanceled) + { + result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => + { + var promise = (WaitUntilValueChangedUnityObjectPromise)state; + promise.core.TrySetCanceled(promise.cancellationToken); + }, result); + } TaskTracker.TrackActiveTask(result, 3); @@ -453,6 +496,7 @@ bool TryReturn() monitorFunction = default; equalityComparer = default; cancellationToken = default; + cancellationTokenRegistration.Dispose(); return pool.TryPush(this); } } @@ -474,6 +518,7 @@ static WaitUntilValueChangedStandardObjectPromise() Func monitorFunction; IEqualityComparer equalityComparer; CancellationToken cancellationToken; + CancellationTokenRegistration cancellationTokenRegistration; UniTaskCompletionSourceCore core; @@ -481,7 +526,7 @@ static WaitUntilValueChangedStandardObjectPromise() { } - public static IUniTaskSource Create(T target, Func monitorFunction, IEqualityComparer equalityComparer, PlayerLoopTiming timing, CancellationToken cancellationToken, out short token) + public static IUniTaskSource Create(T target, Func monitorFunction, IEqualityComparer equalityComparer, PlayerLoopTiming timing, CancellationToken cancellationToken, bool cancelImmediately, out short token) { if (cancellationToken.IsCancellationRequested) { @@ -498,6 +543,15 @@ public static IUniTaskSource Create(T target, Func monitorFunction, IEq result.currentValue = monitorFunction(target); result.equalityComparer = equalityComparer ?? UnityEqualityComparer.GetDefault(); result.cancellationToken = cancellationToken; + + if (cancelImmediately && cancellationToken.CanBeCanceled) + { + result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => + { + var promise = (WaitUntilValueChangedStandardObjectPromise)state; + promise.core.TrySetCanceled(promise.cancellationToken); + }, result); + } TaskTracker.TrackActiveTask(result, 3); @@ -575,6 +629,7 @@ bool TryReturn() monitorFunction = default; equalityComparer = default; cancellationToken = default; + cancellationTokenRegistration.Dispose(); return pool.TryPush(this); } } diff --git a/Runtime/Plugins/UniTask/Runtime/UniTask.WaitUntil.cs.meta b/Runtime/Plugins/UniTask/Runtime/UniTask.WaitUntil.cs.meta index 1d9866c0..6e64dc7e 100644 --- a/Runtime/Plugins/UniTask/Runtime/UniTask.WaitUntil.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/UniTask.WaitUntil.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 105f0aa718bb445e5892d0d6ff7cd388 +guid: 87c9c533491903a4288536b5ac173db8 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/UniTask.WhenAll.Generated.cs.meta b/Runtime/Plugins/UniTask/Runtime/UniTask.WhenAll.Generated.cs.meta index e0e0e75f..40ed46cd 100644 --- a/Runtime/Plugins/UniTask/Runtime/UniTask.WhenAll.Generated.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/UniTask.WhenAll.Generated.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 63d24329e6e564fecbea4aefe648a594 +guid: 5110117231c8a6d4095fd0cbd3f4c142 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/UniTask.WhenAll.cs.meta b/Runtime/Plugins/UniTask/Runtime/UniTask.WhenAll.cs.meta index 75abd429..0366aa87 100644 --- a/Runtime/Plugins/UniTask/Runtime/UniTask.WhenAll.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/UniTask.WhenAll.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 62395c67ba241456398e649f706405d4 +guid: 355997a305ba64248822eec34998a1a0 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/UniTask.WhenAny.Generated.cs.meta b/Runtime/Plugins/UniTask/Runtime/UniTask.WhenAny.Generated.cs.meta index 1ce8dad4..49a2c3fd 100644 --- a/Runtime/Plugins/UniTask/Runtime/UniTask.WhenAny.Generated.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/UniTask.WhenAny.Generated.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: a3f82964c46c44ee79588e5f44931547 +guid: 13d604ac281570c4eac9962429f19ca9 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/UniTask.WhenAny.cs.meta b/Runtime/Plugins/UniTask/Runtime/UniTask.WhenAny.cs.meta index 2cf0be15..c10f7621 100644 --- a/Runtime/Plugins/UniTask/Runtime/UniTask.WhenAny.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/UniTask.WhenAny.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 7e70941ad86204bc899e05346d88d66e +guid: c32578978c37eaf41bdd90e1b034637d MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/UniTask.asmdef.meta b/Runtime/Plugins/UniTask/Runtime/UniTask.asmdef.meta index 362a4269..e497045e 100644 --- a/Runtime/Plugins/UniTask/Runtime/UniTask.asmdef.meta +++ b/Runtime/Plugins/UniTask/Runtime/UniTask.asmdef.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 1eaf7438b68a141a39da26d98b990fe7 +guid: f51ebe6a0ceec4240a699833d6309b23 AssemblyDefinitionImporter: externalObjects: {} userData: diff --git a/Runtime/Plugins/UniTask/Runtime/UniTask.cs.meta b/Runtime/Plugins/UniTask/Runtime/UniTask.cs.meta index 3d755cef..04eb6b64 100644 --- a/Runtime/Plugins/UniTask/Runtime/UniTask.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/UniTask.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 2292a17cf34064e31a92fb93723f5e28 +guid: 8947adf23181ff04db73829df217ca94 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/UniTaskCompletionSource.cs b/Runtime/Plugins/UniTask/Runtime/UniTaskCompletionSource.cs index 67b882ee..bf2d054b 100644 --- a/Runtime/Plugins/UniTask/Runtime/UniTaskCompletionSource.cs +++ b/Runtime/Plugins/UniTask/Runtime/UniTaskCompletionSource.cs @@ -137,8 +137,8 @@ public bool TrySetResult(TResult result) if (continuation != null || Interlocked.CompareExchange(ref this.continuation, UniTaskCompletionSourceCoreShared.s_sentinel, null) != null) { continuation(continuationState); - return true; } + return true; } return false; @@ -165,8 +165,8 @@ public bool TrySetException(Exception error) if (continuation != null || Interlocked.CompareExchange(ref this.continuation, UniTaskCompletionSourceCoreShared.s_sentinel, null) != null) { continuation(continuationState); - return true; } + return true; } return false; @@ -184,8 +184,8 @@ public bool TrySetCanceled(CancellationToken cancellationToken = default) if (continuation != null || Interlocked.CompareExchange(ref this.continuation, UniTaskCompletionSourceCoreShared.s_sentinel, null) != null) { continuation(continuationState); - return true; } + return true; } return false; @@ -328,6 +328,7 @@ static AutoResetUniTaskCompletionSource() } UniTaskCompletionSourceCore core; + short version; AutoResetUniTaskCompletionSource() { @@ -340,6 +341,7 @@ public static AutoResetUniTaskCompletionSource Create() { result = new AutoResetUniTaskCompletionSource(); } + result.version = result.core.Version; TaskTracker.TrackActiveTask(result, 2); return result; } @@ -383,19 +385,19 @@ public UniTask Task [DebuggerHidden] public bool TrySetResult() { - return core.TrySetResult(AsyncUnit.Default); + return version == core.Version && core.TrySetResult(AsyncUnit.Default); } [DebuggerHidden] public bool TrySetCanceled(CancellationToken cancellationToken = default) { - return core.TrySetCanceled(cancellationToken); + return version == core.Version && core.TrySetCanceled(cancellationToken); } [DebuggerHidden] public bool TrySetException(Exception exception) { - return core.TrySetException(exception); + return version == core.Version && core.TrySetException(exception); } [DebuggerHidden] @@ -409,7 +411,6 @@ public void GetResult(short token) { TryReturn(); } - } [DebuggerHidden] @@ -451,6 +452,7 @@ static AutoResetUniTaskCompletionSource() } UniTaskCompletionSourceCore core; + short version; AutoResetUniTaskCompletionSource() { @@ -463,6 +465,7 @@ public static AutoResetUniTaskCompletionSource Create() { result = new AutoResetUniTaskCompletionSource(); } + result.version = result.core.Version; TaskTracker.TrackActiveTask(result, 2); return result; } @@ -506,19 +509,19 @@ public UniTask Task [DebuggerHidden] public bool TrySetResult(T result) { - return core.TrySetResult(result); + return version == core.Version && core.TrySetResult(result); } [DebuggerHidden] public bool TrySetCanceled(CancellationToken cancellationToken = default) { - return core.TrySetCanceled(cancellationToken); + return version == core.Version && core.TrySetCanceled(cancellationToken); } [DebuggerHidden] public bool TrySetException(Exception exception) { - return core.TrySetException(exception); + return version == core.Version && core.TrySetException(exception); } [DebuggerHidden] @@ -937,5 +940,5 @@ bool TrySignalCompletion(UniTaskStatus status) } return false; } - } + } } \ No newline at end of file diff --git a/Runtime/Plugins/UniTask/Runtime/UniTaskCompletionSource.cs.meta b/Runtime/Plugins/UniTask/Runtime/UniTaskCompletionSource.cs.meta index 4e296796..2ae5ee31 100644 --- a/Runtime/Plugins/UniTask/Runtime/UniTaskCompletionSource.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/UniTaskCompletionSource.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: d2de3e742160f4b3099b82e0938880ae +guid: ed03524d09e7eb24a9fb9137198feb84 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/UniTaskExtensions.Shorthand.cs.meta b/Runtime/Plugins/UniTask/Runtime/UniTaskExtensions.Shorthand.cs.meta index 1b2911d2..e2dcc142 100644 --- a/Runtime/Plugins/UniTask/Runtime/UniTaskExtensions.Shorthand.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/UniTaskExtensions.Shorthand.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 8f80f81470bd04fdeaf83a58ec68f1b2 +guid: 4b4ff020f73dc6d4b8ebd4760d61fb43 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/UniTaskExtensions.cs b/Runtime/Plugins/UniTask/Runtime/UniTaskExtensions.cs index d3301090..362da525 100644 --- a/Runtime/Plugins/UniTask/Runtime/UniTaskExtensions.cs +++ b/Runtime/Plugins/UniTask/Runtime/UniTaskExtensions.cs @@ -28,7 +28,7 @@ public static UniTask AsUniTask(this Task task, bool useCurrentSynchron p.TrySetCanceled(); break; case TaskStatus.Faulted: - p.TrySetException(x.Exception); + p.TrySetException(x.Exception.InnerException ?? x.Exception); break; case TaskStatus.RanToCompletion: p.TrySetResult(x.Result); @@ -58,7 +58,7 @@ public static UniTask AsUniTask(this Task task, bool useCurrentSynchronizationCo p.TrySetCanceled(); break; case TaskStatus.Faulted: - p.TrySetException(x.Exception); + p.TrySetException(x.Exception.InnerException ?? x.Exception); break; case TaskStatus.RanToCompletion: p.TrySetResult(); diff --git a/Runtime/Plugins/UniTask/Runtime/UniTaskExtensions.cs.meta b/Runtime/Plugins/UniTask/Runtime/UniTaskExtensions.cs.meta index e89832a3..0d229460 100644 --- a/Runtime/Plugins/UniTask/Runtime/UniTaskExtensions.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/UniTaskExtensions.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 770f42f432e4446919a47f840e9f94ea +guid: 05460c617dae1e440861a7438535389f MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/UniTaskObservableExtensions.cs.meta b/Runtime/Plugins/UniTask/Runtime/UniTaskObservableExtensions.cs.meta index 62ca487f..527a49fc 100644 --- a/Runtime/Plugins/UniTask/Runtime/UniTaskObservableExtensions.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/UniTaskObservableExtensions.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 5a4329d381aa84f4482492b78f65d59d +guid: eaea262a5ad393d419c15b3b2901d664 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/UniTaskScheduler.cs.meta b/Runtime/Plugins/UniTask/Runtime/UniTaskScheduler.cs.meta index 5614edbf..5e29191f 100644 --- a/Runtime/Plugins/UniTask/Runtime/UniTaskScheduler.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/UniTaskScheduler.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: ea016913e101c474db1ac0877cd5efb8 +guid: d6cad69921702d5488d96b5ef30df1b0 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/UniTaskSynchronizationContext.cs.meta b/Runtime/Plugins/UniTask/Runtime/UniTaskSynchronizationContext.cs.meta index 30665c1b..9828c893 100644 --- a/Runtime/Plugins/UniTask/Runtime/UniTaskSynchronizationContext.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/UniTaskSynchronizationContext.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: f900f25aeddc84a1580fb97c9ca34d40 +guid: abf3aae9813db2849bce518f8596e920 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/UniTaskVoid.cs.meta b/Runtime/Plugins/UniTask/Runtime/UniTaskVoid.cs.meta index b574c381..01f7156c 100644 --- a/Runtime/Plugins/UniTask/Runtime/UniTaskVoid.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/UniTaskVoid.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 7d5192eb897614e43aa375973f381595 +guid: e9f28cd922179634d863011548f89ae7 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.AssetBundleRequestAllAssets.cs b/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.AssetBundleRequestAllAssets.cs index 1a1e011f..5d34692d 100644 --- a/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.AssetBundleRequestAllAssets.cs +++ b/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.AssetBundleRequestAllAssets.cs @@ -24,12 +24,17 @@ public static AssetBundleRequestAllAssetsAwaiter AwaitForAllAssets(this AssetBun return AwaitForAllAssets(asyncOperation, null, PlayerLoopTiming.Update, cancellationToken: cancellationToken); } - public static UniTask AwaitForAllAssets(this AssetBundleRequest asyncOperation, IProgress progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) + public static UniTask AwaitForAllAssets(this AssetBundleRequest asyncOperation, CancellationToken cancellationToken, bool cancelImmediately) + { + return AwaitForAllAssets(asyncOperation, progress: null, cancellationToken: cancellationToken, cancelImmediately: cancelImmediately); + } + + public static UniTask AwaitForAllAssets(this AssetBundleRequest asyncOperation, IProgress progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false) { Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation)); if (cancellationToken.IsCancellationRequested) return UniTask.FromCanceled(cancellationToken); if (asyncOperation.isDone) return UniTask.FromResult(asyncOperation.allAssets); - return new UniTask(AssetBundleRequestAllAssetsConfiguredSource.Create(asyncOperation, timing, progress, cancellationToken, out var token), token); + return new UniTask(AssetBundleRequestAllAssetsConfiguredSource.Create(asyncOperation, timing, progress, cancellationToken, cancelImmediately, out var token), token); } public struct AssetBundleRequestAllAssetsAwaiter : ICriticalNotifyCompletion @@ -95,15 +100,19 @@ static AssetBundleRequestAllAssetsConfiguredSource() AssetBundleRequest asyncOperation; IProgress progress; CancellationToken cancellationToken; + CancellationTokenRegistration cancellationTokenRegistration; + bool completed; UniTaskCompletionSourceCore core; + Action continuationAction; + AssetBundleRequestAllAssetsConfiguredSource() { - + continuationAction = Continuation; } - public static IUniTaskSource Create(AssetBundleRequest asyncOperation, PlayerLoopTiming timing, IProgress progress, CancellationToken cancellationToken, out short token) + public static IUniTaskSource Create(AssetBundleRequest asyncOperation, PlayerLoopTiming timing, IProgress progress, CancellationToken cancellationToken, bool cancelImmediately, out short token) { if (cancellationToken.IsCancellationRequested) { @@ -118,6 +127,18 @@ static AssetBundleRequestAllAssetsConfiguredSource() result.asyncOperation = asyncOperation; result.progress = progress; result.cancellationToken = cancellationToken; + result.completed = false; + + asyncOperation.completed += result.continuationAction; + + if (cancelImmediately && cancellationToken.CanBeCanceled) + { + result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => + { + var source = (AssetBundleRequestAllAssetsConfiguredSource)state; + source.core.TrySetCanceled(source.cancellationToken); + }, result); + } TaskTracker.TrackActiveTask(result, 3); @@ -161,6 +182,12 @@ public void OnCompleted(Action continuation, object state, short token) public bool MoveNext() { + // Already completed + if (completed || asyncOperation == null) + { + return false; + } + if (cancellationToken.IsCancellationRequested) { core.TrySetCanceled(cancellationToken); @@ -188,8 +215,29 @@ bool TryReturn() asyncOperation = default; progress = default; cancellationToken = default; + cancellationTokenRegistration.Dispose(); return pool.TryPush(this); } + + void Continuation(AsyncOperation _) + { + if (completed) + { + TryReturn(); + } + else + { + completed = true; + if (cancellationToken.IsCancellationRequested) + { + core.TrySetCanceled(cancellationToken); + } + else + { + core.TrySetResult(asyncOperation.allAssets); + } + } + } } } } diff --git a/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.AssetBundleRequestAllAssets.cs.meta b/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.AssetBundleRequestAllAssets.cs.meta index e49184c5..79be9231 100644 --- a/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.AssetBundleRequestAllAssets.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.AssetBundleRequestAllAssets.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: a97902fd5529c452cbbc5f3b92d22a85 +guid: e9147caba40da434da95b39709c13784 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.AsyncGPUReadback.cs b/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.AsyncGPUReadback.cs index 5805dbb1..5d73dc1a 100644 --- a/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.AsyncGPUReadback.cs +++ b/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.AsyncGPUReadback.cs @@ -20,12 +20,17 @@ public static UniTask WithCancellation(this AsyncGPURea return ToUniTask(asyncOperation, cancellationToken: cancellationToken); } - public static UniTask ToUniTask(this AsyncGPUReadbackRequest asyncOperation, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) + public static UniTask WithCancellation(this AsyncGPUReadbackRequest asyncOperation, CancellationToken cancellationToken, bool cancelImmediately) { - if (asyncOperation.done) return UniTask.FromResult(asyncOperation); - return new UniTask(AsyncGPUReadbackRequestAwaiterConfiguredSource.Create(asyncOperation, timing, cancellationToken, out var token), token); + return ToUniTask(asyncOperation, cancellationToken: cancellationToken, cancelImmediately: cancelImmediately); } + public static UniTask ToUniTask(this AsyncGPUReadbackRequest asyncOperation, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false) + { + if (asyncOperation.done) return UniTask.FromResult(asyncOperation); + return new UniTask(AsyncGPUReadbackRequestAwaiterConfiguredSource.Create(asyncOperation, timing, cancellationToken, cancelImmediately, out var token), token); + } + sealed class AsyncGPUReadbackRequestAwaiterConfiguredSource : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode { static TaskPool pool; @@ -39,15 +44,15 @@ static AsyncGPUReadbackRequestAwaiterConfiguredSource() AsyncGPUReadbackRequest asyncOperation; CancellationToken cancellationToken; + CancellationTokenRegistration cancellationTokenRegistration; UniTaskCompletionSourceCore core; AsyncGPUReadbackRequestAwaiterConfiguredSource() { - } - public static IUniTaskSource Create(AsyncGPUReadbackRequest asyncOperation, PlayerLoopTiming timing, CancellationToken cancellationToken, out short token) + public static IUniTaskSource Create(AsyncGPUReadbackRequest asyncOperation, PlayerLoopTiming timing, CancellationToken cancellationToken, bool cancelImmediately, out short token) { if (cancellationToken.IsCancellationRequested) { @@ -61,6 +66,15 @@ public static IUniTaskSource Create(AsyncGPUReadbackReq result.asyncOperation = asyncOperation; result.cancellationToken = cancellationToken; + + if (cancelImmediately && cancellationToken.CanBeCanceled) + { + result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => + { + var promise = (AsyncGPUReadbackRequestAwaiterConfiguredSource)state; + promise.core.TrySetCanceled(promise.cancellationToken); + }, result); + } TaskTracker.TrackActiveTask(result, 3); @@ -131,6 +145,7 @@ bool TryReturn() core.Reset(); asyncOperation = default; cancellationToken = default; + cancellationTokenRegistration.Dispose(); return pool.TryPush(this); } } diff --git a/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.AsyncGPUReadback.cs.meta b/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.AsyncGPUReadback.cs.meta index daf1c87f..510c49e3 100644 --- a/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.AsyncGPUReadback.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.AsyncGPUReadback.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: dfe829dd6f48342f487c01bade402417 +guid: 98f5fedb44749ab4688674d79126b46a MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.Jobs.cs.meta b/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.Jobs.cs.meta index 7390ffbc..c07df0b8 100644 --- a/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.Jobs.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.Jobs.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: ece57d271825444c8b1d758485529d0a +guid: 30979a768fbd4b94f8694eee8a305c99 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.MonoBehaviour.cs.meta b/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.MonoBehaviour.cs.meta index 8e2f0913..6e45863f 100644 --- a/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.MonoBehaviour.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.MonoBehaviour.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 0540c6e1f9f7b42fd8962098f30e244d +guid: 2edd588bb09eb0a4695d039d6a1f02b2 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.cs b/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.cs index 2f726041..b9cd1c9f 100644 --- a/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.cs +++ b/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.cs @@ -17,7 +17,6 @@ public static partial class UnityAsyncExtensions #if !UNITY_2023_1_OR_NEWER // from Unity2023.1.0a15, AsyncOperationAwaitableExtensions.GetAwaiter is defined in UnityEngine. - public static AsyncOperationAwaiter GetAwaiter(this AsyncOperation asyncOperation) { Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation)); @@ -30,12 +29,17 @@ public static UniTask WithCancellation(this AsyncOperation asyncOperation, Cance return ToUniTask(asyncOperation, cancellationToken: cancellationToken); } - public static UniTask ToUniTask(this AsyncOperation asyncOperation, IProgress progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) + public static UniTask WithCancellation(this AsyncOperation asyncOperation, CancellationToken cancellationToken, bool cancelImmediately) + { + return ToUniTask(asyncOperation, cancellationToken: cancellationToken, cancelImmediately: cancelImmediately); + } + + public static UniTask ToUniTask(this AsyncOperation asyncOperation, IProgress progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false) { Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation)); if (cancellationToken.IsCancellationRequested) return UniTask.FromCanceled(cancellationToken); if (asyncOperation.isDone) return UniTask.CompletedTask; - return new UniTask(AsyncOperationConfiguredSource.Create(asyncOperation, timing, progress, cancellationToken, out var token), token); + return new UniTask(AsyncOperationConfiguredSource.Create(asyncOperation, timing, progress, cancellationToken, cancelImmediately, out var token), token); } public struct AsyncOperationAwaiter : ICriticalNotifyCompletion @@ -92,15 +96,19 @@ static AsyncOperationConfiguredSource() AsyncOperation asyncOperation; IProgress progress; CancellationToken cancellationToken; + CancellationTokenRegistration cancellationTokenRegistration; + bool completed; UniTaskCompletionSourceCore core; + Action continuationAction; + AsyncOperationConfiguredSource() { - + continuationAction = Continuation; } - public static IUniTaskSource Create(AsyncOperation asyncOperation, PlayerLoopTiming timing, IProgress progress, CancellationToken cancellationToken, out short token) + public static IUniTaskSource Create(AsyncOperation asyncOperation, PlayerLoopTiming timing, IProgress progress, CancellationToken cancellationToken, bool cancelImmediately, out short token) { if (cancellationToken.IsCancellationRequested) { @@ -115,6 +123,18 @@ public static IUniTaskSource Create(AsyncOperation asyncOperation, PlayerLoopTim result.asyncOperation = asyncOperation; result.progress = progress; result.cancellationToken = cancellationToken; + result.completed = false; + + asyncOperation.completed += result.continuationAction; + + if (cancelImmediately && cancellationToken.CanBeCanceled) + { + result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => + { + var source = (AsyncOperationConfiguredSource)state; + source.core.TrySetCanceled(source.cancellationToken); + }, result); + } TaskTracker.TrackActiveTask(result, 3); @@ -154,6 +174,12 @@ public void OnCompleted(Action continuation, object state, short token) public bool MoveNext() { + // Already completed + if (completed || asyncOperation == null) + { + return false; + } + if (cancellationToken.IsCancellationRequested) { core.TrySetCanceled(cancellationToken); @@ -178,11 +204,33 @@ bool TryReturn() { TaskTracker.RemoveTracking(this); core.Reset(); + asyncOperation.completed -= continuationAction; asyncOperation = default; progress = default; cancellationToken = default; + cancellationTokenRegistration.Dispose(); return pool.TryPush(this); } + + void Continuation(AsyncOperation _) + { + if (completed) + { + TryReturn(); + } + else + { + completed = true; + if (cancellationToken.IsCancellationRequested) + { + core.TrySetCanceled(cancellationToken); + } + else + { + core.TrySetResult(AsyncUnit.Default); + } + } + } } #endregion @@ -200,12 +248,17 @@ public static ResourceRequestAwaiter GetAwaiter(this ResourceRequest asyncOperat return ToUniTask(asyncOperation, cancellationToken: cancellationToken); } - public static UniTask ToUniTask(this ResourceRequest asyncOperation, IProgress progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) + public static UniTask WithCancellation(this ResourceRequest asyncOperation, CancellationToken cancellationToken, bool cancelImmediately) + { + return ToUniTask(asyncOperation, cancellationToken: cancellationToken, cancelImmediately: cancelImmediately); + } + + public static UniTask ToUniTask(this ResourceRequest asyncOperation, IProgress progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false) { Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation)); if (cancellationToken.IsCancellationRequested) return UniTask.FromCanceled(cancellationToken); if (asyncOperation.isDone) return UniTask.FromResult(asyncOperation.asset); - return new UniTask(ResourceRequestConfiguredSource.Create(asyncOperation, timing, progress, cancellationToken, out var token), token); + return new UniTask(ResourceRequestConfiguredSource.Create(asyncOperation, timing, progress, cancellationToken, cancelImmediately, out var token), token); } public struct ResourceRequestAwaiter : ICriticalNotifyCompletion @@ -266,15 +319,19 @@ static ResourceRequestConfiguredSource() ResourceRequest asyncOperation; IProgress progress; CancellationToken cancellationToken; + CancellationTokenRegistration cancellationTokenRegistration; + bool completed; UniTaskCompletionSourceCore core; + Action continuationAction; + ResourceRequestConfiguredSource() { - + continuationAction = Continuation; } - public static IUniTaskSource Create(ResourceRequest asyncOperation, PlayerLoopTiming timing, IProgress progress, CancellationToken cancellationToken, out short token) + public static IUniTaskSource Create(ResourceRequest asyncOperation, PlayerLoopTiming timing, IProgress progress, CancellationToken cancellationToken, bool cancelImmediately, out short token) { if (cancellationToken.IsCancellationRequested) { @@ -289,6 +346,18 @@ static ResourceRequestConfiguredSource() result.asyncOperation = asyncOperation; result.progress = progress; result.cancellationToken = cancellationToken; + result.completed = false; + + asyncOperation.completed += result.continuationAction; + + if (cancelImmediately && cancellationToken.CanBeCanceled) + { + result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => + { + var source = (ResourceRequestConfiguredSource)state; + source.core.TrySetCanceled(source.cancellationToken); + }, result); + } TaskTracker.TrackActiveTask(result, 3); @@ -332,6 +401,12 @@ public void OnCompleted(Action continuation, object state, short token) public bool MoveNext() { + // Already completed + if (completed || asyncOperation == null) + { + return false; + } + if (cancellationToken.IsCancellationRequested) { core.TrySetCanceled(cancellationToken); @@ -356,11 +431,33 @@ bool TryReturn() { TaskTracker.RemoveTracking(this); core.Reset(); + asyncOperation.completed -= continuationAction; asyncOperation = default; progress = default; cancellationToken = default; + cancellationTokenRegistration.Dispose(); return pool.TryPush(this); } + + void Continuation(AsyncOperation _) + { + if (completed) + { + TryReturn(); + } + else + { + completed = true; + if (cancellationToken.IsCancellationRequested) + { + core.TrySetCanceled(cancellationToken); + } + else + { + core.TrySetResult(asyncOperation.asset); + } + } + } } #endregion @@ -379,12 +476,17 @@ public static AssetBundleRequestAwaiter GetAwaiter(this AssetBundleRequest async return ToUniTask(asyncOperation, cancellationToken: cancellationToken); } - public static UniTask ToUniTask(this AssetBundleRequest asyncOperation, IProgress progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) + public static UniTask WithCancellation(this AssetBundleRequest asyncOperation, CancellationToken cancellationToken, bool cancelImmediately) + { + return ToUniTask(asyncOperation, cancellationToken: cancellationToken, cancelImmediately: cancelImmediately); + } + + public static UniTask ToUniTask(this AssetBundleRequest asyncOperation, IProgress progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false) { Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation)); if (cancellationToken.IsCancellationRequested) return UniTask.FromCanceled(cancellationToken); if (asyncOperation.isDone) return UniTask.FromResult(asyncOperation.asset); - return new UniTask(AssetBundleRequestConfiguredSource.Create(asyncOperation, timing, progress, cancellationToken, out var token), token); + return new UniTask(AssetBundleRequestConfiguredSource.Create(asyncOperation, timing, progress, cancellationToken, cancelImmediately, out var token), token); } public struct AssetBundleRequestAwaiter : ICriticalNotifyCompletion @@ -445,15 +547,19 @@ static AssetBundleRequestConfiguredSource() AssetBundleRequest asyncOperation; IProgress progress; CancellationToken cancellationToken; + CancellationTokenRegistration cancellationTokenRegistration; + bool completed; UniTaskCompletionSourceCore core; + Action continuationAction; + AssetBundleRequestConfiguredSource() { - + continuationAction = Continuation; } - public static IUniTaskSource Create(AssetBundleRequest asyncOperation, PlayerLoopTiming timing, IProgress progress, CancellationToken cancellationToken, out short token) + public static IUniTaskSource Create(AssetBundleRequest asyncOperation, PlayerLoopTiming timing, IProgress progress, CancellationToken cancellationToken, bool cancelImmediately, out short token) { if (cancellationToken.IsCancellationRequested) { @@ -468,6 +574,18 @@ static AssetBundleRequestConfiguredSource() result.asyncOperation = asyncOperation; result.progress = progress; result.cancellationToken = cancellationToken; + result.completed = false; + + asyncOperation.completed += result.continuationAction; + + if (cancelImmediately && cancellationToken.CanBeCanceled) + { + result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => + { + var source = (AssetBundleRequestConfiguredSource)state; + source.core.TrySetCanceled(source.cancellationToken); + }, result); + } TaskTracker.TrackActiveTask(result, 3); @@ -511,6 +629,12 @@ public void OnCompleted(Action continuation, object state, short token) public bool MoveNext() { + // Already completed + if (completed || asyncOperation == null) + { + return false; + } + if (cancellationToken.IsCancellationRequested) { core.TrySetCanceled(cancellationToken); @@ -535,11 +659,33 @@ bool TryReturn() { TaskTracker.RemoveTracking(this); core.Reset(); + asyncOperation.completed -= continuationAction; asyncOperation = default; progress = default; cancellationToken = default; + cancellationTokenRegistration.Dispose(); return pool.TryPush(this); } + + void Continuation(AsyncOperation _) + { + if (completed) + { + TryReturn(); + } + else + { + completed = true; + if (cancellationToken.IsCancellationRequested) + { + core.TrySetCanceled(cancellationToken); + } + else + { + core.TrySetResult(asyncOperation.asset); + } + } + } } #endregion @@ -559,12 +705,17 @@ public static UniTask WithCancellation(this AssetBundleCreateReques return ToUniTask(asyncOperation, cancellationToken: cancellationToken); } - public static UniTask ToUniTask(this AssetBundleCreateRequest asyncOperation, IProgress progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) + public static UniTask WithCancellation(this AssetBundleCreateRequest asyncOperation, CancellationToken cancellationToken, bool cancelImmediately) + { + return ToUniTask(asyncOperation, cancellationToken: cancellationToken, cancelImmediately: cancelImmediately); + } + + public static UniTask ToUniTask(this AssetBundleCreateRequest asyncOperation, IProgress progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false) { Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation)); if (cancellationToken.IsCancellationRequested) return UniTask.FromCanceled(cancellationToken); if (asyncOperation.isDone) return UniTask.FromResult(asyncOperation.assetBundle); - return new UniTask(AssetBundleCreateRequestConfiguredSource.Create(asyncOperation, timing, progress, cancellationToken, out var token), token); + return new UniTask(AssetBundleCreateRequestConfiguredSource.Create(asyncOperation, timing, progress, cancellationToken, cancelImmediately, out var token), token); } public struct AssetBundleCreateRequestAwaiter : ICriticalNotifyCompletion @@ -625,15 +776,19 @@ static AssetBundleCreateRequestConfiguredSource() AssetBundleCreateRequest asyncOperation; IProgress progress; CancellationToken cancellationToken; + CancellationTokenRegistration cancellationTokenRegistration; + bool completed; UniTaskCompletionSourceCore core; + Action continuationAction; + AssetBundleCreateRequestConfiguredSource() { - + continuationAction = Continuation; } - public static IUniTaskSource Create(AssetBundleCreateRequest asyncOperation, PlayerLoopTiming timing, IProgress progress, CancellationToken cancellationToken, out short token) + public static IUniTaskSource Create(AssetBundleCreateRequest asyncOperation, PlayerLoopTiming timing, IProgress progress, CancellationToken cancellationToken, bool cancelImmediately, out short token) { if (cancellationToken.IsCancellationRequested) { @@ -648,6 +803,18 @@ public static IUniTaskSource Create(AssetBundleCreateRequest asyncO result.asyncOperation = asyncOperation; result.progress = progress; result.cancellationToken = cancellationToken; + result.completed = false; + + asyncOperation.completed += result.continuationAction; + + if (cancelImmediately && cancellationToken.CanBeCanceled) + { + result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => + { + var source = (AssetBundleCreateRequestConfiguredSource)state; + source.core.TrySetCanceled(source.cancellationToken); + }, result); + } TaskTracker.TrackActiveTask(result, 3); @@ -691,6 +858,12 @@ public void OnCompleted(Action continuation, object state, short token) public bool MoveNext() { + // Already completed + if (completed || asyncOperation == null) + { + return false; + } + if (cancellationToken.IsCancellationRequested) { core.TrySetCanceled(cancellationToken); @@ -715,11 +888,33 @@ bool TryReturn() { TaskTracker.RemoveTracking(this); core.Reset(); + asyncOperation.completed -= continuationAction; asyncOperation = default; progress = default; cancellationToken = default; + cancellationTokenRegistration.Dispose(); return pool.TryPush(this); } + + void Continuation(AsyncOperation _) + { + if (completed) + { + TryReturn(); + } + else + { + completed = true; + if (cancellationToken.IsCancellationRequested) + { + core.TrySetCanceled(cancellationToken); + } + else + { + core.TrySetResult(asyncOperation.assetBundle); + } + } + } } #endregion @@ -739,7 +934,12 @@ public static UniTask WithCancellation(this UnityWebRequestAsyn return ToUniTask(asyncOperation, cancellationToken: cancellationToken); } - public static UniTask ToUniTask(this UnityWebRequestAsyncOperation asyncOperation, IProgress progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken)) + public static UniTask WithCancellation(this UnityWebRequestAsyncOperation asyncOperation, CancellationToken cancellationToken, bool cancelImmediately) + { + return ToUniTask(asyncOperation, cancellationToken: cancellationToken, cancelImmediately: cancelImmediately); + } + + public static UniTask ToUniTask(this UnityWebRequestAsyncOperation asyncOperation, IProgress progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false) { Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation)); if (cancellationToken.IsCancellationRequested) return UniTask.FromCanceled(cancellationToken); @@ -751,7 +951,7 @@ public static UniTask WithCancellation(this UnityWebRequestAsyn } return UniTask.FromResult(asyncOperation.webRequest); } - return new UniTask(UnityWebRequestAsyncOperationConfiguredSource.Create(asyncOperation, timing, progress, cancellationToken, out var token), token); + return new UniTask(UnityWebRequestAsyncOperationConfiguredSource.Create(asyncOperation, timing, progress, cancellationToken, cancelImmediately, out var token), token); } public struct UnityWebRequestAsyncOperationAwaiter : ICriticalNotifyCompletion @@ -820,15 +1020,19 @@ static UnityWebRequestAsyncOperationConfiguredSource() UnityWebRequestAsyncOperation asyncOperation; IProgress progress; CancellationToken cancellationToken; + CancellationTokenRegistration cancellationTokenRegistration; + bool completed; UniTaskCompletionSourceCore core; + Action continuationAction; + UnityWebRequestAsyncOperationConfiguredSource() { - + continuationAction = Continuation; } - public static IUniTaskSource Create(UnityWebRequestAsyncOperation asyncOperation, PlayerLoopTiming timing, IProgress progress, CancellationToken cancellationToken, out short token) + public static IUniTaskSource Create(UnityWebRequestAsyncOperation asyncOperation, PlayerLoopTiming timing, IProgress progress, CancellationToken cancellationToken, bool cancelImmediately, out short token) { if (cancellationToken.IsCancellationRequested) { @@ -843,6 +1047,19 @@ public static IUniTaskSource Create(UnityWebRequestAsyncOperati result.asyncOperation = asyncOperation; result.progress = progress; result.cancellationToken = cancellationToken; + result.completed = false; + + asyncOperation.completed += result.continuationAction; + + if (cancelImmediately && cancellationToken.CanBeCanceled) + { + result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => + { + var source = (UnityWebRequestAsyncOperationConfiguredSource)state; + source.asyncOperation.webRequest.Abort(); + source.core.TrySetCanceled(source.cancellationToken); + }, result); + } TaskTracker.TrackActiveTask(result, 3); @@ -886,6 +1103,12 @@ public void OnCompleted(Action continuation, object state, short token) public bool MoveNext() { + // Already completed + if (completed || asyncOperation == null) + { + return false; + } + if (cancellationToken.IsCancellationRequested) { asyncOperation.webRequest.Abort(); @@ -918,11 +1141,37 @@ bool TryReturn() { TaskTracker.RemoveTracking(this); core.Reset(); + asyncOperation.completed -= continuationAction; asyncOperation = default; progress = default; cancellationToken = default; + cancellationTokenRegistration.Dispose(); return pool.TryPush(this); } + + void Continuation(AsyncOperation _) + { + if (completed) + { + TryReturn(); + } + else + { + completed = true; + if (cancellationToken.IsCancellationRequested) + { + core.TrySetCanceled(cancellationToken); + } + else if (asyncOperation.webRequest.IsError()) + { + core.TrySetException(new UnityWebRequestException(asyncOperation.webRequest)); + } + else + { + core.TrySetResult(asyncOperation.webRequest); + } + } + } } #endregion diff --git a/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.cs.meta b/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.cs.meta index bb22f53b..6dfab815 100644 --- a/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: c406bc570a700426c8b2d45162fb1ff6 +guid: 8cc7fd65dd1433e419be4764aeb51391 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.uGUI.cs.meta b/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.uGUI.cs.meta index 50a86f9c..90c5d515 100644 --- a/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.uGUI.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/UnityAsyncExtensions.uGUI.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: fb7ea1b03263e43f9bc5b96f99a21a89 +guid: 6804799fba2376d4099561d176101aff MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/UnityAwaitableExtensions.cs b/Runtime/Plugins/UniTask/Runtime/UnityAwaitableExtensions.cs new file mode 100644 index 00000000..4580da3a --- /dev/null +++ b/Runtime/Plugins/UniTask/Runtime/UnityAwaitableExtensions.cs @@ -0,0 +1,17 @@ +#if UNITY_2023_1_OR_NEWER +namespace Cysharp.Threading.Tasks +{ + public static class UnityAwaitableExtensions + { + public static async UniTask AsUniTask(this UnityEngine.Awaitable awaitable) + { + await awaitable; + } + + public static async UniTask AsUniTask(this UnityEngine.Awaitable awaitable) + { + return await awaitable; + } + } +} +#endif diff --git a/Runtime/Plugins/UniTask/Runtime/UnityAwaitableExtensions.cs.meta b/Runtime/Plugins/UniTask/Runtime/UnityAwaitableExtensions.cs.meta new file mode 100644 index 00000000..08752a42 --- /dev/null +++ b/Runtime/Plugins/UniTask/Runtime/UnityAwaitableExtensions.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c29533c9e4284dee914b71a6579ea274 +timeCreated: 1698895807 \ No newline at end of file diff --git a/Runtime/Plugins/UniTask/Runtime/UnityBindingExtensions.cs.meta b/Runtime/Plugins/UniTask/Runtime/UnityBindingExtensions.cs.meta index cea56643..3fae798e 100644 --- a/Runtime/Plugins/UniTask/Runtime/UnityBindingExtensions.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/UnityBindingExtensions.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: d6e448df71d364546933113cf36d2a3a +guid: 090b20e3528552b4a8d751f7df525c2b MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/UnityWebRequestException.cs.meta b/Runtime/Plugins/UniTask/Runtime/UnityWebRequestException.cs.meta index e2ae831d..50c475e8 100644 --- a/Runtime/Plugins/UniTask/Runtime/UnityWebRequestException.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/UnityWebRequestException.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 805d9fd994c6949929954ed327d11c49 +guid: 013a499e522703a42962a779b4d9850c MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/Runtime/_InternalVisibleTo.cs.meta b/Runtime/Plugins/UniTask/Runtime/_InternalVisibleTo.cs.meta index 23e36f66..2ec6cd36 100644 --- a/Runtime/Plugins/UniTask/Runtime/_InternalVisibleTo.cs.meta +++ b/Runtime/Plugins/UniTask/Runtime/_InternalVisibleTo.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 66fa2c3768fc44331886fb34605bf111 +guid: 8507e97eb606fad4b99c6edf92e19cb8 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Plugins/UniTask/package.json b/Runtime/Plugins/UniTask/package.json index 1aa6355b..84b5b0a3 100644 --- a/Runtime/Plugins/UniTask/package.json +++ b/Runtime/Plugins/UniTask/package.json @@ -1,20 +1,12 @@ { - "name": "com.cysharp.unitask", - "displayName": "UniTask", - "author": { - "name": "Cysharp, Inc.", - "url": "https://cysharp.co.jp/en/" - }, - "version": "2.3.3", - "unity": "2018.4", - "description": "Provides an efficient async/await integration to Unity.", - "keywords": [ - "async/await", - "async", - "Task", - "UniTask" - ], - "license": "MIT", - "category": "Task", - "dependencies": {} + "name": "com.cysharp.unitask", + "displayName": "UniTask", + "author": { "name": "Cysharp, Inc.", "url": "https://cysharp.co.jp/en/" }, + "version": "2.5.0", + "unity": "2018.4", + "description": "Provides an efficient async/await integration to Unity.", + "keywords": [ "async/await", "async", "Task", "UniTask" ], + "license": "MIT", + "category": "Task", + "dependencies": {} } diff --git a/Runtime/codebase/DeepLinkWallets/PhantomDeepLink.cs b/Runtime/codebase/DeepLinkWallets/PhantomDeepLink.cs index 4d1c9447..54c89489 100644 --- a/Runtime/codebase/DeepLinkWallets/PhantomDeepLink.cs +++ b/Runtime/codebase/DeepLinkWallets/PhantomDeepLink.cs @@ -112,6 +112,7 @@ private RpcCluster GetCluster() RpcCluster.DevNet => RpcCluster.DevNet, RpcCluster.TestNet => RpcCluster.TestNet, RpcCluster.MainNet => RpcCluster.MainNet, + RpcCluster.LocalNet => RpcCluster.LocalNet, _ => RpcCluster.MainNet }; } diff --git a/Runtime/codebase/DeepLinkWallets/Utils.cs b/Runtime/codebase/DeepLinkWallets/Utils.cs index 45eb7d72..3996c5e4 100644 --- a/Runtime/codebase/DeepLinkWallets/Utils.cs +++ b/Runtime/codebase/DeepLinkWallets/Utils.cs @@ -124,6 +124,7 @@ private static string GetClusterString(RpcCluster rpcCluster) RpcCluster.MainNet => "mainnet-beta", RpcCluster.DevNet => "devnet", RpcCluster.TestNet => "testnet", + RpcCluster.LocalNet => "localnet", _ => "mainnet-beta" }; } diff --git a/Runtime/codebase/SolanaMobileStack/LocalAssociationScenario.cs b/Runtime/codebase/SolanaMobileStack/LocalAssociationScenario.cs index a9e86fc6..1db054f2 100644 --- a/Runtime/codebase/SolanaMobileStack/LocalAssociationScenario.cs +++ b/Runtime/codebase/SolanaMobileStack/LocalAssociationScenario.cs @@ -41,7 +41,6 @@ public LocalAssociationScenario(int clientTimeoutMs = 9000) _didConnect = true; var helloReq = _session.CreateHelloReq(); _webSocket.Send(helloReq); - _webSocket.DispatchMessageQueue(); ListenKeyExchange(); }; _webSocket.OnClose += (e) => @@ -91,7 +90,6 @@ private async void ListenKeyExchange() { while (!_handledEncryptedMessage) { - _webSocket.DispatchMessageQueue(); var timeDelta = TimeSpan.FromMilliseconds(300); await Task.Delay(timeDelta); } diff --git a/Runtime/codebase/SolanaMobileStack/MobileWalletAdapterWebSocket.cs b/Runtime/codebase/SolanaMobileStack/MobileWalletAdapterWebSocket.cs index 89c47908..0272b484 100644 --- a/Runtime/codebase/SolanaMobileStack/MobileWalletAdapterWebSocket.cs +++ b/Runtime/codebase/SolanaMobileStack/MobileWalletAdapterWebSocket.cs @@ -21,6 +21,5 @@ public void Send(byte[] message) throw new ArgumentException("Message cannot be null or empty"); var encryptedMessage = _session.EncryptSessionPayload(message); _webSocket.Send(encryptedMessage); - _webSocket.DispatchMessageQueue(); } } \ No newline at end of file diff --git a/Runtime/codebase/WalletBase.cs b/Runtime/codebase/WalletBase.cs index be6a86a6..ab7835a3 100644 --- a/Runtime/codebase/WalletBase.cs +++ b/Runtime/codebase/WalletBase.cs @@ -21,7 +21,8 @@ public enum RpcCluster { MainNet = 0, DevNet = 1, - TestNet = 2 + TestNet = 2, + LocalNet = 3 } public abstract class WalletBase : IWalletBase @@ -36,7 +37,8 @@ public abstract class WalletBase : IWalletBase { { 0, Cluster.MainNet }, { 1, Cluster.DevNet }, - { 2, Cluster.TestNet } + { 2, Cluster.TestNet }, + { 3, Cluster.LocalNet } }; protected readonly Dictionary RPCNameMap = new () @@ -44,7 +46,7 @@ public abstract class WalletBase : IWalletBase { 0, "mainnet-beta" }, { 1, "devnet" }, { 2, "testnet" }, - { 3, "mainnet-beta" }, + { 3, "localnet" }, }; protected readonly string CustomRpcUri; diff --git a/Runtime/codebase/Web3.cs b/Runtime/codebase/Web3.cs index d68e732a..e95a2d12 100644 --- a/Runtime/codebase/Web3.cs +++ b/Runtime/codebase/Web3.cs @@ -107,6 +107,7 @@ public static event WalletChange OnWalletChangeState public static Action OnLogin; public static Action OnLogout; + public static Action OnWebSocketConnect; private static double _solAmount = 0; public delegate void BalanceChange(double sol); @@ -331,7 +332,7 @@ public static Task BlockHash( /// Notify all registered listeners /// /// - public static async UniTask UpdateBalance(Commitment commitment = Commitment.Confirmed) + public static async UniTask UpdateBalance(Commitment commitment = Commitment.Processed) { if (Instance == null || Instance.WalletBase == null) return; @@ -345,7 +346,7 @@ public static async UniTask UpdateBalance(Commitment commitment = Commitment.Con /// Notify all registered listeners /// /// - public static async UniTask UpdateNFTs(Commitment commitment = Commitment.Confirmed) + public static async UniTask UpdateNFTs(Commitment commitment = Commitment.Processed) { if(_isLoadingNfts) return; _isLoadingNfts = true; @@ -365,7 +366,7 @@ public static async UniTask UpdateNFTs(Commitment commitment = Commitment.Confir bool loadTexture = true, bool notifyRegisteredListeners = true, int requestsMillisecondsDelay = 0, - Commitment commitment = Commitment.Confirmed) + Commitment commitment = Commitment.Processed) { loadTexture = LoadNftsTextureByDefault ?? loadTexture; if(Wallet == null) return null; @@ -416,7 +417,7 @@ public static async UniTask UpdateNFTs(Commitment commitment = Commitment.Confir requestsMillisecondsDelay = Mathf.Max(requestsMillisecondsDelay, 100, NftLoadingRequestsDelay); } if (requestsMillisecondsDelay > 0) await UniTask.Delay(requestsMillisecondsDelay); - + await UniTask.SwitchToMainThread(); var tNft = Nft.Nft.TryGetNftData(item.Account.Data.Parsed.Info.Mint, Rpc, loadTexture: loadTexture).AsUniTask(); loadingTasks.Add(tNft); tNft.ContinueWith(nft => @@ -437,10 +438,11 @@ public static async UniTask UpdateNFTs(Commitment commitment = Commitment.Confir return nfts; } - private static async UniTask SubscribeToWalletEvents(Commitment commitment = Commitment.Confirmed) + private static async UniTask SubscribeToWalletEvents(Commitment commitment = Commitment.Processed) { if(WsRpc == null) return; await Wallet.AwaitWsRpcConnection(); + OnWebSocketConnect?.Invoke(); await WsRpc.SubscribeAccountInfoAsync( Account.PublicKey, (_, accountInfo) => diff --git a/Samples~/Solana Wallet/Scenes/wallet_scene.unity b/Samples~/Solana Wallet/Scenes/wallet_scene.unity index ebc4598f..7e05e0ac 100644 --- a/Samples~/Solana Wallet/Scenes/wallet_scene.unity +++ b/Samples~/Solana Wallet/Scenes/wallet_scene.unity @@ -104,7 +104,7 @@ NavMeshSettings: serializedVersion: 2 m_ObjectHideFlags: 0 m_BuildSettings: - serializedVersion: 3 + serializedVersion: 2 agentTypeID: 0 agentRadius: 0.5 agentHeight: 2 @@ -117,7 +117,7 @@ NavMeshSettings: cellSize: 0.16666667 manualTileSize: 0 tileSize: 256 - buildHeightMesh: 0 + accuratePlacement: 0 maxJobWorkers: 0 preserveTilesOutsideBounds: 0 debug: @@ -154,17 +154,9 @@ Camera: m_projectionMatrixMode: 1 m_GateFitMode: 2 m_FOVAxisMode: 0 - m_Iso: 200 - m_ShutterSpeed: 0.005 - m_Aperture: 16 - m_FocusDistance: 10 - m_FocalLength: 50 - m_BladeCount: 5 - m_Curvature: {x: 2, y: 11} - m_BarrelClipping: 0.25 - m_Anamorphism: 0 m_SensorSize: {x: 36, y: 24} m_LensShift: {x: 0, y: 0} + m_FocalLength: 50 m_NormalizedViewPortRect: serializedVersion: 2 x: 0 @@ -368,7 +360,6 @@ PrefabInstance: m_ObjectHideFlags: 0 serializedVersion: 2 m_Modification: - serializedVersion: 3 m_TransformParent: {fileID: 0} m_Modifications: - target: {fileID: 175970951105407052, guid: 51b19f34b566aa04ea3325e5810f314c, type: 3} @@ -423,6 +414,10 @@ PrefabInstance: propertyPath: m_AnchoredPosition.y value: 0 objectReference: {fileID: 0} + - target: {fileID: 1336760630763171628, guid: 51b19f34b566aa04ea3325e5810f314c, type: 3} + propertyPath: m_AnchoredPosition.x + value: 0.13024902 + objectReference: {fileID: 0} - target: {fileID: 1386163264363631060, guid: 51b19f34b566aa04ea3325e5810f314c, type: 3} propertyPath: m_AnchoredPosition.y value: 0 @@ -493,7 +488,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 3211121489190443638, guid: 51b19f34b566aa04ea3325e5810f314c, type: 3} propertyPath: m_AnchoredPosition.y - value: 0 + value: -34 objectReference: {fileID: 0} - target: {fileID: 3389550029039025430, guid: 51b19f34b566aa04ea3325e5810f314c, type: 3} propertyPath: m_AnchoredPosition.y @@ -695,6 +690,10 @@ PrefabInstance: propertyPath: m_AnchoredPosition.y value: 0 objectReference: {fileID: 0} + - target: {fileID: 5707216438012718698, guid: 51b19f34b566aa04ea3325e5810f314c, type: 3} + propertyPath: m_AnchoredPosition.x + value: -4.499756 + objectReference: {fileID: 0} - target: {fileID: 5707216438012718698, guid: 51b19f34b566aa04ea3325e5810f314c, type: 3} propertyPath: m_AnchoredPosition.y value: 0 @@ -940,16 +939,12 @@ PrefabInstance: value: 0 objectReference: {fileID: 0} m_RemovedComponents: [] - m_RemovedGameObjects: [] - m_AddedGameObjects: [] - m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 51b19f34b566aa04ea3325e5810f314c, type: 3} --- !u!1001 &6943455501189903268 PrefabInstance: m_ObjectHideFlags: 0 serializedVersion: 2 m_Modification: - serializedVersion: 3 m_TransformParent: {fileID: 0} m_Modifications: - target: {fileID: 6943455501282507180, guid: f43ecbac77afa435bacb53e2b24a8907, type: 3} @@ -1066,7 +1061,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 6943455502497181191, guid: f43ecbac77afa435bacb53e2b24a8907, type: 3} propertyPath: m_AnchoredPosition.y - value: 0 + value: 22 objectReference: {fileID: 0} - target: {fileID: 6943455502520650084, guid: f43ecbac77afa435bacb53e2b24a8907, type: 3} propertyPath: m_AnchoredPosition.y @@ -1081,7 +1076,4 @@ PrefabInstance: value: 0 objectReference: {fileID: 0} m_RemovedComponents: [] - m_RemovedGameObjects: [] - m_AddedGameObjects: [] - m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: f43ecbac77afa435bacb53e2b24a8907, type: 3} diff --git a/Samples~/Solana Wallet/Scripts/example/screens/WalletScreen.cs b/Samples~/Solana Wallet/Scripts/example/screens/WalletScreen.cs index 66ed49c2..f0b64352 100644 --- a/Samples~/Solana Wallet/Scripts/example/screens/WalletScreen.cs +++ b/Samples~/Solana Wallet/Scripts/example/screens/WalletScreen.cs @@ -151,7 +151,7 @@ private async UniTask GetOwnedTokenAccounts() { if(_isLoadingTokens) return; _isLoadingTokens = true; - var tokens = await Web3.Wallet.GetTokenAccounts(Commitment.Confirmed); + var tokens = await Web3.Wallet.GetTokenAccounts(Commitment.Processed); if(tokens == null) return; // Remove tokens not owned anymore and update amounts var tkToRemove = new List(); @@ -173,7 +173,10 @@ private async UniTask GetOwnedTokenAccounts() tkToRemove.ForEach(tk => { _instantiatedTokens.Remove(tk); - Destroy(tk.gameObject); + MainThreadDispatcher.Instance().Enqueue(() => + { + Destroy(tk.gameObject); + }); }); // Add new tokens List loadingTasks = new List(); @@ -186,22 +189,25 @@ private async UniTask GetOwnedTokenAccounts() if (!(item.Account.Data.Parsed.Info.TokenAmount.AmountUlong > 0)) break; if (_instantiatedTokens.All(t => t.TokenAccount.Account.Data.Parsed.Info.Mint != item.Account.Data.Parsed.Info.Mint)) { - var tk = Instantiate(tokenItem, tokenContainer, true); - tk.transform.localScale = Vector3.one; - - var loadTask = Nft.Nft.TryGetNftData(item.Account.Data.Parsed.Info.Mint, - Web3.Instance.WalletBase.ActiveRpcClient).AsUniTask(); - loadingTasks.Add(loadTask); - loadTask.ContinueWith(nft => + // Run in the main thread + await MainThreadDispatcher.Instance().EnqueueAsync(() => { - TokenItem tkInstance = tk.GetComponent(); - _instantiatedTokens.Add(tkInstance); - tk.SetActive(true); - if (tkInstance) + var tk = Instantiate(tokenItem, tokenContainer, true); + tk.transform.localScale = Vector3.one; + var loadTask = Nft.Nft.TryGetNftData(item.Account.Data.Parsed.Info.Mint, + Web3.Instance.WalletBase.ActiveRpcClient, commitment: Commitment.Processed).AsUniTask(); + loadingTasks.Add(loadTask); + loadTask.ContinueWith(nft => { - tkInstance.InitializeData(item, this, nft).Forget(); - } - }).Forget(); + TokenItem tkInstance = tk.GetComponent(); + _instantiatedTokens.Add(tkInstance); + tk.SetActive(true); + if (tkInstance) + { + tkInstance.InitializeData(item, this, nft).Forget(); + } + }).Forget(); + }); } } } diff --git a/Samples~/Solana Wallet/Textures/magicblock-logo.png.meta b/Samples~/Solana Wallet/Textures/magicblock-logo.png.meta index 608930d6..58c8b0c1 100644 --- a/Samples~/Solana Wallet/Textures/magicblock-logo.png.meta +++ b/Samples~/Solana Wallet/Textures/magicblock-logo.png.meta @@ -125,6 +125,18 @@ TextureImporter: overridden: 0 androidETC2FallbackOverride: 0 forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 spriteSheet: serializedVersion: 2 sprites: []