From 354fd65d58e9009027e9a30667fef641d35d6c38 Mon Sep 17 00:00:00 2001 From: neuecc Date: Tue, 12 May 2020 14:29:21 +0900 Subject: [PATCH] redesigned asyncenumerable ugui and monobehaviourmessagetrigger --- src/UniTask.NetCoreSandbox/Program.cs | 2 + .../UniTask/Triggers/AsyncTriggerBase.cs | 186 ++- .../Triggers/MonoBehaviourMessagesTriggers.cs | 1036 +++++++---------- .../Triggers/MonoBehaviourMessagesTriggers.tt | 15 +- .../UniTask/UnityAsyncExtensions.uGUI.cs | 459 ++++---- src/UniTask/Assets/Scenes/SandboxMain.cs | 29 +- 6 files changed, 810 insertions(+), 917 deletions(-) diff --git a/src/UniTask.NetCoreSandbox/Program.cs b/src/UniTask.NetCoreSandbox/Program.cs index ff83580..ca7bcb4 100644 --- a/src/UniTask.NetCoreSandbox/Program.cs +++ b/src/UniTask.NetCoreSandbox/Program.cs @@ -55,6 +55,8 @@ namespace NetCoreSandbox // AsyncEnumerable.Range(1, 10).GroupBy(x=>x).Select(x=>x.first + // AsyncEnumerable.Range(1,10).WithCancellation(CancellationToken.None).WithCancellation + //Enumerable.Range(1,10).ToHashSet( diff --git a/src/UniTask/Assets/Plugins/UniTask/Triggers/AsyncTriggerBase.cs b/src/UniTask/Assets/Plugins/UniTask/Triggers/AsyncTriggerBase.cs index 926bebc..2c43a31 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Triggers/AsyncTriggerBase.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Triggers/AsyncTriggerBase.cs @@ -1,16 +1,17 @@ #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member -using System; -using System.Collections.Generic; -using System.Threading; using Cysharp.Threading.Tasks.Internal; using Cysharp.Threading.Tasks.Linq; +using System; +using System.Threading; using UnityEngine; namespace Cysharp.Threading.Tasks.Triggers { - public abstract class AsyncTriggerBase : MonoBehaviour + public abstract class AsyncTriggerBase : MonoBehaviour, IUniTaskAsyncEnumerable { + protected TriggerEvent triggerEvent; + bool calledAwake; bool calledDestroy; ICancelPromise triggerSlot; @@ -20,14 +21,14 @@ namespace Cysharp.Threading.Tasks.Triggers calledAwake = true; } - protected TriggerEvent SetTriggerEvent(ref TriggerEvent field) + protected TriggerEvent GetTriggerEvent() { - if (field == null) + if (triggerEvent == null) { - field = new TriggerEvent(); + triggerEvent = new TriggerEvent(); if (triggerSlot == null) { - triggerSlot = field; + triggerSlot = triggerEvent; } else { @@ -40,7 +41,7 @@ namespace Cysharp.Threading.Tasks.Triggers PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, new AwakeMonitor(this)); } - return field; + return triggerEvent; } void OnDestroy() @@ -52,11 +53,87 @@ namespace Cysharp.Threading.Tasks.Triggers triggerSlot = null; } + public IUniTaskAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) + { + return new Enumerator(GetTriggerEvent(), cancellationToken); + } + + sealed class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator, IResolveCancelPromise + { + static Action cancellationCallback = CancellationCallback; + + readonly TriggerEvent triggerEvent; + CancellationToken cancellationToken; + CancellationTokenRegistration registration; + bool called; + bool isDisposed; + + public Enumerator(TriggerEvent triggerEvent, CancellationToken cancellationToken) + { + this.triggerEvent = triggerEvent; + this.cancellationToken = cancellationToken; + } + + public bool TrySetCanceled(CancellationToken cancellationToken = default) + { + return completionSource.TrySetCanceled(cancellationToken); + } + + public bool TrySetResult(T value) + { + Current = value; + return completionSource.TrySetResult(true); + } + + static void CancellationCallback(object state) + { + var self = (Enumerator)state; + self.DisposeAsync().Forget(); // sync + + self.completionSource.TrySetCanceled(self.cancellationToken); + } + + public T Current { get; private set; } + + public UniTask MoveNextAsync() + { + cancellationToken.ThrowIfCancellationRequested(); + completionSource.Reset(); + + if (!called) + { + called = true; + + TaskTracker.TrackActiveTask(this, 3); + triggerEvent.Add(this); + if (cancellationToken.CanBeCanceled) + { + registration = cancellationToken.RegisterWithoutCaptureExecutionContext(cancellationCallback, this); + } + } + + return new UniTask(this, completionSource.Version); + } + + public UniTask DisposeAsync() + { + if (!isDisposed) + { + isDisposed = true; + TaskTracker.RemoveTracking(this); + registration.Dispose(); + triggerEvent.Remove(this); + } + + return default; + } + } + class AwakeMonitor : IPlayerLoopItem { - readonly AsyncTriggerBase trigger; + readonly AsyncTriggerBase trigger; - public AwakeMonitor(AsyncTriggerBase trigger) + public AwakeMonitor(AsyncTriggerBase trigger) { this.trigger = trigger; } @@ -208,90 +285,6 @@ namespace Cysharp.Threading.Tasks.Triggers } } - public sealed class TriggerAsyncEnumerable : IUniTaskAsyncEnumerable - { - readonly TriggerEvent triggerEvent; - - public TriggerAsyncEnumerable(TriggerEvent triggerEvent) - { - this.triggerEvent = triggerEvent; - } - - public IUniTaskAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) - { - return new Enumerator(triggerEvent, cancellationToken); - } - - sealed class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator, IResolveCancelPromise - { - static Action cancellationCallback = CancellationCallback; - - readonly TriggerEvent triggerEvent; - CancellationToken cancellationToken; - CancellationTokenRegistration registration; - bool called; - bool isDisposed; - - public Enumerator(TriggerEvent triggerEvent, CancellationToken cancellationToken) - { - this.triggerEvent = triggerEvent; - this.cancellationToken = cancellationToken; - } - - public bool TrySetCanceled(CancellationToken cancellationToken = default) - { - return completionSource.TrySetCanceled(cancellationToken); - } - - public bool TrySetResult(T value) - { - Current = value; - return completionSource.TrySetResult(true); - } - - static void CancellationCallback(object state) - { - var self = (Enumerator)state; - self.DisposeAsync().Forget(); // sync - - self.completionSource.TrySetCanceled(self.cancellationToken); - } - - public T Current { get; private set; } - - public UniTask MoveNextAsync() - { - cancellationToken.ThrowIfCancellationRequested(); - - if (!called) - { - TaskTracker.TrackActiveTask(this, 3); - triggerEvent.Add(this); - if (cancellationToken.CanBeCanceled) - { - registration = cancellationToken.RegisterWithoutCaptureExecutionContext(cancellationCallback, this); - } - } - - completionSource.Reset(); - return new UniTask(this, completionSource.Version); - } - - public UniTask DisposeAsync() - { - if (!isDisposed) - { - isDisposed = true; - TaskTracker.RemoveTracking(this); - registration.Dispose(); - triggerEvent.Remove(this); - } - - return default; - } - } - } - public sealed class TriggerEvent : IResolveCancelPromise { // optimize: many cases, handler is single. @@ -493,5 +486,4 @@ namespace Cysharp.Threading.Tasks.Triggers } } } -} - +} \ No newline at end of file diff --git a/src/UniTask/Assets/Plugins/UniTask/Triggers/MonoBehaviourMessagesTriggers.cs b/src/UniTask/Assets/Plugins/UniTask/Triggers/MonoBehaviourMessagesTriggers.cs index da2e038..2504288 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Triggers/MonoBehaviourMessagesTriggers.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Triggers/MonoBehaviourMessagesTriggers.cs @@ -36,33 +36,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncFixedUpdateTrigger : AsyncTriggerBase + public sealed class AsyncFixedUpdateTrigger : AsyncTriggerBase { - TriggerEvent fixedUpdateTriggerEvent; - void FixedUpdate() { - fixedUpdateTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncFixedUpdateHandler GetFixedUpdateAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref fixedUpdateTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncFixedUpdateHandler GetFixedUpdateAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref fixedUpdateTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask FixedUpdateAsync() { - return ((IAsyncFixedUpdateHandler)new AsyncTriggerHandler(SetTriggerEvent(ref fixedUpdateTriggerEvent), true)).FixedUpdateAsync(); + return ((IAsyncFixedUpdateHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).FixedUpdateAsync(); } public UniTask FixedUpdateAsync(CancellationToken cancellationToken) { - return ((IAsyncFixedUpdateHandler)new AsyncTriggerHandler(SetTriggerEvent(ref fixedUpdateTriggerEvent), cancellationToken, true)).FixedUpdateAsync(); + return ((IAsyncFixedUpdateHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).FixedUpdateAsync(); } } #endregion @@ -97,33 +95,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncLateUpdateTrigger : AsyncTriggerBase + public sealed class AsyncLateUpdateTrigger : AsyncTriggerBase { - TriggerEvent lateUpdateTriggerEvent; - void LateUpdate() { - lateUpdateTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncLateUpdateHandler GetLateUpdateAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref lateUpdateTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncLateUpdateHandler GetLateUpdateAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref lateUpdateTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask LateUpdateAsync() { - return ((IAsyncLateUpdateHandler)new AsyncTriggerHandler(SetTriggerEvent(ref lateUpdateTriggerEvent), true)).LateUpdateAsync(); + return ((IAsyncLateUpdateHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).LateUpdateAsync(); } public UniTask LateUpdateAsync(CancellationToken cancellationToken) { - return ((IAsyncLateUpdateHandler)new AsyncTriggerHandler(SetTriggerEvent(ref lateUpdateTriggerEvent), cancellationToken, true)).LateUpdateAsync(); + return ((IAsyncLateUpdateHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).LateUpdateAsync(); } } #endregion @@ -158,33 +154,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncAnimatorIKTrigger : AsyncTriggerBase + public sealed class AsyncAnimatorIKTrigger : AsyncTriggerBase { - TriggerEvent onAnimatorIKTriggerEvent; - void OnAnimatorIK(int layerIndex) { - onAnimatorIKTriggerEvent?.TrySetResult((layerIndex)); + triggerEvent?.TrySetResult((layerIndex)); } public IAsyncOnAnimatorIKHandler GetOnAnimatorIKAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onAnimatorIKTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnAnimatorIKHandler GetOnAnimatorIKAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onAnimatorIKTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnAnimatorIKAsync() { - return ((IAsyncOnAnimatorIKHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onAnimatorIKTriggerEvent), true)).OnAnimatorIKAsync(); + return ((IAsyncOnAnimatorIKHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnAnimatorIKAsync(); } public UniTask OnAnimatorIKAsync(CancellationToken cancellationToken) { - return ((IAsyncOnAnimatorIKHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onAnimatorIKTriggerEvent), cancellationToken, true)).OnAnimatorIKAsync(); + return ((IAsyncOnAnimatorIKHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnAnimatorIKAsync(); } } #endregion @@ -219,33 +213,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncAnimatorMoveTrigger : AsyncTriggerBase + public sealed class AsyncAnimatorMoveTrigger : AsyncTriggerBase { - TriggerEvent onAnimatorMoveTriggerEvent; - void OnAnimatorMove() { - onAnimatorMoveTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncOnAnimatorMoveHandler GetOnAnimatorMoveAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onAnimatorMoveTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnAnimatorMoveHandler GetOnAnimatorMoveAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onAnimatorMoveTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnAnimatorMoveAsync() { - return ((IAsyncOnAnimatorMoveHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onAnimatorMoveTriggerEvent), true)).OnAnimatorMoveAsync(); + return ((IAsyncOnAnimatorMoveHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnAnimatorMoveAsync(); } public UniTask OnAnimatorMoveAsync(CancellationToken cancellationToken) { - return ((IAsyncOnAnimatorMoveHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onAnimatorMoveTriggerEvent), cancellationToken, true)).OnAnimatorMoveAsync(); + return ((IAsyncOnAnimatorMoveHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnAnimatorMoveAsync(); } } #endregion @@ -280,33 +272,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncApplicationFocusTrigger : AsyncTriggerBase + public sealed class AsyncApplicationFocusTrigger : AsyncTriggerBase { - TriggerEvent onApplicationFocusTriggerEvent; - void OnApplicationFocus(bool hasFocus) { - onApplicationFocusTriggerEvent?.TrySetResult((hasFocus)); + triggerEvent?.TrySetResult((hasFocus)); } public IAsyncOnApplicationFocusHandler GetOnApplicationFocusAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationFocusTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnApplicationFocusHandler GetOnApplicationFocusAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationFocusTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnApplicationFocusAsync() { - return ((IAsyncOnApplicationFocusHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationFocusTriggerEvent), true)).OnApplicationFocusAsync(); + return ((IAsyncOnApplicationFocusHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnApplicationFocusAsync(); } public UniTask OnApplicationFocusAsync(CancellationToken cancellationToken) { - return ((IAsyncOnApplicationFocusHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationFocusTriggerEvent), cancellationToken, true)).OnApplicationFocusAsync(); + return ((IAsyncOnApplicationFocusHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnApplicationFocusAsync(); } } #endregion @@ -341,33 +331,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncApplicationPauseTrigger : AsyncTriggerBase + public sealed class AsyncApplicationPauseTrigger : AsyncTriggerBase { - TriggerEvent onApplicationPauseTriggerEvent; - void OnApplicationPause(bool pauseStatus) { - onApplicationPauseTriggerEvent?.TrySetResult((pauseStatus)); + triggerEvent?.TrySetResult((pauseStatus)); } public IAsyncOnApplicationPauseHandler GetOnApplicationPauseAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationPauseTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnApplicationPauseHandler GetOnApplicationPauseAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationPauseTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnApplicationPauseAsync() { - return ((IAsyncOnApplicationPauseHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationPauseTriggerEvent), true)).OnApplicationPauseAsync(); + return ((IAsyncOnApplicationPauseHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnApplicationPauseAsync(); } public UniTask OnApplicationPauseAsync(CancellationToken cancellationToken) { - return ((IAsyncOnApplicationPauseHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationPauseTriggerEvent), cancellationToken, true)).OnApplicationPauseAsync(); + return ((IAsyncOnApplicationPauseHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnApplicationPauseAsync(); } } #endregion @@ -402,33 +390,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncApplicationQuitTrigger : AsyncTriggerBase + public sealed class AsyncApplicationQuitTrigger : AsyncTriggerBase { - TriggerEvent onApplicationQuitTriggerEvent; - void OnApplicationQuit() { - onApplicationQuitTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncOnApplicationQuitHandler GetOnApplicationQuitAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationQuitTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnApplicationQuitHandler GetOnApplicationQuitAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationQuitTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnApplicationQuitAsync() { - return ((IAsyncOnApplicationQuitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationQuitTriggerEvent), true)).OnApplicationQuitAsync(); + return ((IAsyncOnApplicationQuitHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnApplicationQuitAsync(); } public UniTask OnApplicationQuitAsync(CancellationToken cancellationToken) { - return ((IAsyncOnApplicationQuitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationQuitTriggerEvent), cancellationToken, true)).OnApplicationQuitAsync(); + return ((IAsyncOnApplicationQuitHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnApplicationQuitAsync(); } } #endregion @@ -463,33 +449,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncAudioFilterReadTrigger : AsyncTriggerBase + public sealed class AsyncAudioFilterReadTrigger : AsyncTriggerBase<(float[] data, int channels)> { - TriggerEvent<(float[] data, int channels)> onAudioFilterReadTriggerEvent; - void OnAudioFilterRead(float[] data, int channels) { - onAudioFilterReadTriggerEvent?.TrySetResult((data, channels)); + triggerEvent?.TrySetResult((data, channels)); } public IAsyncOnAudioFilterReadHandler GetOnAudioFilterReadAsyncHandler() { - return new AsyncTriggerHandler<(float[] data, int channels)>(SetTriggerEvent(ref onAudioFilterReadTriggerEvent), false); + return new AsyncTriggerHandler<(float[] data, int channels)>(GetTriggerEvent(), false); } public IAsyncOnAudioFilterReadHandler GetOnAudioFilterReadAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler<(float[] data, int channels)>(SetTriggerEvent(ref onAudioFilterReadTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler<(float[] data, int channels)>(GetTriggerEvent(), cancellationToken, false); } public UniTask<(float[] data, int channels)> OnAudioFilterReadAsync() { - return ((IAsyncOnAudioFilterReadHandler)new AsyncTriggerHandler<(float[] data, int channels)>(SetTriggerEvent(ref onAudioFilterReadTriggerEvent), true)).OnAudioFilterReadAsync(); + return ((IAsyncOnAudioFilterReadHandler)new AsyncTriggerHandler<(float[] data, int channels)>(GetTriggerEvent(), true)).OnAudioFilterReadAsync(); } public UniTask<(float[] data, int channels)> OnAudioFilterReadAsync(CancellationToken cancellationToken) { - return ((IAsyncOnAudioFilterReadHandler)new AsyncTriggerHandler<(float[] data, int channels)>(SetTriggerEvent(ref onAudioFilterReadTriggerEvent), cancellationToken, true)).OnAudioFilterReadAsync(); + return ((IAsyncOnAudioFilterReadHandler)new AsyncTriggerHandler<(float[] data, int channels)>(GetTriggerEvent(), cancellationToken, true)).OnAudioFilterReadAsync(); } } #endregion @@ -524,33 +508,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncBecameInvisibleTrigger : AsyncTriggerBase + public sealed class AsyncBecameInvisibleTrigger : AsyncTriggerBase { - TriggerEvent onBecameInvisibleTriggerEvent; - void OnBecameInvisible() { - onBecameInvisibleTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncOnBecameInvisibleHandler GetOnBecameInvisibleAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onBecameInvisibleTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnBecameInvisibleHandler GetOnBecameInvisibleAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onBecameInvisibleTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnBecameInvisibleAsync() { - return ((IAsyncOnBecameInvisibleHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onBecameInvisibleTriggerEvent), true)).OnBecameInvisibleAsync(); + return ((IAsyncOnBecameInvisibleHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnBecameInvisibleAsync(); } public UniTask OnBecameInvisibleAsync(CancellationToken cancellationToken) { - return ((IAsyncOnBecameInvisibleHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onBecameInvisibleTriggerEvent), cancellationToken, true)).OnBecameInvisibleAsync(); + return ((IAsyncOnBecameInvisibleHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnBecameInvisibleAsync(); } } #endregion @@ -585,33 +567,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncBecameVisibleTrigger : AsyncTriggerBase + public sealed class AsyncBecameVisibleTrigger : AsyncTriggerBase { - TriggerEvent onBecameVisibleTriggerEvent; - void OnBecameVisible() { - onBecameVisibleTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncOnBecameVisibleHandler GetOnBecameVisibleAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onBecameVisibleTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnBecameVisibleHandler GetOnBecameVisibleAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onBecameVisibleTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnBecameVisibleAsync() { - return ((IAsyncOnBecameVisibleHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onBecameVisibleTriggerEvent), true)).OnBecameVisibleAsync(); + return ((IAsyncOnBecameVisibleHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnBecameVisibleAsync(); } public UniTask OnBecameVisibleAsync(CancellationToken cancellationToken) { - return ((IAsyncOnBecameVisibleHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onBecameVisibleTriggerEvent), cancellationToken, true)).OnBecameVisibleAsync(); + return ((IAsyncOnBecameVisibleHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnBecameVisibleAsync(); } } #endregion @@ -646,33 +626,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncBeforeTransformParentChangedTrigger : AsyncTriggerBase + public sealed class AsyncBeforeTransformParentChangedTrigger : AsyncTriggerBase { - TriggerEvent onBeforeTransformParentChangedTriggerEvent; - void OnBeforeTransformParentChanged() { - onBeforeTransformParentChangedTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncOnBeforeTransformParentChangedHandler GetOnBeforeTransformParentChangedAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onBeforeTransformParentChangedTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnBeforeTransformParentChangedHandler GetOnBeforeTransformParentChangedAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onBeforeTransformParentChangedTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnBeforeTransformParentChangedAsync() { - return ((IAsyncOnBeforeTransformParentChangedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onBeforeTransformParentChangedTriggerEvent), true)).OnBeforeTransformParentChangedAsync(); + return ((IAsyncOnBeforeTransformParentChangedHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnBeforeTransformParentChangedAsync(); } public UniTask OnBeforeTransformParentChangedAsync(CancellationToken cancellationToken) { - return ((IAsyncOnBeforeTransformParentChangedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onBeforeTransformParentChangedTriggerEvent), cancellationToken, true)).OnBeforeTransformParentChangedAsync(); + return ((IAsyncOnBeforeTransformParentChangedHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnBeforeTransformParentChangedAsync(); } } #endregion @@ -707,33 +685,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncOnCanvasGroupChangedTrigger : AsyncTriggerBase + public sealed class AsyncOnCanvasGroupChangedTrigger : AsyncTriggerBase { - TriggerEvent onCanvasGroupChangedTriggerEvent; - void OnCanvasGroupChanged() { - onCanvasGroupChangedTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncOnCanvasGroupChangedHandler GetOnCanvasGroupChangedAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onCanvasGroupChangedTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnCanvasGroupChangedHandler GetOnCanvasGroupChangedAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onCanvasGroupChangedTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnCanvasGroupChangedAsync() { - return ((IAsyncOnCanvasGroupChangedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCanvasGroupChangedTriggerEvent), true)).OnCanvasGroupChangedAsync(); + return ((IAsyncOnCanvasGroupChangedHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnCanvasGroupChangedAsync(); } public UniTask OnCanvasGroupChangedAsync(CancellationToken cancellationToken) { - return ((IAsyncOnCanvasGroupChangedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCanvasGroupChangedTriggerEvent), cancellationToken, true)).OnCanvasGroupChangedAsync(); + return ((IAsyncOnCanvasGroupChangedHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnCanvasGroupChangedAsync(); } } #endregion @@ -768,33 +744,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncCollisionEnterTrigger : AsyncTriggerBase + public sealed class AsyncCollisionEnterTrigger : AsyncTriggerBase { - TriggerEvent onCollisionEnterTriggerEvent; - void OnCollisionEnter(Collision coll) { - onCollisionEnterTriggerEvent?.TrySetResult((coll)); + triggerEvent?.TrySetResult((coll)); } public IAsyncOnCollisionEnterHandler GetOnCollisionEnterAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionEnterTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnCollisionEnterHandler GetOnCollisionEnterAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionEnterTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnCollisionEnterAsync() { - return ((IAsyncOnCollisionEnterHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionEnterTriggerEvent), true)).OnCollisionEnterAsync(); + return ((IAsyncOnCollisionEnterHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnCollisionEnterAsync(); } public UniTask OnCollisionEnterAsync(CancellationToken cancellationToken) { - return ((IAsyncOnCollisionEnterHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionEnterTriggerEvent), cancellationToken, true)).OnCollisionEnterAsync(); + return ((IAsyncOnCollisionEnterHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnCollisionEnterAsync(); } } #endregion @@ -829,33 +803,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncCollisionEnter2DTrigger : AsyncTriggerBase + public sealed class AsyncCollisionEnter2DTrigger : AsyncTriggerBase { - TriggerEvent onCollisionEnter2DTriggerEvent; - void OnCollisionEnter2D(Collision2D coll) { - onCollisionEnter2DTriggerEvent?.TrySetResult((coll)); + triggerEvent?.TrySetResult((coll)); } public IAsyncOnCollisionEnter2DHandler GetOnCollisionEnter2DAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionEnter2DTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnCollisionEnter2DHandler GetOnCollisionEnter2DAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionEnter2DTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnCollisionEnter2DAsync() { - return ((IAsyncOnCollisionEnter2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionEnter2DTriggerEvent), true)).OnCollisionEnter2DAsync(); + return ((IAsyncOnCollisionEnter2DHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnCollisionEnter2DAsync(); } public UniTask OnCollisionEnter2DAsync(CancellationToken cancellationToken) { - return ((IAsyncOnCollisionEnter2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionEnter2DTriggerEvent), cancellationToken, true)).OnCollisionEnter2DAsync(); + return ((IAsyncOnCollisionEnter2DHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnCollisionEnter2DAsync(); } } #endregion @@ -890,33 +862,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncCollisionExitTrigger : AsyncTriggerBase + public sealed class AsyncCollisionExitTrigger : AsyncTriggerBase { - TriggerEvent onCollisionExitTriggerEvent; - void OnCollisionExit(Collision coll) { - onCollisionExitTriggerEvent?.TrySetResult((coll)); + triggerEvent?.TrySetResult((coll)); } public IAsyncOnCollisionExitHandler GetOnCollisionExitAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionExitTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnCollisionExitHandler GetOnCollisionExitAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionExitTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnCollisionExitAsync() { - return ((IAsyncOnCollisionExitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionExitTriggerEvent), true)).OnCollisionExitAsync(); + return ((IAsyncOnCollisionExitHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnCollisionExitAsync(); } public UniTask OnCollisionExitAsync(CancellationToken cancellationToken) { - return ((IAsyncOnCollisionExitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionExitTriggerEvent), cancellationToken, true)).OnCollisionExitAsync(); + return ((IAsyncOnCollisionExitHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnCollisionExitAsync(); } } #endregion @@ -951,33 +921,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncCollisionExit2DTrigger : AsyncTriggerBase + public sealed class AsyncCollisionExit2DTrigger : AsyncTriggerBase { - TriggerEvent onCollisionExit2DTriggerEvent; - void OnCollisionExit2D(Collision2D coll) { - onCollisionExit2DTriggerEvent?.TrySetResult((coll)); + triggerEvent?.TrySetResult((coll)); } public IAsyncOnCollisionExit2DHandler GetOnCollisionExit2DAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionExit2DTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnCollisionExit2DHandler GetOnCollisionExit2DAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionExit2DTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnCollisionExit2DAsync() { - return ((IAsyncOnCollisionExit2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionExit2DTriggerEvent), true)).OnCollisionExit2DAsync(); + return ((IAsyncOnCollisionExit2DHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnCollisionExit2DAsync(); } public UniTask OnCollisionExit2DAsync(CancellationToken cancellationToken) { - return ((IAsyncOnCollisionExit2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionExit2DTriggerEvent), cancellationToken, true)).OnCollisionExit2DAsync(); + return ((IAsyncOnCollisionExit2DHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnCollisionExit2DAsync(); } } #endregion @@ -1012,33 +980,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncCollisionStayTrigger : AsyncTriggerBase + public sealed class AsyncCollisionStayTrigger : AsyncTriggerBase { - TriggerEvent onCollisionStayTriggerEvent; - void OnCollisionStay(Collision coll) { - onCollisionStayTriggerEvent?.TrySetResult((coll)); + triggerEvent?.TrySetResult((coll)); } public IAsyncOnCollisionStayHandler GetOnCollisionStayAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionStayTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnCollisionStayHandler GetOnCollisionStayAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionStayTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnCollisionStayAsync() { - return ((IAsyncOnCollisionStayHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionStayTriggerEvent), true)).OnCollisionStayAsync(); + return ((IAsyncOnCollisionStayHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnCollisionStayAsync(); } public UniTask OnCollisionStayAsync(CancellationToken cancellationToken) { - return ((IAsyncOnCollisionStayHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionStayTriggerEvent), cancellationToken, true)).OnCollisionStayAsync(); + return ((IAsyncOnCollisionStayHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnCollisionStayAsync(); } } #endregion @@ -1073,33 +1039,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncCollisionStay2DTrigger : AsyncTriggerBase + public sealed class AsyncCollisionStay2DTrigger : AsyncTriggerBase { - TriggerEvent onCollisionStay2DTriggerEvent; - void OnCollisionStay2D(Collision2D coll) { - onCollisionStay2DTriggerEvent?.TrySetResult((coll)); + triggerEvent?.TrySetResult((coll)); } public IAsyncOnCollisionStay2DHandler GetOnCollisionStay2DAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionStay2DTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnCollisionStay2DHandler GetOnCollisionStay2DAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionStay2DTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnCollisionStay2DAsync() { - return ((IAsyncOnCollisionStay2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionStay2DTriggerEvent), true)).OnCollisionStay2DAsync(); + return ((IAsyncOnCollisionStay2DHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnCollisionStay2DAsync(); } public UniTask OnCollisionStay2DAsync(CancellationToken cancellationToken) { - return ((IAsyncOnCollisionStay2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionStay2DTriggerEvent), cancellationToken, true)).OnCollisionStay2DAsync(); + return ((IAsyncOnCollisionStay2DHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnCollisionStay2DAsync(); } } #endregion @@ -1134,33 +1098,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncControllerColliderHitTrigger : AsyncTriggerBase + public sealed class AsyncControllerColliderHitTrigger : AsyncTriggerBase { - TriggerEvent onControllerColliderHitTriggerEvent; - void OnControllerColliderHit(ControllerColliderHit hit) { - onControllerColliderHitTriggerEvent?.TrySetResult((hit)); + triggerEvent?.TrySetResult((hit)); } public IAsyncOnControllerColliderHitHandler GetOnControllerColliderHitAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onControllerColliderHitTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnControllerColliderHitHandler GetOnControllerColliderHitAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onControllerColliderHitTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnControllerColliderHitAsync() { - return ((IAsyncOnControllerColliderHitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onControllerColliderHitTriggerEvent), true)).OnControllerColliderHitAsync(); + return ((IAsyncOnControllerColliderHitHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnControllerColliderHitAsync(); } public UniTask OnControllerColliderHitAsync(CancellationToken cancellationToken) { - return ((IAsyncOnControllerColliderHitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onControllerColliderHitTriggerEvent), cancellationToken, true)).OnControllerColliderHitAsync(); + return ((IAsyncOnControllerColliderHitHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnControllerColliderHitAsync(); } } #endregion @@ -1195,33 +1157,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncDisableTrigger : AsyncTriggerBase + public sealed class AsyncDisableTrigger : AsyncTriggerBase { - TriggerEvent onDisableTriggerEvent; - void OnDisable() { - onDisableTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncOnDisableHandler GetOnDisableAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onDisableTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnDisableHandler GetOnDisableAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onDisableTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnDisableAsync() { - return ((IAsyncOnDisableHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDisableTriggerEvent), true)).OnDisableAsync(); + return ((IAsyncOnDisableHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnDisableAsync(); } public UniTask OnDisableAsync(CancellationToken cancellationToken) { - return ((IAsyncOnDisableHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDisableTriggerEvent), cancellationToken, true)).OnDisableAsync(); + return ((IAsyncOnDisableHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnDisableAsync(); } } #endregion @@ -1256,33 +1216,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncDrawGizmosTrigger : AsyncTriggerBase + public sealed class AsyncDrawGizmosTrigger : AsyncTriggerBase { - TriggerEvent onDrawGizmosTriggerEvent; - void OnDrawGizmos() { - onDrawGizmosTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncOnDrawGizmosHandler GetOnDrawGizmosAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onDrawGizmosTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnDrawGizmosHandler GetOnDrawGizmosAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onDrawGizmosTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnDrawGizmosAsync() { - return ((IAsyncOnDrawGizmosHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDrawGizmosTriggerEvent), true)).OnDrawGizmosAsync(); + return ((IAsyncOnDrawGizmosHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnDrawGizmosAsync(); } public UniTask OnDrawGizmosAsync(CancellationToken cancellationToken) { - return ((IAsyncOnDrawGizmosHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDrawGizmosTriggerEvent), cancellationToken, true)).OnDrawGizmosAsync(); + return ((IAsyncOnDrawGizmosHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnDrawGizmosAsync(); } } #endregion @@ -1317,33 +1275,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncDrawGizmosSelectedTrigger : AsyncTriggerBase + public sealed class AsyncDrawGizmosSelectedTrigger : AsyncTriggerBase { - TriggerEvent onDrawGizmosSelectedTriggerEvent; - void OnDrawGizmosSelected() { - onDrawGizmosSelectedTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncOnDrawGizmosSelectedHandler GetOnDrawGizmosSelectedAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onDrawGizmosSelectedTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnDrawGizmosSelectedHandler GetOnDrawGizmosSelectedAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onDrawGizmosSelectedTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnDrawGizmosSelectedAsync() { - return ((IAsyncOnDrawGizmosSelectedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDrawGizmosSelectedTriggerEvent), true)).OnDrawGizmosSelectedAsync(); + return ((IAsyncOnDrawGizmosSelectedHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnDrawGizmosSelectedAsync(); } public UniTask OnDrawGizmosSelectedAsync(CancellationToken cancellationToken) { - return ((IAsyncOnDrawGizmosSelectedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDrawGizmosSelectedTriggerEvent), cancellationToken, true)).OnDrawGizmosSelectedAsync(); + return ((IAsyncOnDrawGizmosSelectedHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnDrawGizmosSelectedAsync(); } } #endregion @@ -1378,33 +1334,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncEnableTrigger : AsyncTriggerBase + public sealed class AsyncEnableTrigger : AsyncTriggerBase { - TriggerEvent onEnableTriggerEvent; - void OnEnable() { - onEnableTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncOnEnableHandler GetOnEnableAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onEnableTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnEnableHandler GetOnEnableAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onEnableTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnEnableAsync() { - return ((IAsyncOnEnableHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onEnableTriggerEvent), true)).OnEnableAsync(); + return ((IAsyncOnEnableHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnEnableAsync(); } public UniTask OnEnableAsync(CancellationToken cancellationToken) { - return ((IAsyncOnEnableHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onEnableTriggerEvent), cancellationToken, true)).OnEnableAsync(); + return ((IAsyncOnEnableHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnEnableAsync(); } } #endregion @@ -1439,33 +1393,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncGUITrigger : AsyncTriggerBase + public sealed class AsyncGUITrigger : AsyncTriggerBase { - TriggerEvent onGUITriggerEvent; - void OnGUI() { - onGUITriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncOnGUIHandler GetOnGUIAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onGUITriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnGUIHandler GetOnGUIAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onGUITriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnGUIAsync() { - return ((IAsyncOnGUIHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onGUITriggerEvent), true)).OnGUIAsync(); + return ((IAsyncOnGUIHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnGUIAsync(); } public UniTask OnGUIAsync(CancellationToken cancellationToken) { - return ((IAsyncOnGUIHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onGUITriggerEvent), cancellationToken, true)).OnGUIAsync(); + return ((IAsyncOnGUIHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnGUIAsync(); } } #endregion @@ -1500,33 +1452,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncJointBreakTrigger : AsyncTriggerBase + public sealed class AsyncJointBreakTrigger : AsyncTriggerBase { - TriggerEvent onJointBreakTriggerEvent; - void OnJointBreak(float breakForce) { - onJointBreakTriggerEvent?.TrySetResult((breakForce)); + triggerEvent?.TrySetResult((breakForce)); } public IAsyncOnJointBreakHandler GetOnJointBreakAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onJointBreakTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnJointBreakHandler GetOnJointBreakAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onJointBreakTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnJointBreakAsync() { - return ((IAsyncOnJointBreakHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onJointBreakTriggerEvent), true)).OnJointBreakAsync(); + return ((IAsyncOnJointBreakHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnJointBreakAsync(); } public UniTask OnJointBreakAsync(CancellationToken cancellationToken) { - return ((IAsyncOnJointBreakHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onJointBreakTriggerEvent), cancellationToken, true)).OnJointBreakAsync(); + return ((IAsyncOnJointBreakHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnJointBreakAsync(); } } #endregion @@ -1561,33 +1511,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncJointBreak2DTrigger : AsyncTriggerBase + public sealed class AsyncJointBreak2DTrigger : AsyncTriggerBase { - TriggerEvent onJointBreak2DTriggerEvent; - void OnJointBreak2D(Joint2D brokenJoint) { - onJointBreak2DTriggerEvent?.TrySetResult((brokenJoint)); + triggerEvent?.TrySetResult((brokenJoint)); } public IAsyncOnJointBreak2DHandler GetOnJointBreak2DAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onJointBreak2DTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnJointBreak2DHandler GetOnJointBreak2DAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onJointBreak2DTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnJointBreak2DAsync() { - return ((IAsyncOnJointBreak2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onJointBreak2DTriggerEvent), true)).OnJointBreak2DAsync(); + return ((IAsyncOnJointBreak2DHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnJointBreak2DAsync(); } public UniTask OnJointBreak2DAsync(CancellationToken cancellationToken) { - return ((IAsyncOnJointBreak2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onJointBreak2DTriggerEvent), cancellationToken, true)).OnJointBreak2DAsync(); + return ((IAsyncOnJointBreak2DHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnJointBreak2DAsync(); } } #endregion @@ -1622,33 +1570,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncMouseDownTrigger : AsyncTriggerBase + public sealed class AsyncMouseDownTrigger : AsyncTriggerBase { - TriggerEvent onMouseDownTriggerEvent; - void OnMouseDown() { - onMouseDownTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncOnMouseDownHandler GetOnMouseDownAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseDownTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnMouseDownHandler GetOnMouseDownAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseDownTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnMouseDownAsync() { - return ((IAsyncOnMouseDownHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseDownTriggerEvent), true)).OnMouseDownAsync(); + return ((IAsyncOnMouseDownHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnMouseDownAsync(); } public UniTask OnMouseDownAsync(CancellationToken cancellationToken) { - return ((IAsyncOnMouseDownHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseDownTriggerEvent), cancellationToken, true)).OnMouseDownAsync(); + return ((IAsyncOnMouseDownHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnMouseDownAsync(); } } #endregion @@ -1683,33 +1629,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncMouseDragTrigger : AsyncTriggerBase + public sealed class AsyncMouseDragTrigger : AsyncTriggerBase { - TriggerEvent onMouseDragTriggerEvent; - void OnMouseDrag() { - onMouseDragTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncOnMouseDragHandler GetOnMouseDragAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseDragTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnMouseDragHandler GetOnMouseDragAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseDragTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnMouseDragAsync() { - return ((IAsyncOnMouseDragHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseDragTriggerEvent), true)).OnMouseDragAsync(); + return ((IAsyncOnMouseDragHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnMouseDragAsync(); } public UniTask OnMouseDragAsync(CancellationToken cancellationToken) { - return ((IAsyncOnMouseDragHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseDragTriggerEvent), cancellationToken, true)).OnMouseDragAsync(); + return ((IAsyncOnMouseDragHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnMouseDragAsync(); } } #endregion @@ -1744,33 +1688,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncMouseEnterTrigger : AsyncTriggerBase + public sealed class AsyncMouseEnterTrigger : AsyncTriggerBase { - TriggerEvent onMouseEnterTriggerEvent; - void OnMouseEnter() { - onMouseEnterTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncOnMouseEnterHandler GetOnMouseEnterAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseEnterTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnMouseEnterHandler GetOnMouseEnterAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseEnterTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnMouseEnterAsync() { - return ((IAsyncOnMouseEnterHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseEnterTriggerEvent), true)).OnMouseEnterAsync(); + return ((IAsyncOnMouseEnterHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnMouseEnterAsync(); } public UniTask OnMouseEnterAsync(CancellationToken cancellationToken) { - return ((IAsyncOnMouseEnterHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseEnterTriggerEvent), cancellationToken, true)).OnMouseEnterAsync(); + return ((IAsyncOnMouseEnterHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnMouseEnterAsync(); } } #endregion @@ -1805,33 +1747,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncMouseExitTrigger : AsyncTriggerBase + public sealed class AsyncMouseExitTrigger : AsyncTriggerBase { - TriggerEvent onMouseExitTriggerEvent; - void OnMouseExit() { - onMouseExitTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncOnMouseExitHandler GetOnMouseExitAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseExitTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnMouseExitHandler GetOnMouseExitAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseExitTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnMouseExitAsync() { - return ((IAsyncOnMouseExitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseExitTriggerEvent), true)).OnMouseExitAsync(); + return ((IAsyncOnMouseExitHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnMouseExitAsync(); } public UniTask OnMouseExitAsync(CancellationToken cancellationToken) { - return ((IAsyncOnMouseExitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseExitTriggerEvent), cancellationToken, true)).OnMouseExitAsync(); + return ((IAsyncOnMouseExitHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnMouseExitAsync(); } } #endregion @@ -1866,33 +1806,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncMouseOverTrigger : AsyncTriggerBase + public sealed class AsyncMouseOverTrigger : AsyncTriggerBase { - TriggerEvent onMouseOverTriggerEvent; - void OnMouseOver() { - onMouseOverTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncOnMouseOverHandler GetOnMouseOverAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseOverTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnMouseOverHandler GetOnMouseOverAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseOverTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnMouseOverAsync() { - return ((IAsyncOnMouseOverHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseOverTriggerEvent), true)).OnMouseOverAsync(); + return ((IAsyncOnMouseOverHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnMouseOverAsync(); } public UniTask OnMouseOverAsync(CancellationToken cancellationToken) { - return ((IAsyncOnMouseOverHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseOverTriggerEvent), cancellationToken, true)).OnMouseOverAsync(); + return ((IAsyncOnMouseOverHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnMouseOverAsync(); } } #endregion @@ -1927,33 +1865,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncMouseUpTrigger : AsyncTriggerBase + public sealed class AsyncMouseUpTrigger : AsyncTriggerBase { - TriggerEvent onMouseUpTriggerEvent; - void OnMouseUp() { - onMouseUpTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncOnMouseUpHandler GetOnMouseUpAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseUpTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnMouseUpHandler GetOnMouseUpAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseUpTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnMouseUpAsync() { - return ((IAsyncOnMouseUpHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseUpTriggerEvent), true)).OnMouseUpAsync(); + return ((IAsyncOnMouseUpHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnMouseUpAsync(); } public UniTask OnMouseUpAsync(CancellationToken cancellationToken) { - return ((IAsyncOnMouseUpHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseUpTriggerEvent), cancellationToken, true)).OnMouseUpAsync(); + return ((IAsyncOnMouseUpHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnMouseUpAsync(); } } #endregion @@ -1988,33 +1924,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncMouseUpAsButtonTrigger : AsyncTriggerBase + public sealed class AsyncMouseUpAsButtonTrigger : AsyncTriggerBase { - TriggerEvent onMouseUpAsButtonTriggerEvent; - void OnMouseUpAsButton() { - onMouseUpAsButtonTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncOnMouseUpAsButtonHandler GetOnMouseUpAsButtonAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseUpAsButtonTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnMouseUpAsButtonHandler GetOnMouseUpAsButtonAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseUpAsButtonTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnMouseUpAsButtonAsync() { - return ((IAsyncOnMouseUpAsButtonHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseUpAsButtonTriggerEvent), true)).OnMouseUpAsButtonAsync(); + return ((IAsyncOnMouseUpAsButtonHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnMouseUpAsButtonAsync(); } public UniTask OnMouseUpAsButtonAsync(CancellationToken cancellationToken) { - return ((IAsyncOnMouseUpAsButtonHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseUpAsButtonTriggerEvent), cancellationToken, true)).OnMouseUpAsButtonAsync(); + return ((IAsyncOnMouseUpAsButtonHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnMouseUpAsButtonAsync(); } } #endregion @@ -2049,33 +1983,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncParticleCollisionTrigger : AsyncTriggerBase + public sealed class AsyncParticleCollisionTrigger : AsyncTriggerBase { - TriggerEvent onParticleCollisionTriggerEvent; - void OnParticleCollision(GameObject other) { - onParticleCollisionTriggerEvent?.TrySetResult((other)); + triggerEvent?.TrySetResult((other)); } public IAsyncOnParticleCollisionHandler GetOnParticleCollisionAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onParticleCollisionTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnParticleCollisionHandler GetOnParticleCollisionAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onParticleCollisionTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnParticleCollisionAsync() { - return ((IAsyncOnParticleCollisionHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onParticleCollisionTriggerEvent), true)).OnParticleCollisionAsync(); + return ((IAsyncOnParticleCollisionHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnParticleCollisionAsync(); } public UniTask OnParticleCollisionAsync(CancellationToken cancellationToken) { - return ((IAsyncOnParticleCollisionHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onParticleCollisionTriggerEvent), cancellationToken, true)).OnParticleCollisionAsync(); + return ((IAsyncOnParticleCollisionHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnParticleCollisionAsync(); } } #endregion @@ -2110,33 +2042,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncParticleSystemStoppedTrigger : AsyncTriggerBase + public sealed class AsyncParticleSystemStoppedTrigger : AsyncTriggerBase { - TriggerEvent onParticleSystemStoppedTriggerEvent; - void OnParticleSystemStopped() { - onParticleSystemStoppedTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncOnParticleSystemStoppedHandler GetOnParticleSystemStoppedAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onParticleSystemStoppedTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnParticleSystemStoppedHandler GetOnParticleSystemStoppedAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onParticleSystemStoppedTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnParticleSystemStoppedAsync() { - return ((IAsyncOnParticleSystemStoppedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onParticleSystemStoppedTriggerEvent), true)).OnParticleSystemStoppedAsync(); + return ((IAsyncOnParticleSystemStoppedHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnParticleSystemStoppedAsync(); } public UniTask OnParticleSystemStoppedAsync(CancellationToken cancellationToken) { - return ((IAsyncOnParticleSystemStoppedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onParticleSystemStoppedTriggerEvent), cancellationToken, true)).OnParticleSystemStoppedAsync(); + return ((IAsyncOnParticleSystemStoppedHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnParticleSystemStoppedAsync(); } } #endregion @@ -2171,33 +2101,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncParticleTriggerTrigger : AsyncTriggerBase + public sealed class AsyncParticleTriggerTrigger : AsyncTriggerBase { - TriggerEvent onParticleTriggerTriggerEvent; - void OnParticleTrigger() { - onParticleTriggerTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncOnParticleTriggerHandler GetOnParticleTriggerAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onParticleTriggerTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnParticleTriggerHandler GetOnParticleTriggerAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onParticleTriggerTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnParticleTriggerAsync() { - return ((IAsyncOnParticleTriggerHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onParticleTriggerTriggerEvent), true)).OnParticleTriggerAsync(); + return ((IAsyncOnParticleTriggerHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnParticleTriggerAsync(); } public UniTask OnParticleTriggerAsync(CancellationToken cancellationToken) { - return ((IAsyncOnParticleTriggerHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onParticleTriggerTriggerEvent), cancellationToken, true)).OnParticleTriggerAsync(); + return ((IAsyncOnParticleTriggerHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnParticleTriggerAsync(); } } #endregion @@ -2233,33 +2161,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncParticleUpdateJobScheduledTrigger : AsyncTriggerBase + public sealed class AsyncParticleUpdateJobScheduledTrigger : AsyncTriggerBase { - TriggerEvent onParticleUpdateJobScheduledTriggerEvent; - void OnParticleUpdateJobScheduled(UnityEngine.ParticleSystemJobs.ParticleSystemJobData particles) { - onParticleUpdateJobScheduledTriggerEvent?.TrySetResult((particles)); + triggerEvent?.TrySetResult((particles)); } public IAsyncOnParticleUpdateJobScheduledHandler GetOnParticleUpdateJobScheduledAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onParticleUpdateJobScheduledTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnParticleUpdateJobScheduledHandler GetOnParticleUpdateJobScheduledAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onParticleUpdateJobScheduledTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnParticleUpdateJobScheduledAsync() { - return ((IAsyncOnParticleUpdateJobScheduledHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onParticleUpdateJobScheduledTriggerEvent), true)).OnParticleUpdateJobScheduledAsync(); + return ((IAsyncOnParticleUpdateJobScheduledHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnParticleUpdateJobScheduledAsync(); } public UniTask OnParticleUpdateJobScheduledAsync(CancellationToken cancellationToken) { - return ((IAsyncOnParticleUpdateJobScheduledHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onParticleUpdateJobScheduledTriggerEvent), cancellationToken, true)).OnParticleUpdateJobScheduledAsync(); + return ((IAsyncOnParticleUpdateJobScheduledHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnParticleUpdateJobScheduledAsync(); } } #endif @@ -2295,33 +2221,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncPostRenderTrigger : AsyncTriggerBase + public sealed class AsyncPostRenderTrigger : AsyncTriggerBase { - TriggerEvent onPostRenderTriggerEvent; - void OnPostRender() { - onPostRenderTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncOnPostRenderHandler GetOnPostRenderAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onPostRenderTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnPostRenderHandler GetOnPostRenderAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onPostRenderTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnPostRenderAsync() { - return ((IAsyncOnPostRenderHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPostRenderTriggerEvent), true)).OnPostRenderAsync(); + return ((IAsyncOnPostRenderHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnPostRenderAsync(); } public UniTask OnPostRenderAsync(CancellationToken cancellationToken) { - return ((IAsyncOnPostRenderHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPostRenderTriggerEvent), cancellationToken, true)).OnPostRenderAsync(); + return ((IAsyncOnPostRenderHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnPostRenderAsync(); } } #endregion @@ -2356,33 +2280,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncPreCullTrigger : AsyncTriggerBase + public sealed class AsyncPreCullTrigger : AsyncTriggerBase { - TriggerEvent onPreCullTriggerEvent; - void OnPreCull() { - onPreCullTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncOnPreCullHandler GetOnPreCullAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onPreCullTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnPreCullHandler GetOnPreCullAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onPreCullTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnPreCullAsync() { - return ((IAsyncOnPreCullHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPreCullTriggerEvent), true)).OnPreCullAsync(); + return ((IAsyncOnPreCullHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnPreCullAsync(); } public UniTask OnPreCullAsync(CancellationToken cancellationToken) { - return ((IAsyncOnPreCullHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPreCullTriggerEvent), cancellationToken, true)).OnPreCullAsync(); + return ((IAsyncOnPreCullHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnPreCullAsync(); } } #endregion @@ -2417,33 +2339,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncPreRenderTrigger : AsyncTriggerBase + public sealed class AsyncPreRenderTrigger : AsyncTriggerBase { - TriggerEvent onPreRenderTriggerEvent; - void OnPreRender() { - onPreRenderTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncOnPreRenderHandler GetOnPreRenderAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onPreRenderTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnPreRenderHandler GetOnPreRenderAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onPreRenderTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnPreRenderAsync() { - return ((IAsyncOnPreRenderHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPreRenderTriggerEvent), true)).OnPreRenderAsync(); + return ((IAsyncOnPreRenderHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnPreRenderAsync(); } public UniTask OnPreRenderAsync(CancellationToken cancellationToken) { - return ((IAsyncOnPreRenderHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPreRenderTriggerEvent), cancellationToken, true)).OnPreRenderAsync(); + return ((IAsyncOnPreRenderHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnPreRenderAsync(); } } #endregion @@ -2478,33 +2398,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncRectTransformDimensionsChangeTrigger : AsyncTriggerBase + public sealed class AsyncRectTransformDimensionsChangeTrigger : AsyncTriggerBase { - TriggerEvent onRectTransformDimensionsChangeTriggerEvent; - void OnRectTransformDimensionsChange() { - onRectTransformDimensionsChangeTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncOnRectTransformDimensionsChangeHandler GetOnRectTransformDimensionsChangeAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onRectTransformDimensionsChangeTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnRectTransformDimensionsChangeHandler GetOnRectTransformDimensionsChangeAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onRectTransformDimensionsChangeTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnRectTransformDimensionsChangeAsync() { - return ((IAsyncOnRectTransformDimensionsChangeHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onRectTransformDimensionsChangeTriggerEvent), true)).OnRectTransformDimensionsChangeAsync(); + return ((IAsyncOnRectTransformDimensionsChangeHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnRectTransformDimensionsChangeAsync(); } public UniTask OnRectTransformDimensionsChangeAsync(CancellationToken cancellationToken) { - return ((IAsyncOnRectTransformDimensionsChangeHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onRectTransformDimensionsChangeTriggerEvent), cancellationToken, true)).OnRectTransformDimensionsChangeAsync(); + return ((IAsyncOnRectTransformDimensionsChangeHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnRectTransformDimensionsChangeAsync(); } } #endregion @@ -2539,33 +2457,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncRectTransformRemovedTrigger : AsyncTriggerBase + public sealed class AsyncRectTransformRemovedTrigger : AsyncTriggerBase { - TriggerEvent onRectTransformRemovedTriggerEvent; - void OnRectTransformRemoved() { - onRectTransformRemovedTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncOnRectTransformRemovedHandler GetOnRectTransformRemovedAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onRectTransformRemovedTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnRectTransformRemovedHandler GetOnRectTransformRemovedAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onRectTransformRemovedTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnRectTransformRemovedAsync() { - return ((IAsyncOnRectTransformRemovedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onRectTransformRemovedTriggerEvent), true)).OnRectTransformRemovedAsync(); + return ((IAsyncOnRectTransformRemovedHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnRectTransformRemovedAsync(); } public UniTask OnRectTransformRemovedAsync(CancellationToken cancellationToken) { - return ((IAsyncOnRectTransformRemovedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onRectTransformRemovedTriggerEvent), cancellationToken, true)).OnRectTransformRemovedAsync(); + return ((IAsyncOnRectTransformRemovedHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnRectTransformRemovedAsync(); } } #endregion @@ -2600,33 +2516,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncRenderImageTrigger : AsyncTriggerBase + public sealed class AsyncRenderImageTrigger : AsyncTriggerBase<(RenderTexture source, RenderTexture destination)> { - TriggerEvent<(RenderTexture source, RenderTexture destination)> onRenderImageTriggerEvent; - void OnRenderImage(RenderTexture source, RenderTexture destination) { - onRenderImageTriggerEvent?.TrySetResult((source, destination)); + triggerEvent?.TrySetResult((source, destination)); } public IAsyncOnRenderImageHandler GetOnRenderImageAsyncHandler() { - return new AsyncTriggerHandler<(RenderTexture source, RenderTexture destination)>(SetTriggerEvent(ref onRenderImageTriggerEvent), false); + return new AsyncTriggerHandler<(RenderTexture source, RenderTexture destination)>(GetTriggerEvent(), false); } public IAsyncOnRenderImageHandler GetOnRenderImageAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler<(RenderTexture source, RenderTexture destination)>(SetTriggerEvent(ref onRenderImageTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler<(RenderTexture source, RenderTexture destination)>(GetTriggerEvent(), cancellationToken, false); } public UniTask<(RenderTexture source, RenderTexture destination)> OnRenderImageAsync() { - return ((IAsyncOnRenderImageHandler)new AsyncTriggerHandler<(RenderTexture source, RenderTexture destination)>(SetTriggerEvent(ref onRenderImageTriggerEvent), true)).OnRenderImageAsync(); + return ((IAsyncOnRenderImageHandler)new AsyncTriggerHandler<(RenderTexture source, RenderTexture destination)>(GetTriggerEvent(), true)).OnRenderImageAsync(); } public UniTask<(RenderTexture source, RenderTexture destination)> OnRenderImageAsync(CancellationToken cancellationToken) { - return ((IAsyncOnRenderImageHandler)new AsyncTriggerHandler<(RenderTexture source, RenderTexture destination)>(SetTriggerEvent(ref onRenderImageTriggerEvent), cancellationToken, true)).OnRenderImageAsync(); + return ((IAsyncOnRenderImageHandler)new AsyncTriggerHandler<(RenderTexture source, RenderTexture destination)>(GetTriggerEvent(), cancellationToken, true)).OnRenderImageAsync(); } } #endregion @@ -2661,33 +2575,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncRenderObjectTrigger : AsyncTriggerBase + public sealed class AsyncRenderObjectTrigger : AsyncTriggerBase { - TriggerEvent onRenderObjectTriggerEvent; - void OnRenderObject() { - onRenderObjectTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncOnRenderObjectHandler GetOnRenderObjectAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onRenderObjectTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnRenderObjectHandler GetOnRenderObjectAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onRenderObjectTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnRenderObjectAsync() { - return ((IAsyncOnRenderObjectHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onRenderObjectTriggerEvent), true)).OnRenderObjectAsync(); + return ((IAsyncOnRenderObjectHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnRenderObjectAsync(); } public UniTask OnRenderObjectAsync(CancellationToken cancellationToken) { - return ((IAsyncOnRenderObjectHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onRenderObjectTriggerEvent), cancellationToken, true)).OnRenderObjectAsync(); + return ((IAsyncOnRenderObjectHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnRenderObjectAsync(); } } #endregion @@ -2722,33 +2634,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncServerInitializedTrigger : AsyncTriggerBase + public sealed class AsyncServerInitializedTrigger : AsyncTriggerBase { - TriggerEvent onServerInitializedTriggerEvent; - void OnServerInitialized() { - onServerInitializedTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncOnServerInitializedHandler GetOnServerInitializedAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onServerInitializedTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnServerInitializedHandler GetOnServerInitializedAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onServerInitializedTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnServerInitializedAsync() { - return ((IAsyncOnServerInitializedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onServerInitializedTriggerEvent), true)).OnServerInitializedAsync(); + return ((IAsyncOnServerInitializedHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnServerInitializedAsync(); } public UniTask OnServerInitializedAsync(CancellationToken cancellationToken) { - return ((IAsyncOnServerInitializedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onServerInitializedTriggerEvent), cancellationToken, true)).OnServerInitializedAsync(); + return ((IAsyncOnServerInitializedHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnServerInitializedAsync(); } } #endregion @@ -2783,33 +2693,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncTransformChildrenChangedTrigger : AsyncTriggerBase + public sealed class AsyncTransformChildrenChangedTrigger : AsyncTriggerBase { - TriggerEvent onTransformChildrenChangedTriggerEvent; - void OnTransformChildrenChanged() { - onTransformChildrenChangedTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncOnTransformChildrenChangedHandler GetOnTransformChildrenChangedAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onTransformChildrenChangedTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnTransformChildrenChangedHandler GetOnTransformChildrenChangedAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onTransformChildrenChangedTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnTransformChildrenChangedAsync() { - return ((IAsyncOnTransformChildrenChangedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTransformChildrenChangedTriggerEvent), true)).OnTransformChildrenChangedAsync(); + return ((IAsyncOnTransformChildrenChangedHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnTransformChildrenChangedAsync(); } public UniTask OnTransformChildrenChangedAsync(CancellationToken cancellationToken) { - return ((IAsyncOnTransformChildrenChangedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTransformChildrenChangedTriggerEvent), cancellationToken, true)).OnTransformChildrenChangedAsync(); + return ((IAsyncOnTransformChildrenChangedHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnTransformChildrenChangedAsync(); } } #endregion @@ -2844,33 +2752,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncTransformParentChangedTrigger : AsyncTriggerBase + public sealed class AsyncTransformParentChangedTrigger : AsyncTriggerBase { - TriggerEvent onTransformParentChangedTriggerEvent; - void OnTransformParentChanged() { - onTransformParentChangedTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncOnTransformParentChangedHandler GetOnTransformParentChangedAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onTransformParentChangedTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnTransformParentChangedHandler GetOnTransformParentChangedAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onTransformParentChangedTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnTransformParentChangedAsync() { - return ((IAsyncOnTransformParentChangedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTransformParentChangedTriggerEvent), true)).OnTransformParentChangedAsync(); + return ((IAsyncOnTransformParentChangedHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnTransformParentChangedAsync(); } public UniTask OnTransformParentChangedAsync(CancellationToken cancellationToken) { - return ((IAsyncOnTransformParentChangedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTransformParentChangedTriggerEvent), cancellationToken, true)).OnTransformParentChangedAsync(); + return ((IAsyncOnTransformParentChangedHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnTransformParentChangedAsync(); } } #endregion @@ -2905,33 +2811,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncTriggerEnterTrigger : AsyncTriggerBase + public sealed class AsyncTriggerEnterTrigger : AsyncTriggerBase { - TriggerEvent onTriggerEnterTriggerEvent; - void OnTriggerEnter(Collider other) { - onTriggerEnterTriggerEvent?.TrySetResult((other)); + triggerEvent?.TrySetResult((other)); } public IAsyncOnTriggerEnterHandler GetOnTriggerEnterAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerEnterTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnTriggerEnterHandler GetOnTriggerEnterAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerEnterTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnTriggerEnterAsync() { - return ((IAsyncOnTriggerEnterHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerEnterTriggerEvent), true)).OnTriggerEnterAsync(); + return ((IAsyncOnTriggerEnterHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnTriggerEnterAsync(); } public UniTask OnTriggerEnterAsync(CancellationToken cancellationToken) { - return ((IAsyncOnTriggerEnterHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerEnterTriggerEvent), cancellationToken, true)).OnTriggerEnterAsync(); + return ((IAsyncOnTriggerEnterHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnTriggerEnterAsync(); } } #endregion @@ -2966,33 +2870,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncTriggerEnter2DTrigger : AsyncTriggerBase + public sealed class AsyncTriggerEnter2DTrigger : AsyncTriggerBase { - TriggerEvent onTriggerEnter2DTriggerEvent; - void OnTriggerEnter2D(Collider2D other) { - onTriggerEnter2DTriggerEvent?.TrySetResult((other)); + triggerEvent?.TrySetResult((other)); } public IAsyncOnTriggerEnter2DHandler GetOnTriggerEnter2DAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerEnter2DTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnTriggerEnter2DHandler GetOnTriggerEnter2DAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerEnter2DTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnTriggerEnter2DAsync() { - return ((IAsyncOnTriggerEnter2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerEnter2DTriggerEvent), true)).OnTriggerEnter2DAsync(); + return ((IAsyncOnTriggerEnter2DHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnTriggerEnter2DAsync(); } public UniTask OnTriggerEnter2DAsync(CancellationToken cancellationToken) { - return ((IAsyncOnTriggerEnter2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerEnter2DTriggerEvent), cancellationToken, true)).OnTriggerEnter2DAsync(); + return ((IAsyncOnTriggerEnter2DHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnTriggerEnter2DAsync(); } } #endregion @@ -3027,33 +2929,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncTriggerExitTrigger : AsyncTriggerBase + public sealed class AsyncTriggerExitTrigger : AsyncTriggerBase { - TriggerEvent onTriggerExitTriggerEvent; - void OnTriggerExit(Collider other) { - onTriggerExitTriggerEvent?.TrySetResult((other)); + triggerEvent?.TrySetResult((other)); } public IAsyncOnTriggerExitHandler GetOnTriggerExitAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerExitTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnTriggerExitHandler GetOnTriggerExitAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerExitTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnTriggerExitAsync() { - return ((IAsyncOnTriggerExitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerExitTriggerEvent), true)).OnTriggerExitAsync(); + return ((IAsyncOnTriggerExitHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnTriggerExitAsync(); } public UniTask OnTriggerExitAsync(CancellationToken cancellationToken) { - return ((IAsyncOnTriggerExitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerExitTriggerEvent), cancellationToken, true)).OnTriggerExitAsync(); + return ((IAsyncOnTriggerExitHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnTriggerExitAsync(); } } #endregion @@ -3088,33 +2988,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncTriggerExit2DTrigger : AsyncTriggerBase + public sealed class AsyncTriggerExit2DTrigger : AsyncTriggerBase { - TriggerEvent onTriggerExit2DTriggerEvent; - void OnTriggerExit2D(Collider2D other) { - onTriggerExit2DTriggerEvent?.TrySetResult((other)); + triggerEvent?.TrySetResult((other)); } public IAsyncOnTriggerExit2DHandler GetOnTriggerExit2DAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerExit2DTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnTriggerExit2DHandler GetOnTriggerExit2DAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerExit2DTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnTriggerExit2DAsync() { - return ((IAsyncOnTriggerExit2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerExit2DTriggerEvent), true)).OnTriggerExit2DAsync(); + return ((IAsyncOnTriggerExit2DHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnTriggerExit2DAsync(); } public UniTask OnTriggerExit2DAsync(CancellationToken cancellationToken) { - return ((IAsyncOnTriggerExit2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerExit2DTriggerEvent), cancellationToken, true)).OnTriggerExit2DAsync(); + return ((IAsyncOnTriggerExit2DHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnTriggerExit2DAsync(); } } #endregion @@ -3149,33 +3047,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncTriggerStayTrigger : AsyncTriggerBase + public sealed class AsyncTriggerStayTrigger : AsyncTriggerBase { - TriggerEvent onTriggerStayTriggerEvent; - void OnTriggerStay(Collider other) { - onTriggerStayTriggerEvent?.TrySetResult((other)); + triggerEvent?.TrySetResult((other)); } public IAsyncOnTriggerStayHandler GetOnTriggerStayAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerStayTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnTriggerStayHandler GetOnTriggerStayAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerStayTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnTriggerStayAsync() { - return ((IAsyncOnTriggerStayHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerStayTriggerEvent), true)).OnTriggerStayAsync(); + return ((IAsyncOnTriggerStayHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnTriggerStayAsync(); } public UniTask OnTriggerStayAsync(CancellationToken cancellationToken) { - return ((IAsyncOnTriggerStayHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerStayTriggerEvent), cancellationToken, true)).OnTriggerStayAsync(); + return ((IAsyncOnTriggerStayHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnTriggerStayAsync(); } } #endregion @@ -3210,33 +3106,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncTriggerStay2DTrigger : AsyncTriggerBase + public sealed class AsyncTriggerStay2DTrigger : AsyncTriggerBase { - TriggerEvent onTriggerStay2DTriggerEvent; - void OnTriggerStay2D(Collider2D other) { - onTriggerStay2DTriggerEvent?.TrySetResult((other)); + triggerEvent?.TrySetResult((other)); } public IAsyncOnTriggerStay2DHandler GetOnTriggerStay2DAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerStay2DTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnTriggerStay2DHandler GetOnTriggerStay2DAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerStay2DTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnTriggerStay2DAsync() { - return ((IAsyncOnTriggerStay2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerStay2DTriggerEvent), true)).OnTriggerStay2DAsync(); + return ((IAsyncOnTriggerStay2DHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnTriggerStay2DAsync(); } public UniTask OnTriggerStay2DAsync(CancellationToken cancellationToken) { - return ((IAsyncOnTriggerStay2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerStay2DTriggerEvent), cancellationToken, true)).OnTriggerStay2DAsync(); + return ((IAsyncOnTriggerStay2DHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnTriggerStay2DAsync(); } } #endregion @@ -3271,33 +3165,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncValidateTrigger : AsyncTriggerBase + public sealed class AsyncValidateTrigger : AsyncTriggerBase { - TriggerEvent onValidateTriggerEvent; - void OnValidate() { - onValidateTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncOnValidateHandler GetOnValidateAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onValidateTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnValidateHandler GetOnValidateAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onValidateTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnValidateAsync() { - return ((IAsyncOnValidateHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onValidateTriggerEvent), true)).OnValidateAsync(); + return ((IAsyncOnValidateHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnValidateAsync(); } public UniTask OnValidateAsync(CancellationToken cancellationToken) { - return ((IAsyncOnValidateHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onValidateTriggerEvent), cancellationToken, true)).OnValidateAsync(); + return ((IAsyncOnValidateHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnValidateAsync(); } } #endregion @@ -3332,33 +3224,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncWillRenderObjectTrigger : AsyncTriggerBase + public sealed class AsyncWillRenderObjectTrigger : AsyncTriggerBase { - TriggerEvent onWillRenderObjectTriggerEvent; - void OnWillRenderObject() { - onWillRenderObjectTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncOnWillRenderObjectHandler GetOnWillRenderObjectAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onWillRenderObjectTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnWillRenderObjectHandler GetOnWillRenderObjectAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onWillRenderObjectTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnWillRenderObjectAsync() { - return ((IAsyncOnWillRenderObjectHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onWillRenderObjectTriggerEvent), true)).OnWillRenderObjectAsync(); + return ((IAsyncOnWillRenderObjectHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnWillRenderObjectAsync(); } public UniTask OnWillRenderObjectAsync(CancellationToken cancellationToken) { - return ((IAsyncOnWillRenderObjectHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onWillRenderObjectTriggerEvent), cancellationToken, true)).OnWillRenderObjectAsync(); + return ((IAsyncOnWillRenderObjectHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnWillRenderObjectAsync(); } } #endregion @@ -3393,33 +3283,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncResetTrigger : AsyncTriggerBase + public sealed class AsyncResetTrigger : AsyncTriggerBase { - TriggerEvent resetTriggerEvent; - void Reset() { - resetTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncResetHandler GetResetAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref resetTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncResetHandler GetResetAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref resetTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask ResetAsync() { - return ((IAsyncResetHandler)new AsyncTriggerHandler(SetTriggerEvent(ref resetTriggerEvent), true)).ResetAsync(); + return ((IAsyncResetHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).ResetAsync(); } public UniTask ResetAsync(CancellationToken cancellationToken) { - return ((IAsyncResetHandler)new AsyncTriggerHandler(SetTriggerEvent(ref resetTriggerEvent), cancellationToken, true)).ResetAsync(); + return ((IAsyncResetHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).ResetAsync(); } } #endregion @@ -3454,33 +3342,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncUpdateTrigger : AsyncTriggerBase + public sealed class AsyncUpdateTrigger : AsyncTriggerBase { - TriggerEvent updateTriggerEvent; - void Update() { - updateTriggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent?.TrySetResult(AsyncUnit.Default); } public IAsyncUpdateHandler GetUpdateAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref updateTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncUpdateHandler GetUpdateAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref updateTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask UpdateAsync() { - return ((IAsyncUpdateHandler)new AsyncTriggerHandler(SetTriggerEvent(ref updateTriggerEvent), true)).UpdateAsync(); + return ((IAsyncUpdateHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).UpdateAsync(); } public UniTask UpdateAsync(CancellationToken cancellationToken) { - return ((IAsyncUpdateHandler)new AsyncTriggerHandler(SetTriggerEvent(ref updateTriggerEvent), cancellationToken, true)).UpdateAsync(); + return ((IAsyncUpdateHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).UpdateAsync(); } } #endregion @@ -3515,33 +3401,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncBeginDragTrigger : AsyncTriggerBase, IBeginDragHandler + public sealed class AsyncBeginDragTrigger : AsyncTriggerBase, IBeginDragHandler { - TriggerEvent onBeginDragTriggerEvent; - void IBeginDragHandler.OnBeginDrag(PointerEventData eventData) { - onBeginDragTriggerEvent?.TrySetResult((eventData)); + triggerEvent?.TrySetResult((eventData)); } public IAsyncOnBeginDragHandler GetOnBeginDragAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onBeginDragTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnBeginDragHandler GetOnBeginDragAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onBeginDragTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnBeginDragAsync() { - return ((IAsyncOnBeginDragHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onBeginDragTriggerEvent), true)).OnBeginDragAsync(); + return ((IAsyncOnBeginDragHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnBeginDragAsync(); } public UniTask OnBeginDragAsync(CancellationToken cancellationToken) { - return ((IAsyncOnBeginDragHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onBeginDragTriggerEvent), cancellationToken, true)).OnBeginDragAsync(); + return ((IAsyncOnBeginDragHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnBeginDragAsync(); } } #endregion @@ -3576,33 +3460,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncCancelTrigger : AsyncTriggerBase, ICancelHandler + public sealed class AsyncCancelTrigger : AsyncTriggerBase, ICancelHandler { - TriggerEvent onCancelTriggerEvent; - void ICancelHandler.OnCancel(BaseEventData eventData) { - onCancelTriggerEvent?.TrySetResult((eventData)); + triggerEvent?.TrySetResult((eventData)); } public IAsyncOnCancelHandler GetOnCancelAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onCancelTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnCancelHandler GetOnCancelAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onCancelTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnCancelAsync() { - return ((IAsyncOnCancelHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCancelTriggerEvent), true)).OnCancelAsync(); + return ((IAsyncOnCancelHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnCancelAsync(); } public UniTask OnCancelAsync(CancellationToken cancellationToken) { - return ((IAsyncOnCancelHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCancelTriggerEvent), cancellationToken, true)).OnCancelAsync(); + return ((IAsyncOnCancelHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnCancelAsync(); } } #endregion @@ -3637,33 +3519,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncDeselectTrigger : AsyncTriggerBase, IDeselectHandler + public sealed class AsyncDeselectTrigger : AsyncTriggerBase, IDeselectHandler { - TriggerEvent onDeselectTriggerEvent; - void IDeselectHandler.OnDeselect(BaseEventData eventData) { - onDeselectTriggerEvent?.TrySetResult((eventData)); + triggerEvent?.TrySetResult((eventData)); } public IAsyncOnDeselectHandler GetOnDeselectAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onDeselectTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnDeselectHandler GetOnDeselectAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onDeselectTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnDeselectAsync() { - return ((IAsyncOnDeselectHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDeselectTriggerEvent), true)).OnDeselectAsync(); + return ((IAsyncOnDeselectHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnDeselectAsync(); } public UniTask OnDeselectAsync(CancellationToken cancellationToken) { - return ((IAsyncOnDeselectHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDeselectTriggerEvent), cancellationToken, true)).OnDeselectAsync(); + return ((IAsyncOnDeselectHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnDeselectAsync(); } } #endregion @@ -3698,33 +3578,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncDragTrigger : AsyncTriggerBase, IDragHandler + public sealed class AsyncDragTrigger : AsyncTriggerBase, IDragHandler { - TriggerEvent onDragTriggerEvent; - void IDragHandler.OnDrag(PointerEventData eventData) { - onDragTriggerEvent?.TrySetResult((eventData)); + triggerEvent?.TrySetResult((eventData)); } public IAsyncOnDragHandler GetOnDragAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onDragTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnDragHandler GetOnDragAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onDragTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnDragAsync() { - return ((IAsyncOnDragHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDragTriggerEvent), true)).OnDragAsync(); + return ((IAsyncOnDragHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnDragAsync(); } public UniTask OnDragAsync(CancellationToken cancellationToken) { - return ((IAsyncOnDragHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDragTriggerEvent), cancellationToken, true)).OnDragAsync(); + return ((IAsyncOnDragHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnDragAsync(); } } #endregion @@ -3759,33 +3637,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncDropTrigger : AsyncTriggerBase, IDropHandler + public sealed class AsyncDropTrigger : AsyncTriggerBase, IDropHandler { - TriggerEvent onDropTriggerEvent; - void IDropHandler.OnDrop(PointerEventData eventData) { - onDropTriggerEvent?.TrySetResult((eventData)); + triggerEvent?.TrySetResult((eventData)); } public IAsyncOnDropHandler GetOnDropAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onDropTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnDropHandler GetOnDropAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onDropTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnDropAsync() { - return ((IAsyncOnDropHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDropTriggerEvent), true)).OnDropAsync(); + return ((IAsyncOnDropHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnDropAsync(); } public UniTask OnDropAsync(CancellationToken cancellationToken) { - return ((IAsyncOnDropHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDropTriggerEvent), cancellationToken, true)).OnDropAsync(); + return ((IAsyncOnDropHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnDropAsync(); } } #endregion @@ -3820,33 +3696,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncEndDragTrigger : AsyncTriggerBase, IEndDragHandler + public sealed class AsyncEndDragTrigger : AsyncTriggerBase, IEndDragHandler { - TriggerEvent onEndDragTriggerEvent; - void IEndDragHandler.OnEndDrag(PointerEventData eventData) { - onEndDragTriggerEvent?.TrySetResult((eventData)); + triggerEvent?.TrySetResult((eventData)); } public IAsyncOnEndDragHandler GetOnEndDragAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onEndDragTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnEndDragHandler GetOnEndDragAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onEndDragTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnEndDragAsync() { - return ((IAsyncOnEndDragHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onEndDragTriggerEvent), true)).OnEndDragAsync(); + return ((IAsyncOnEndDragHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnEndDragAsync(); } public UniTask OnEndDragAsync(CancellationToken cancellationToken) { - return ((IAsyncOnEndDragHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onEndDragTriggerEvent), cancellationToken, true)).OnEndDragAsync(); + return ((IAsyncOnEndDragHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnEndDragAsync(); } } #endregion @@ -3881,33 +3755,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncInitializePotentialDragTrigger : AsyncTriggerBase, IInitializePotentialDragHandler + public sealed class AsyncInitializePotentialDragTrigger : AsyncTriggerBase, IInitializePotentialDragHandler { - TriggerEvent onInitializePotentialDragTriggerEvent; - void IInitializePotentialDragHandler.OnInitializePotentialDrag(PointerEventData eventData) { - onInitializePotentialDragTriggerEvent?.TrySetResult((eventData)); + triggerEvent?.TrySetResult((eventData)); } public IAsyncOnInitializePotentialDragHandler GetOnInitializePotentialDragAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onInitializePotentialDragTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnInitializePotentialDragHandler GetOnInitializePotentialDragAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onInitializePotentialDragTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnInitializePotentialDragAsync() { - return ((IAsyncOnInitializePotentialDragHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onInitializePotentialDragTriggerEvent), true)).OnInitializePotentialDragAsync(); + return ((IAsyncOnInitializePotentialDragHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnInitializePotentialDragAsync(); } public UniTask OnInitializePotentialDragAsync(CancellationToken cancellationToken) { - return ((IAsyncOnInitializePotentialDragHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onInitializePotentialDragTriggerEvent), cancellationToken, true)).OnInitializePotentialDragAsync(); + return ((IAsyncOnInitializePotentialDragHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnInitializePotentialDragAsync(); } } #endregion @@ -3942,33 +3814,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncMoveTrigger : AsyncTriggerBase, IMoveHandler + public sealed class AsyncMoveTrigger : AsyncTriggerBase, IMoveHandler { - TriggerEvent onMoveTriggerEvent; - void IMoveHandler.OnMove(AxisEventData eventData) { - onMoveTriggerEvent?.TrySetResult((eventData)); + triggerEvent?.TrySetResult((eventData)); } public IAsyncOnMoveHandler GetOnMoveAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onMoveTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnMoveHandler GetOnMoveAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onMoveTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnMoveAsync() { - return ((IAsyncOnMoveHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMoveTriggerEvent), true)).OnMoveAsync(); + return ((IAsyncOnMoveHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnMoveAsync(); } public UniTask OnMoveAsync(CancellationToken cancellationToken) { - return ((IAsyncOnMoveHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMoveTriggerEvent), cancellationToken, true)).OnMoveAsync(); + return ((IAsyncOnMoveHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnMoveAsync(); } } #endregion @@ -4003,33 +3873,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncPointerClickTrigger : AsyncTriggerBase, IPointerClickHandler + public sealed class AsyncPointerClickTrigger : AsyncTriggerBase, IPointerClickHandler { - TriggerEvent onPointerClickTriggerEvent; - void IPointerClickHandler.OnPointerClick(PointerEventData eventData) { - onPointerClickTriggerEvent?.TrySetResult((eventData)); + triggerEvent?.TrySetResult((eventData)); } public IAsyncOnPointerClickHandler GetOnPointerClickAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onPointerClickTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnPointerClickHandler GetOnPointerClickAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onPointerClickTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnPointerClickAsync() { - return ((IAsyncOnPointerClickHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPointerClickTriggerEvent), true)).OnPointerClickAsync(); + return ((IAsyncOnPointerClickHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnPointerClickAsync(); } public UniTask OnPointerClickAsync(CancellationToken cancellationToken) { - return ((IAsyncOnPointerClickHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPointerClickTriggerEvent), cancellationToken, true)).OnPointerClickAsync(); + return ((IAsyncOnPointerClickHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnPointerClickAsync(); } } #endregion @@ -4064,33 +3932,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncPointerDownTrigger : AsyncTriggerBase, IPointerDownHandler + public sealed class AsyncPointerDownTrigger : AsyncTriggerBase, IPointerDownHandler { - TriggerEvent onPointerDownTriggerEvent; - void IPointerDownHandler.OnPointerDown(PointerEventData eventData) { - onPointerDownTriggerEvent?.TrySetResult((eventData)); + triggerEvent?.TrySetResult((eventData)); } public IAsyncOnPointerDownHandler GetOnPointerDownAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onPointerDownTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnPointerDownHandler GetOnPointerDownAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onPointerDownTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnPointerDownAsync() { - return ((IAsyncOnPointerDownHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPointerDownTriggerEvent), true)).OnPointerDownAsync(); + return ((IAsyncOnPointerDownHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnPointerDownAsync(); } public UniTask OnPointerDownAsync(CancellationToken cancellationToken) { - return ((IAsyncOnPointerDownHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPointerDownTriggerEvent), cancellationToken, true)).OnPointerDownAsync(); + return ((IAsyncOnPointerDownHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnPointerDownAsync(); } } #endregion @@ -4125,33 +3991,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncPointerEnterTrigger : AsyncTriggerBase, IPointerEnterHandler + public sealed class AsyncPointerEnterTrigger : AsyncTriggerBase, IPointerEnterHandler { - TriggerEvent onPointerEnterTriggerEvent; - void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData) { - onPointerEnterTriggerEvent?.TrySetResult((eventData)); + triggerEvent?.TrySetResult((eventData)); } public IAsyncOnPointerEnterHandler GetOnPointerEnterAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onPointerEnterTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnPointerEnterHandler GetOnPointerEnterAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onPointerEnterTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnPointerEnterAsync() { - return ((IAsyncOnPointerEnterHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPointerEnterTriggerEvent), true)).OnPointerEnterAsync(); + return ((IAsyncOnPointerEnterHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnPointerEnterAsync(); } public UniTask OnPointerEnterAsync(CancellationToken cancellationToken) { - return ((IAsyncOnPointerEnterHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPointerEnterTriggerEvent), cancellationToken, true)).OnPointerEnterAsync(); + return ((IAsyncOnPointerEnterHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnPointerEnterAsync(); } } #endregion @@ -4186,33 +4050,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncPointerExitTrigger : AsyncTriggerBase, IPointerExitHandler + public sealed class AsyncPointerExitTrigger : AsyncTriggerBase, IPointerExitHandler { - TriggerEvent onPointerExitTriggerEvent; - void IPointerExitHandler.OnPointerExit(PointerEventData eventData) { - onPointerExitTriggerEvent?.TrySetResult((eventData)); + triggerEvent?.TrySetResult((eventData)); } public IAsyncOnPointerExitHandler GetOnPointerExitAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onPointerExitTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnPointerExitHandler GetOnPointerExitAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onPointerExitTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnPointerExitAsync() { - return ((IAsyncOnPointerExitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPointerExitTriggerEvent), true)).OnPointerExitAsync(); + return ((IAsyncOnPointerExitHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnPointerExitAsync(); } public UniTask OnPointerExitAsync(CancellationToken cancellationToken) { - return ((IAsyncOnPointerExitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPointerExitTriggerEvent), cancellationToken, true)).OnPointerExitAsync(); + return ((IAsyncOnPointerExitHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnPointerExitAsync(); } } #endregion @@ -4247,33 +4109,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncPointerUpTrigger : AsyncTriggerBase, IPointerUpHandler + public sealed class AsyncPointerUpTrigger : AsyncTriggerBase, IPointerUpHandler { - TriggerEvent onPointerUpTriggerEvent; - void IPointerUpHandler.OnPointerUp(PointerEventData eventData) { - onPointerUpTriggerEvent?.TrySetResult((eventData)); + triggerEvent?.TrySetResult((eventData)); } public IAsyncOnPointerUpHandler GetOnPointerUpAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onPointerUpTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnPointerUpHandler GetOnPointerUpAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onPointerUpTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnPointerUpAsync() { - return ((IAsyncOnPointerUpHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPointerUpTriggerEvent), true)).OnPointerUpAsync(); + return ((IAsyncOnPointerUpHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnPointerUpAsync(); } public UniTask OnPointerUpAsync(CancellationToken cancellationToken) { - return ((IAsyncOnPointerUpHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPointerUpTriggerEvent), cancellationToken, true)).OnPointerUpAsync(); + return ((IAsyncOnPointerUpHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnPointerUpAsync(); } } #endregion @@ -4308,33 +4168,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncScrollTrigger : AsyncTriggerBase, IScrollHandler + public sealed class AsyncScrollTrigger : AsyncTriggerBase, IScrollHandler { - TriggerEvent onScrollTriggerEvent; - void IScrollHandler.OnScroll(PointerEventData eventData) { - onScrollTriggerEvent?.TrySetResult((eventData)); + triggerEvent?.TrySetResult((eventData)); } public IAsyncOnScrollHandler GetOnScrollAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onScrollTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnScrollHandler GetOnScrollAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onScrollTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnScrollAsync() { - return ((IAsyncOnScrollHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onScrollTriggerEvent), true)).OnScrollAsync(); + return ((IAsyncOnScrollHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnScrollAsync(); } public UniTask OnScrollAsync(CancellationToken cancellationToken) { - return ((IAsyncOnScrollHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onScrollTriggerEvent), cancellationToken, true)).OnScrollAsync(); + return ((IAsyncOnScrollHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnScrollAsync(); } } #endregion @@ -4369,33 +4227,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncSelectTrigger : AsyncTriggerBase, ISelectHandler + public sealed class AsyncSelectTrigger : AsyncTriggerBase, ISelectHandler { - TriggerEvent onSelectTriggerEvent; - void ISelectHandler.OnSelect(BaseEventData eventData) { - onSelectTriggerEvent?.TrySetResult((eventData)); + triggerEvent?.TrySetResult((eventData)); } public IAsyncOnSelectHandler GetOnSelectAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onSelectTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnSelectHandler GetOnSelectAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onSelectTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnSelectAsync() { - return ((IAsyncOnSelectHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onSelectTriggerEvent), true)).OnSelectAsync(); + return ((IAsyncOnSelectHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnSelectAsync(); } public UniTask OnSelectAsync(CancellationToken cancellationToken) { - return ((IAsyncOnSelectHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onSelectTriggerEvent), cancellationToken, true)).OnSelectAsync(); + return ((IAsyncOnSelectHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnSelectAsync(); } } #endregion @@ -4430,33 +4286,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncSubmitTrigger : AsyncTriggerBase, ISubmitHandler + public sealed class AsyncSubmitTrigger : AsyncTriggerBase, ISubmitHandler { - TriggerEvent onSubmitTriggerEvent; - void ISubmitHandler.OnSubmit(BaseEventData eventData) { - onSubmitTriggerEvent?.TrySetResult((eventData)); + triggerEvent?.TrySetResult((eventData)); } public IAsyncOnSubmitHandler GetOnSubmitAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onSubmitTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnSubmitHandler GetOnSubmitAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onSubmitTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnSubmitAsync() { - return ((IAsyncOnSubmitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onSubmitTriggerEvent), true)).OnSubmitAsync(); + return ((IAsyncOnSubmitHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnSubmitAsync(); } public UniTask OnSubmitAsync(CancellationToken cancellationToken) { - return ((IAsyncOnSubmitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onSubmitTriggerEvent), cancellationToken, true)).OnSubmitAsync(); + return ((IAsyncOnSubmitHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnSubmitAsync(); } } #endregion @@ -4491,33 +4345,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class AsyncUpdateSelectedTrigger : AsyncTriggerBase, IUpdateSelectedHandler + public sealed class AsyncUpdateSelectedTrigger : AsyncTriggerBase, IUpdateSelectedHandler { - TriggerEvent onUpdateSelectedTriggerEvent; - void IUpdateSelectedHandler.OnUpdateSelected(BaseEventData eventData) { - onUpdateSelectedTriggerEvent?.TrySetResult((eventData)); + triggerEvent?.TrySetResult((eventData)); } public IAsyncOnUpdateSelectedHandler GetOnUpdateSelectedAsyncHandler() { - return new AsyncTriggerHandler(SetTriggerEvent(ref onUpdateSelectedTriggerEvent), false); + return new AsyncTriggerHandler(GetTriggerEvent(), false); } public IAsyncOnUpdateSelectedHandler GetOnUpdateSelectedAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(SetTriggerEvent(ref onUpdateSelectedTriggerEvent), cancellationToken, false); + return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); } public UniTask OnUpdateSelectedAsync() { - return ((IAsyncOnUpdateSelectedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onUpdateSelectedTriggerEvent), true)).OnUpdateSelectedAsync(); + return ((IAsyncOnUpdateSelectedHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnUpdateSelectedAsync(); } public UniTask OnUpdateSelectedAsync(CancellationToken cancellationToken) { - return ((IAsyncOnUpdateSelectedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onUpdateSelectedTriggerEvent), cancellationToken, true)).OnUpdateSelectedAsync(); + return ((IAsyncOnUpdateSelectedHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnUpdateSelectedAsync(); } } #endregion diff --git a/src/UniTask/Assets/Plugins/UniTask/Triggers/MonoBehaviourMessagesTriggers.tt b/src/UniTask/Assets/Plugins/UniTask/Triggers/MonoBehaviourMessagesTriggers.tt index a0ff5ba..5d8de56 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Triggers/MonoBehaviourMessagesTriggers.tt +++ b/src/UniTask/Assets/Plugins/UniTask/Triggers/MonoBehaviourMessagesTriggers.tt @@ -99,7 +99,6 @@ Func ToInterfaceName = x => $"IAsync{x}Handler"; Func ToUniTaskName = x => x == "AsyncUnit" ? "UniTask" : $"UniTask<{x}>"; Func ToCastUniTasSourceType = x => x == "AsyncUnit" ? "IUniTaskSource" : $"IUniTaskSource<{x}>"; - Func TriggerFieldName = x => char.ToLowerInvariant(x[0]) + x.Substring(1, x.Length - 1) + "TriggerEvent"; Func OnInvokeSuffix = x => x == "AsyncUnit" ? ".AsUniTask()" : $""; Func<(string argType, string argName)[], string> BuildMethodArgument = x => string.Join(", ", x.Select(y => y.argType + " " + y.argName)); Func<(string argType, string argName)[], string> BuildResultParameter = x => x.Length == 0 ? "AsyncUnit.Default" : "(" + string.Join(", ", x.Select(y => y.argName)) + ")"; @@ -148,33 +147,31 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public sealed class Async<#= t.triggerName #>Trigger : AsyncTriggerBase<#= (t.handlerInterface == null) ? "" : $", {t.handlerInterface}" #> + public sealed class Async<#= t.triggerName #>Trigger : AsyncTriggerBase<<#= t.returnType #>><#= (t.handlerInterface == null) ? "" : $", {t.handlerInterface}" #> { - TriggerEvent<<#= t.returnType #>> <#= TriggerFieldName(t.methodName) #>; - void <#= (t.handlerInterface == null) ? "" : $"{t.handlerInterface}." #><#= t.methodName #>(<#= BuildMethodArgument(t.arguments) #>) { - <#= TriggerFieldName(t.methodName) #>?.TrySetResult(<#= BuildResultParameter(t.arguments) #>); + triggerEvent?.TrySetResult(<#= BuildResultParameter(t.arguments) #>); } public <#= ToInterfaceName(t.methodName) #> Get<#= t.methodName #>AsyncHandler() { - return new AsyncTriggerHandler<<#= t.returnType #>>(SetTriggerEvent(ref <#= TriggerFieldName(t.methodName) #>), false); + return new AsyncTriggerHandler<<#= t.returnType #>>(GetTriggerEvent(), false); } public <#= ToInterfaceName(t.methodName) #> Get<#= t.methodName #>AsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler<<#= t.returnType #>>(SetTriggerEvent(ref <#= TriggerFieldName(t.methodName) #>), cancellationToken, false); + return new AsyncTriggerHandler<<#= t.returnType #>>(GetTriggerEvent(), cancellationToken, false); } public <#= ToUniTaskName(t.returnType) #> <#= t.methodName #>Async() { - return ((<#= ToInterfaceName(t.methodName) #>)new AsyncTriggerHandler<<#= t.returnType #>>(SetTriggerEvent(ref <#= TriggerFieldName(t.methodName) #>), true)).<#= t.methodName #>Async(); + return ((<#= ToInterfaceName(t.methodName) #>)new AsyncTriggerHandler<<#= t.returnType #>>(GetTriggerEvent(), true)).<#= t.methodName #>Async(); } public <#= ToUniTaskName(t.returnType) #> <#= t.methodName #>Async(CancellationToken cancellationToken) { - return ((<#= ToInterfaceName(t.methodName) #>)new AsyncTriggerHandler<<#= t.returnType #>>(SetTriggerEvent(ref <#= TriggerFieldName(t.methodName) #>), cancellationToken, true)).<#= t.methodName #>Async(); + return ((<#= ToInterfaceName(t.methodName) #>)new AsyncTriggerHandler<<#= t.returnType #>>(GetTriggerEvent(), cancellationToken, true)).<#= t.methodName #>Async(); } } <# if(Is2019_3(t.triggerName)) { #> diff --git a/src/UniTask/Assets/Plugins/UniTask/UnityAsyncExtensions.uGUI.cs b/src/UniTask/Assets/Plugins/UniTask/UnityAsyncExtensions.uGUI.cs index c324ac5..6bfe1cd 100644 --- a/src/UniTask/Assets/Plugins/UniTask/UnityAsyncExtensions.uGUI.cs +++ b/src/UniTask/Assets/Plugins/UniTask/UnityAsyncExtensions.uGUI.cs @@ -3,6 +3,7 @@ using System; using System.Threading; using Cysharp.Threading.Tasks.Internal; +using Cysharp.Threading.Tasks.Linq; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; @@ -21,6 +22,11 @@ namespace Cysharp.Threading.Tasks return new AsyncUnityEventHandler(unityEvent, cancellationToken, true).OnInvokeAsync(); } + public static IUniTaskAsyncEnumerable OnInvokeAsAsyncEnumerable(this UnityEvent unityEvent, CancellationToken cancellationToken) + { + return new UnityEventHandlerAsyncEnumerable(unityEvent, cancellationToken); + } + public static IAsyncClickEventHandler GetAsyncClickEventHandler(this Button button) { return new AsyncUnityEventHandler(button.onClick, button.GetCancellationTokenOnDestroy(), false); @@ -41,6 +47,16 @@ namespace Cysharp.Threading.Tasks return new AsyncUnityEventHandler(button.onClick, cancellationToken, true).OnInvokeAsync(); } + public static IUniTaskAsyncEnumerable OnClickAsAsyncEnumerable(this Button button) + { + return new UnityEventHandlerAsyncEnumerable(button.onClick, button.GetCancellationTokenOnDestroy()); + } + + public static IUniTaskAsyncEnumerable OnClickAsAsyncEnumerable(this Button button, CancellationToken cancellationToken) + { + return new UnityEventHandlerAsyncEnumerable(button.onClick, cancellationToken); + } + public static IAsyncValueChangedEventHandler GetAsyncValueChangedEventHandler(this Toggle toggle) { return new AsyncUnityEventHandler(toggle.onValueChanged, toggle.GetCancellationTokenOnDestroy(), false); @@ -61,6 +77,16 @@ namespace Cysharp.Threading.Tasks return new AsyncUnityEventHandler(toggle.onValueChanged, cancellationToken, true).OnInvokeAsync(); } + public static IUniTaskAsyncEnumerable OnValueChangedAsAsyncEnumerable(this Toggle toggle) + { + return new UnityEventHandlerAsyncEnumerable(toggle.onValueChanged, toggle.GetCancellationTokenOnDestroy()); + } + + public static IUniTaskAsyncEnumerable OnValueChangedAsAsyncEnumerable(this Toggle toggle, CancellationToken cancellationToken) + { + return new UnityEventHandlerAsyncEnumerable(toggle.onValueChanged, cancellationToken); + } + public static IAsyncValueChangedEventHandler GetAsyncValueChangedEventHandler(this Scrollbar scrollbar) { return new AsyncUnityEventHandler(scrollbar.onValueChanged, scrollbar.GetCancellationTokenOnDestroy(), false); @@ -81,6 +107,16 @@ namespace Cysharp.Threading.Tasks return new AsyncUnityEventHandler(scrollbar.onValueChanged, cancellationToken, true).OnInvokeAsync(); } + public static IUniTaskAsyncEnumerable OnValueChangedAsAsyncEnumerable(this Scrollbar scrollbar) + { + return new UnityEventHandlerAsyncEnumerable(scrollbar.onValueChanged, scrollbar.GetCancellationTokenOnDestroy()); + } + + public static IUniTaskAsyncEnumerable OnValueChangedAsAsyncEnumerable(this Scrollbar scrollbar, CancellationToken cancellationToken) + { + return new UnityEventHandlerAsyncEnumerable(scrollbar.onValueChanged, cancellationToken); + } + public static IAsyncValueChangedEventHandler GetAsyncValueChangedEventHandler(this ScrollRect scrollRect) { return new AsyncUnityEventHandler(scrollRect.onValueChanged, scrollRect.GetCancellationTokenOnDestroy(), false); @@ -101,6 +137,16 @@ namespace Cysharp.Threading.Tasks return new AsyncUnityEventHandler(scrollRect.onValueChanged, cancellationToken, true).OnInvokeAsync(); } + public static IUniTaskAsyncEnumerable OnValueChangedAsAsyncEnumerable(this ScrollRect scrollRect) + { + return new UnityEventHandlerAsyncEnumerable(scrollRect.onValueChanged, scrollRect.GetCancellationTokenOnDestroy()); + } + + public static IUniTaskAsyncEnumerable OnValueChangedAsAsyncEnumerable(this ScrollRect scrollRect, CancellationToken cancellationToken) + { + return new UnityEventHandlerAsyncEnumerable(scrollRect.onValueChanged, cancellationToken); + } + public static IAsyncValueChangedEventHandler GetAsyncValueChangedEventHandler(this Slider slider) { return new AsyncUnityEventHandler(slider.onValueChanged, slider.GetCancellationTokenOnDestroy(), false); @@ -121,6 +167,16 @@ namespace Cysharp.Threading.Tasks return new AsyncUnityEventHandler(slider.onValueChanged, cancellationToken, true).OnInvokeAsync(); } + public static IUniTaskAsyncEnumerable OnValueChangedAsAsyncEnumerable(this Slider slider) + { + return new UnityEventHandlerAsyncEnumerable(slider.onValueChanged, slider.GetCancellationTokenOnDestroy()); + } + + public static IUniTaskAsyncEnumerable OnValueChangedAsAsyncEnumerable(this Slider slider, CancellationToken cancellationToken) + { + return new UnityEventHandlerAsyncEnumerable(slider.onValueChanged, cancellationToken); + } + public static IAsyncEndEditEventHandler GetAsyncEndEditEventHandler(this InputField inputField) { return new AsyncUnityEventHandler(inputField.onEndEdit, inputField.GetCancellationTokenOnDestroy(), false); @@ -141,6 +197,16 @@ namespace Cysharp.Threading.Tasks return new AsyncUnityEventHandler(inputField.onEndEdit, cancellationToken, true).OnInvokeAsync(); } + public static IUniTaskAsyncEnumerable OnEndEditAsAsyncEnumerable(this InputField inputField) + { + return new UnityEventHandlerAsyncEnumerable(inputField.onEndEdit, inputField.GetCancellationTokenOnDestroy()); + } + + public static IUniTaskAsyncEnumerable OnEndEditAsAsyncEnumerable(this InputField inputField, CancellationToken cancellationToken) + { + return new UnityEventHandlerAsyncEnumerable(inputField.onEndEdit, cancellationToken); + } + public static IAsyncValueChangedEventHandler GetAsyncValueChangedEventHandler(this Dropdown dropdown) { return new AsyncUnityEventHandler(dropdown.onValueChanged, dropdown.GetCancellationTokenOnDestroy(), false); @@ -151,36 +217,43 @@ namespace Cysharp.Threading.Tasks return new AsyncUnityEventHandler(dropdown.onValueChanged, cancellationToken, false); } - public static UniTask OnValueChanged(this Dropdown dropdown) + public static UniTask OnValueChangedAsync(this Dropdown dropdown) { return new AsyncUnityEventHandler(dropdown.onValueChanged, dropdown.GetCancellationTokenOnDestroy(), true).OnInvokeAsync(); } - public static UniTask OnValueChanged(this Dropdown dropdown, CancellationToken cancellationToken) + public static UniTask OnValueChangedAsync(this Dropdown dropdown, CancellationToken cancellationToken) { return new AsyncUnityEventHandler(dropdown.onValueChanged, cancellationToken, true).OnInvokeAsync(); } + + public static IUniTaskAsyncEnumerable OnValueChangedAsAsyncEnumerable(this Dropdown dropdown) + { + return new UnityEventHandlerAsyncEnumerable(dropdown.onValueChanged, dropdown.GetCancellationTokenOnDestroy()); + } + + public static IUniTaskAsyncEnumerable OnValueChangedAsAsyncEnumerable(this Dropdown dropdown, CancellationToken cancellationToken) + { + return new UnityEventHandlerAsyncEnumerable(dropdown.onValueChanged, cancellationToken); + } } - public interface IAsyncClickEventHandler : IDisposable, IUniTaskAsyncEnumerable + public interface IAsyncClickEventHandler : IDisposable { UniTask OnClickAsync(); - IAsyncClickEventHandler DisableAutoClose(); } - public interface IAsyncValueChangedEventHandler : IDisposable, IUniTaskAsyncEnumerable + public interface IAsyncValueChangedEventHandler : IDisposable { UniTask OnValueChangedAsync(); - IAsyncValueChangedEventHandler DisableAutoClose(); } - public interface IAsyncEndEditEventHandler : IDisposable, IUniTaskAsyncEnumerable + public interface IAsyncEndEditEventHandler : IDisposable { UniTask OnEndEditAsync(); - IAsyncEndEditEventHandler DisableAutoClose(); } - public class AsyncUnityEventHandler : IUniTaskSource, IDisposable, IAsyncClickEventHandler, IUniTaskAsyncEnumerable + public class AsyncUnityEventHandler : IUniTaskSource, IDisposable, IAsyncClickEventHandler { static Action cancellationCallback = CancellationCallback; @@ -225,7 +298,6 @@ namespace Cysharp.Threading.Tasks void Invoke() { - asyncEnumerator?.SetResult(); core.TrySetResult(AsyncUnit.Default); } @@ -233,15 +305,6 @@ namespace Cysharp.Threading.Tasks { var self = (AsyncUnityEventHandler)state; self.Dispose(); - - // call child cancel - if (self.asyncEnumerator != null) - { - self.asyncEnumerator.CancelFromParent(self.cancellationToken); - self.asyncEnumerator = null; - } - - self.core.TrySetCanceled(self.cancellationToken); } public void Dispose() @@ -255,6 +318,7 @@ namespace Cysharp.Threading.Tasks { unityEvent.RemoveListener(action); } + core.TrySetCanceled(cancellationToken); } } @@ -292,118 +356,9 @@ namespace Cysharp.Threading.Tasks { core.OnCompleted(continuation, state, token); } - - // AsyncEnumerator - - bool disableAutoClose; - Enumerator asyncEnumerator; - - public AsyncUnityEventHandler DisableAutoClose() - { - disableAutoClose = true; - return this; - } - - IAsyncClickEventHandler IAsyncClickEventHandler.DisableAutoClose() - { - disableAutoClose = true; - return this; - } - - IUniTaskAsyncEnumerator IUniTaskAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) - { - if (this.asyncEnumerator != null) - { - throw new InvalidOperationException("Already acquired GetAsyncEnumerator, does not allow get twice before previous enumerator completed."); - } - - this.asyncEnumerator = new Enumerator(this, cancellationToken); - return asyncEnumerator; - } - - class Enumerator : Cysharp.Threading.Tasks.Linq.MoveNextSource, IUniTaskAsyncEnumerator - { - static Action cancellationCallback = CancellationCallback; - - AsyncUnityEventHandler parent; - CancellationToken cancellationToken; - CancellationTokenRegistration registration; - bool isDisposed; - - public Enumerator(AsyncUnityEventHandler parent, CancellationToken cancellationToken) - { - this.parent = parent; - this.cancellationToken = cancellationToken; - - if (cancellationToken.CanBeCanceled && parent.cancellationToken != cancellationToken) - { - registration = cancellationToken.RegisterWithoutCaptureExecutionContext(cancellationCallback, this); - } - - TaskTracker.TrackActiveTask(this, 3); - } - - static void CancellationCallback(object state) - { - var self = (Enumerator)state; - self.DisposeCore(self.cancellationToken); - } - - public void CancelFromParent(CancellationToken cancellationToken) - { - // call from parent, avoid parent close. - parent.disableAutoClose = true; - DisposeCore(cancellationToken); - } - - public void SetResult() - { - completionSource.TrySetResult(true); - } - - public AsyncUnit Current { get; private set; } - - public UniTask MoveNextAsync() - { - completionSource.Reset(); - return new UniTask(this, completionSource.Version); - } - - public UniTask DisposeAsync() - { - DisposeCore(CancellationToken.None); - return default; - } - - void DisposeCore(CancellationToken cancellationToken) - { - if (!isDisposed) - { - isDisposed = true; - registration.Dispose(); - TaskTracker.RemoveTracking(this); - - if (!parent.disableAutoClose) - { - parent.Dispose(); // dispose parent. - } - - if (parent.asyncEnumerator == this) - { - parent.asyncEnumerator = null; - } - - try - { - completionSource.TrySetCanceled(cancellationToken); - } - catch (OperationCanceledException) { } - } - } - } } - public class AsyncUnityEventHandler : IUniTaskSource, IDisposable, IAsyncValueChangedEventHandler, IAsyncEndEditEventHandler, IUniTaskAsyncEnumerable + public class AsyncUnityEventHandler : IUniTaskSource, IDisposable, IAsyncValueChangedEventHandler, IAsyncEndEditEventHandler { static Action cancellationCallback = CancellationCallback; @@ -448,7 +403,6 @@ namespace Cysharp.Threading.Tasks void Invoke(T result) { - asyncEnumerator?.SetResult(result); core.TrySetResult(result); } @@ -456,15 +410,6 @@ namespace Cysharp.Threading.Tasks { var self = (AsyncUnityEventHandler)state; self.Dispose(); - - // call child cancel - if (self.asyncEnumerator != null) - { - self.asyncEnumerator.CancelFromParent(self.cancellationToken); - self.asyncEnumerator = null; - } - - self.core.TrySetCanceled(self.cancellationToken); } public void Dispose() @@ -479,12 +424,7 @@ namespace Cysharp.Threading.Tasks unityEvent.RemoveListener(action); } - asyncEnumerator?.DisposeAsync().Forget(); - try - { - core.TrySetCanceled(); - } - catch (OperationCanceledException) { } + core.TrySetCanceled(); } } @@ -532,120 +472,213 @@ namespace Cysharp.Threading.Tasks { core.OnCompleted(continuation, state, token); } + } - // AsyncEnumerator + public class UnityEventHandlerAsyncEnumerable : IUniTaskAsyncEnumerable + { + readonly UnityEvent unityEvent; + readonly CancellationToken cancellationToken1; - bool disableAutoClose; - Enumerator asyncEnumerator; - - public AsyncUnityEventHandler DisableAutoClose() + public UnityEventHandlerAsyncEnumerable(UnityEvent unityEvent, CancellationToken cancellationToken) { - disableAutoClose = true; - return this; + this.unityEvent = unityEvent; + this.cancellationToken1 = cancellationToken; } - IAsyncValueChangedEventHandler IAsyncValueChangedEventHandler.DisableAutoClose() + public IUniTaskAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) { - disableAutoClose = true; - return this; - } - - IAsyncEndEditEventHandler IAsyncEndEditEventHandler.DisableAutoClose() - { - disableAutoClose = true; - return this; - } - - IUniTaskAsyncEnumerator IUniTaskAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) - { - if (this.asyncEnumerator != null) + if (this.cancellationToken1 == cancellationToken) { - throw new InvalidOperationException("Already acquired GetAsyncEnumerator, does not allow get twice before previous enumerator completed."); + return new Enumerator(unityEvent, this.cancellationToken1, CancellationToken.None); + } + else + { + return new Enumerator(unityEvent, this.cancellationToken1, cancellationToken); } - - this.asyncEnumerator = new Enumerator(this, cancellationToken); - return asyncEnumerator; } - class Enumerator : Cysharp.Threading.Tasks.Linq.MoveNextSource, IUniTaskAsyncEnumerator + class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator { - static Action cancellationCallback = CancellationCallback; + static readonly Action cancel1 = OnCanceled1; + static readonly Action cancel2 = OnCanceled2; - AsyncUnityEventHandler parent; - CancellationToken cancellationToken; - CancellationTokenRegistration registration; + readonly UnityEvent unityEvent; + CancellationToken cancellationToken1; + CancellationToken cancellationToken2; + + UnityAction unityAction; + CancellationTokenRegistration registration1; + CancellationTokenRegistration registration2; bool isDisposed; - public Enumerator(AsyncUnityEventHandler parent, CancellationToken cancellationToken) + public Enumerator(UnityEvent unityEvent, CancellationToken cancellationToken1, CancellationToken cancellationToken2) { - this.parent = parent; - this.cancellationToken = cancellationToken; + this.unityEvent = unityEvent; + this.cancellationToken1 = cancellationToken1; + this.cancellationToken2 = cancellationToken2; + } - if (cancellationToken.CanBeCanceled && parent.cancellationToken != cancellationToken) + public AsyncUnit Current => default; + + public UniTask MoveNextAsync() + { + cancellationToken1.ThrowIfCancellationRequested(); + cancellationToken2.ThrowIfCancellationRequested(); + completionSource.Reset(); + + if (unityAction == null) { - registration = cancellationToken.RegisterWithoutCaptureExecutionContext(cancellationCallback, this); + unityAction = Invoke; + + TaskTracker.TrackActiveTask(this, 3); + unityEvent.AddListener(unityAction); + if (cancellationToken1.CanBeCanceled) + { + registration1 = cancellationToken1.RegisterWithoutCaptureExecutionContext(cancel1, this); + } + if (cancellationToken2.CanBeCanceled) + { + registration2 = cancellationToken1.RegisterWithoutCaptureExecutionContext(cancel2, this); + } } - TaskTracker.TrackActiveTask(this, 3); + return new UniTask(this, completionSource.Version); } - static void CancellationCallback(object state) + void Invoke() + { + completionSource.TrySetResult(true); + } + + static void OnCanceled1(object state) { var self = (Enumerator)state; - self.DisposeCore(self.cancellationToken); + self.DisposeAsync().Forget(); } - public void CancelFromParent(CancellationToken cancellationToken) + static void OnCanceled2(object state) { - // call from parent, avoid parent close. - parent.disableAutoClose = true; - DisposeCore(cancellationToken); + var self = (Enumerator)state; + self.DisposeAsync().Forget(); } - public void SetResult(T result) + public UniTask DisposeAsync() { - Current = result; - completionSource.TrySetResult(true); + if (!isDisposed) + { + isDisposed = true; + TaskTracker.RemoveTracking(this); + registration1.Dispose(); + registration2.Dispose(); + unityEvent.RemoveListener(unityAction); + } + + return default; + } + } + } + + public class UnityEventHandlerAsyncEnumerable : IUniTaskAsyncEnumerable + { + readonly UnityEvent unityEvent; + readonly CancellationToken cancellationToken1; + + public UnityEventHandlerAsyncEnumerable(UnityEvent unityEvent, CancellationToken cancellationToken) + { + this.unityEvent = unityEvent; + this.cancellationToken1 = cancellationToken; + } + + public IUniTaskAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) + { + if (this.cancellationToken1 == cancellationToken) + { + return new Enumerator(unityEvent, this.cancellationToken1, CancellationToken.None); + } + else + { + return new Enumerator(unityEvent, this.cancellationToken1, cancellationToken); + } + } + + class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator + { + static readonly Action cancel1 = OnCanceled1; + static readonly Action cancel2 = OnCanceled2; + + readonly UnityEvent unityEvent; + CancellationToken cancellationToken1; + CancellationToken cancellationToken2; + + UnityAction unityAction; + CancellationTokenRegistration registration1; + CancellationTokenRegistration registration2; + bool isDisposed; + + public Enumerator(UnityEvent unityEvent, CancellationToken cancellationToken1, CancellationToken cancellationToken2) + { + this.unityEvent = unityEvent; + this.cancellationToken1 = cancellationToken1; + this.cancellationToken2 = cancellationToken2; } public T Current { get; private set; } public UniTask MoveNextAsync() { + cancellationToken1.ThrowIfCancellationRequested(); + cancellationToken2.ThrowIfCancellationRequested(); completionSource.Reset(); + + if (unityAction == null) + { + unityAction = Invoke; + + TaskTracker.TrackActiveTask(this, 3); + unityEvent.AddListener(unityAction); + if (cancellationToken1.CanBeCanceled) + { + registration1 = cancellationToken1.RegisterWithoutCaptureExecutionContext(cancel1, this); + } + if (cancellationToken2.CanBeCanceled) + { + registration2 = cancellationToken1.RegisterWithoutCaptureExecutionContext(cancel2, this); + } + } + return new UniTask(this, completionSource.Version); } + void Invoke(T value) + { + Current = value; + completionSource.TrySetResult(true); + } + + static void OnCanceled1(object state) + { + var self = (Enumerator)state; + self.DisposeAsync().Forget(); + } + + static void OnCanceled2(object state) + { + var self = (Enumerator)state; + self.DisposeAsync().Forget(); + } + public UniTask DisposeAsync() - { - DisposeCore(CancellationToken.None); - return default; - } - - void DisposeCore(CancellationToken cancellationToken) { if (!isDisposed) { isDisposed = true; - registration.Dispose(); TaskTracker.RemoveTracking(this); - - if (!parent.disableAutoClose) - { - parent.Dispose(); // dispose parent. - } - - if (parent.asyncEnumerator == this) - { - parent.asyncEnumerator = null; - } - - try - { - completionSource.TrySetCanceled(cancellationToken); - } - catch (OperationCanceledException) { } + registration1.Dispose(); + registration2.Dispose(); + unityEvent.RemoveListener(unityAction); } + + return default; } } } diff --git a/src/UniTask/Assets/Scenes/SandboxMain.cs b/src/UniTask/Assets/Scenes/SandboxMain.cs index 66a82bb..79cf010 100644 --- a/src/UniTask/Assets/Scenes/SandboxMain.cs +++ b/src/UniTask/Assets/Scenes/SandboxMain.cs @@ -1,4 +1,5 @@ using System; + using Cysharp.Threading.Tasks.Linq; using Cysharp.Threading.Tasks.Triggers; using System.Collections; @@ -145,8 +146,23 @@ public class SandboxMain : MonoBehaviour //StartCoroutine(cor); + await okButton.OnClickAsAsyncEnumerable().Where((x, i) => i % 2 == 0).ForEachAsync(_ => + { + Debug.Log("Call"); + }); + + //try + //{ + // await this.GetAsyncUpdateTrigger().ForEachAsync(_ => + // { + // UnityEngine.Debug.Log("EveryUpdate:" + Time.frameCount); + // }); + //} + //catch (OperationCanceledException ex) + //{ + // UnityEngine.Debug.Log("END"); + //} - //this.TryGetComponent( CancellationTokenSource cts = new CancellationTokenSource(); @@ -167,18 +183,19 @@ public class SandboxMain : MonoBehaviour // 5回クリックされるまで待つ、とか。 - Debug.Log("Await start."); + //Debug.Log("Await start."); - await okButton.GetAsyncClickEventHandler().DisableAutoClose() - .Select((_, clickCount) => clickCount + 1) - .FirstAsync(x => x == 5); + //await okButton.GetAsyncClickEventHandler().DisableAutoClose() + // .Select((_, clickCount) => clickCount + 1) + // .FirstAsync(x => x == 5); - Debug.Log("Click 5 times."); + //Debug.Log("Click 5 times."); + // await this.GetAsyncUpdateTrigger().UpdateAsAsyncEnumerable()