diff --git a/src/UniTask.NetCoreSandbox/Program.cs b/src/UniTask.NetCoreSandbox/Program.cs index f63f2ff..6ca55dc 100644 --- a/src/UniTask.NetCoreSandbox/Program.cs +++ b/src/UniTask.NetCoreSandbox/Program.cs @@ -15,6 +15,55 @@ using System.Reactive.Concurrency; namespace NetCoreSandbox { + public class Text + { + + public string text { get; set; } + } + + public static partial class UnityUIComponentExtensions + { + public static void BindTo(this IUniTaskAsyncEnumerable source, Text text) + { + AAAACORECORE(source, text).Forget(); + + async UniTaskVoid AAAACORECORE(IUniTaskAsyncEnumerable source2, Text text2) + { + var e = source2.GetAsyncEnumerator(); + try + { + while (await e.MoveNextAsync()) + { + text2.text = e.Current; + // action(e.Current); + } + } + finally + { + if (e != null) + { + await e.DisposeAsync(); + } + } + } + } + + //public static IDisposable SubscribeToText(this IObservable source, Text text) + //{ + // return source.SubscribeWithState(text, (x, t) => t.text = x.ToString()); + //} + + //public static IDisposable SubscribeToText(this IObservable source, Text text, Func selector) + //{ + // return source.SubscribeWithState2(text, selector, (x, t, s) => t.text = s(x)); + //} + + //public static IDisposable SubscribeToInteractable(this IObservable source, Selectable selectable) + //{ + // return source.SubscribeWithState(selectable, (x, s) => s.interactable = x); + //} + } + class Program { static string FlattenGenArgs(Type type) diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/Triggers/AsyncAwakeTrigger.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/Triggers/AsyncAwakeTrigger.cs index 9c19914..a734f29 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/Triggers/AsyncAwakeTrigger.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/Triggers/AsyncAwakeTrigger.cs @@ -19,56 +19,13 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public class AsyncAwakeTrigger : MonoBehaviour + public sealed class AsyncAwakeTrigger : AsyncTriggerBase { - bool called = false; - TriggerEvent triggerEvent; - - void Awake() - { - called = true; - triggerEvent?.TrySetResult(AsyncUnit.Default); - triggerEvent = null; - } - public UniTask AwakeAsync() { - if (called) return UniTask.CompletedTask; + if (calledAwake) return UniTask.CompletedTask; - PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, new AwakeMonitor(this)); - - if (triggerEvent == null) - { - triggerEvent = new TriggerEvent(); - } - - return ((IAsyncOneShotTrigger)new AsyncTriggerHandler(triggerEvent, true)).OneShotAsync(); - } - - private void OnDestroy() - { - triggerEvent?.TrySetCanceled(CancellationToken.None); - } - - class AwakeMonitor : IPlayerLoopItem - { - readonly AsyncAwakeTrigger trigger; - - public AwakeMonitor(AsyncAwakeTrigger trigger) - { - this.trigger = trigger; - } - - public bool MoveNext() - { - if (trigger.called) return false; - if (trigger == null) - { - trigger.OnDestroy(); - return false; - } - return true; - } + return ((IAsyncOneShotTrigger)new AsyncTriggerHandler(this, true)).OneShotAsync(); } } } diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/Triggers/AsyncDestroyTrigger.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/Triggers/AsyncDestroyTrigger.cs index cf522d5..811f977 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/Triggers/AsyncDestroyTrigger.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/Triggers/AsyncDestroyTrigger.cs @@ -19,11 +19,10 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public class AsyncDestroyTrigger : MonoBehaviour + public sealed class AsyncDestroyTrigger : MonoBehaviour { bool awakeCalled = false; bool called = false; - TriggerEvent triggerEvent; CancellationTokenSource cancellationTokenSource; public CancellationToken CancellationToken @@ -34,6 +33,12 @@ namespace Cysharp.Threading.Tasks.Triggers { cancellationTokenSource = new CancellationTokenSource(); } + + if (!awakeCalled) + { + PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, new AwakeMonitor(this)); + } + return cancellationTokenSource.Token; } } @@ -47,28 +52,24 @@ namespace Cysharp.Threading.Tasks.Triggers { called = true; - triggerEvent?.TrySetResult(AsyncUnit.Default); cancellationTokenSource?.Cancel(); cancellationTokenSource?.Dispose(); - - triggerEvent = null; } public UniTask OnDestroyAsync() { if (called) return UniTask.CompletedTask; - if (!awakeCalled) - { - PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, new AwakeMonitor(this)); - } + var tcs = new UniTaskCompletionSource(); - if (triggerEvent == null) + // OnDestroy = Called Cancel. + CancellationToken.RegisterWithoutCaptureExecutionContext(state => { - triggerEvent = new TriggerEvent(); - } + var tcs2 = (UniTaskCompletionSource)state; + tcs2.TrySetResult(); + }, tcs); - return ((IAsyncOneShotTrigger)new AsyncTriggerHandler(triggerEvent, true)).OneShotAsync(); + return tcs.Task; } class AwakeMonitor : IPlayerLoopItem diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/Triggers/AsyncStartTrigger.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/Triggers/AsyncStartTrigger.cs index 94028c2..63da82a 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/Triggers/AsyncStartTrigger.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/Triggers/AsyncStartTrigger.cs @@ -1,6 +1,5 @@ #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member -using System.Threading; using UnityEngine; namespace Cysharp.Threading.Tasks.Triggers @@ -19,67 +18,21 @@ namespace Cysharp.Threading.Tasks.Triggers } [DisallowMultipleComponent] - public class AsyncStartTrigger : MonoBehaviour + public sealed class AsyncStartTrigger : AsyncTriggerBase { - bool awakeCalled = false; - bool called = false; - TriggerEvent triggerEvent; - - void Awake() - { - awakeCalled = true; - } + bool called; void Start() { called = true; - triggerEvent?.TrySetResult(AsyncUnit.Default); - triggerEvent = null; + RaiseEvent(AsyncUnit.Default); } public UniTask StartAsync() { if (called) return UniTask.CompletedTask; - if (!awakeCalled) - { - PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, new AwakeMonitor(this)); - } - - if (triggerEvent == null) - { - triggerEvent = new TriggerEvent(); - } - - return ((IAsyncOneShotTrigger)new AsyncTriggerHandler(triggerEvent, true)).OneShotAsync(); - } - - private void OnDestroy() - { - triggerEvent?.TrySetCanceled(CancellationToken.None); - } - - class AwakeMonitor : IPlayerLoopItem - { - readonly AsyncStartTrigger trigger; - - public AwakeMonitor(AsyncStartTrigger trigger) - { - this.trigger = trigger; - } - - public bool MoveNext() - { - if (trigger.called) return false; - if (trigger == null) - { - trigger.OnDestroy(); - return false; - } - return true; - } + return ((IAsyncOneShotTrigger)new AsyncTriggerHandler(this, true)).OneShotAsync(); } } - -} - +} \ No newline at end of file diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/Triggers/AsyncTriggerBase.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/Triggers/AsyncTriggerBase.cs index d87848c..a8a34b3 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/Triggers/AsyncTriggerBase.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/Triggers/AsyncTriggerBase.cs @@ -10,67 +10,67 @@ namespace Cysharp.Threading.Tasks.Triggers { public abstract class AsyncTriggerBase : MonoBehaviour, IUniTaskAsyncEnumerable { - protected TriggerEvent triggerEvent; + TriggerEvent triggerEvent; - bool calledAwake; - bool calledDestroy; - ICancelPromise triggerSlot; + internal protected bool calledAwake; + internal protected bool calledDestroy; void Awake() { calledAwake = true; } - protected TriggerEvent GetTriggerEvent() - { - if (triggerEvent == null) - { - triggerEvent = new TriggerEvent(); - if (triggerSlot == null) - { - triggerSlot = triggerEvent; - } - else - { - throw new InvalidOperationException("triggerSlot is already filled."); - } - } - - if (!calledAwake) - { - PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, new AwakeMonitor(this)); - } - - return triggerEvent; - } - void OnDestroy() { if (calledDestroy) return; calledDestroy = true; - triggerSlot?.TrySetCanceled(); - triggerSlot = null; + triggerEvent.TrySetCanceled(CancellationToken.None); + } + + internal void AddHandler(IResolveCancelPromise handler) + { + if (!calledAwake) + { + PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, new AwakeMonitor(this)); + } + + triggerEvent.Add(handler); + } + + internal void RemoveHandler(IResolveCancelPromise handler) + { + if (!calledAwake) + { + PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, new AwakeMonitor(this)); + } + + triggerEvent.Remove(handler); + } + + protected void RaiseEvent(T value) + { + triggerEvent.TrySetResult(value); } public IUniTaskAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) { - return new AsyncTriggerEnumerator(GetTriggerEvent(), cancellationToken); + return new AsyncTriggerEnumerator(this, cancellationToken); } sealed class AsyncTriggerEnumerator : MoveNextSource, IUniTaskAsyncEnumerator, IResolveCancelPromise { static Action cancellationCallback = CancellationCallback; - readonly TriggerEvent triggerEvent; + readonly AsyncTriggerBase parent; CancellationToken cancellationToken; CancellationTokenRegistration registration; bool called; bool isDisposed; - public AsyncTriggerEnumerator(TriggerEvent triggerEvent, CancellationToken cancellationToken) + public AsyncTriggerEnumerator(AsyncTriggerBase parent, CancellationToken cancellationToken) { - this.triggerEvent = triggerEvent; + this.parent = parent; this.cancellationToken = cancellationToken; } @@ -105,13 +105,13 @@ namespace Cysharp.Threading.Tasks.Triggers called = true; TaskTracker.TrackActiveTask(this, 3); - triggerEvent.Add(this); + parent.AddHandler(this); if (cancellationToken.CanBeCanceled) { registration = cancellationToken.RegisterWithoutCaptureExecutionContext(cancellationCallback, this); } } - + return new UniTask(this, completionSource.Version); } @@ -122,7 +122,7 @@ namespace Cysharp.Threading.Tasks.Triggers isDisposed = true; TaskTracker.RemoveTracking(this); registration.Dispose(); - triggerEvent.Remove(this); + parent.RemoveHandler(this); } return default; @@ -169,7 +169,7 @@ namespace Cysharp.Threading.Tasks.Triggers { static Action cancellationCallback = CancellationCallback; - readonly TriggerEvent trigger; + readonly AsyncTriggerBase trigger; CancellationToken cancellationToken; CancellationTokenRegistration registration; @@ -180,7 +180,7 @@ namespace Cysharp.Threading.Tasks.Triggers internal CancellationToken CancellationToken => cancellationToken; - public AsyncTriggerHandler(TriggerEvent trigger, bool callOnce) + internal AsyncTriggerHandler(AsyncTriggerBase trigger, bool callOnce) { if (cancellationToken.IsCancellationRequested) { @@ -193,12 +193,12 @@ namespace Cysharp.Threading.Tasks.Triggers this.registration = default; this.callOnce = callOnce; - trigger.Add(this); + trigger.AddHandler(this); TaskTracker.TrackActiveTask(this, 3); } - public AsyncTriggerHandler(TriggerEvent trigger, CancellationToken cancellationToken, bool callOnce) + internal AsyncTriggerHandler(AsyncTriggerBase trigger, CancellationToken cancellationToken, bool callOnce) { if (cancellationToken.IsCancellationRequested) { @@ -210,7 +210,7 @@ namespace Cysharp.Threading.Tasks.Triggers this.cancellationToken = cancellationToken; this.callOnce = callOnce; - trigger.Add(this); + trigger.AddHandler(this); if (cancellationToken.CanBeCanceled) { @@ -235,7 +235,7 @@ namespace Cysharp.Threading.Tasks.Triggers isDisposed = true; TaskTracker.RemoveTracking(this); registration.Dispose(); - trigger.Remove(this); + trigger.RemoveHandler(this); } } @@ -285,7 +285,8 @@ namespace Cysharp.Threading.Tasks.Triggers } } - public sealed class TriggerEvent : IResolveCancelPromise + // be careful to use, itself is struct. + public struct TriggerEvent { // optimize: many cases, handler is single. IResolveCancelPromise singleHandler; diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/Triggers/MonoBehaviourMessagesTriggers.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/Triggers/MonoBehaviourMessagesTriggers.cs index 2504288..bbe4271 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/Triggers/MonoBehaviourMessagesTriggers.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/Triggers/MonoBehaviourMessagesTriggers.cs @@ -40,27 +40,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void FixedUpdate() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncFixedUpdateHandler GetFixedUpdateAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncFixedUpdateHandler GetFixedUpdateAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask FixedUpdateAsync() { - return ((IAsyncFixedUpdateHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).FixedUpdateAsync(); + return ((IAsyncFixedUpdateHandler)new AsyncTriggerHandler(this, true)).FixedUpdateAsync(); } public UniTask FixedUpdateAsync(CancellationToken cancellationToken) { - return ((IAsyncFixedUpdateHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).FixedUpdateAsync(); + return ((IAsyncFixedUpdateHandler)new AsyncTriggerHandler(this, cancellationToken, true)).FixedUpdateAsync(); } } #endregion @@ -99,27 +99,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void LateUpdate() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncLateUpdateHandler GetLateUpdateAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncLateUpdateHandler GetLateUpdateAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask LateUpdateAsync() { - return ((IAsyncLateUpdateHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).LateUpdateAsync(); + return ((IAsyncLateUpdateHandler)new AsyncTriggerHandler(this, true)).LateUpdateAsync(); } public UniTask LateUpdateAsync(CancellationToken cancellationToken) { - return ((IAsyncLateUpdateHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).LateUpdateAsync(); + return ((IAsyncLateUpdateHandler)new AsyncTriggerHandler(this, cancellationToken, true)).LateUpdateAsync(); } } #endregion @@ -158,27 +158,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnAnimatorIK(int layerIndex) { - triggerEvent?.TrySetResult((layerIndex)); + RaiseEvent((layerIndex)); } public IAsyncOnAnimatorIKHandler GetOnAnimatorIKAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnAnimatorIKHandler GetOnAnimatorIKAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnAnimatorIKAsync() { - return ((IAsyncOnAnimatorIKHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnAnimatorIKAsync(); + return ((IAsyncOnAnimatorIKHandler)new AsyncTriggerHandler(this, true)).OnAnimatorIKAsync(); } public UniTask OnAnimatorIKAsync(CancellationToken cancellationToken) { - return ((IAsyncOnAnimatorIKHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnAnimatorIKAsync(); + return ((IAsyncOnAnimatorIKHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnAnimatorIKAsync(); } } #endregion @@ -217,27 +217,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnAnimatorMove() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncOnAnimatorMoveHandler GetOnAnimatorMoveAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnAnimatorMoveHandler GetOnAnimatorMoveAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnAnimatorMoveAsync() { - return ((IAsyncOnAnimatorMoveHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnAnimatorMoveAsync(); + return ((IAsyncOnAnimatorMoveHandler)new AsyncTriggerHandler(this, true)).OnAnimatorMoveAsync(); } public UniTask OnAnimatorMoveAsync(CancellationToken cancellationToken) { - return ((IAsyncOnAnimatorMoveHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnAnimatorMoveAsync(); + return ((IAsyncOnAnimatorMoveHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnAnimatorMoveAsync(); } } #endregion @@ -276,27 +276,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnApplicationFocus(bool hasFocus) { - triggerEvent?.TrySetResult((hasFocus)); + RaiseEvent((hasFocus)); } public IAsyncOnApplicationFocusHandler GetOnApplicationFocusAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnApplicationFocusHandler GetOnApplicationFocusAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnApplicationFocusAsync() { - return ((IAsyncOnApplicationFocusHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnApplicationFocusAsync(); + return ((IAsyncOnApplicationFocusHandler)new AsyncTriggerHandler(this, true)).OnApplicationFocusAsync(); } public UniTask OnApplicationFocusAsync(CancellationToken cancellationToken) { - return ((IAsyncOnApplicationFocusHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnApplicationFocusAsync(); + return ((IAsyncOnApplicationFocusHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnApplicationFocusAsync(); } } #endregion @@ -335,27 +335,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnApplicationPause(bool pauseStatus) { - triggerEvent?.TrySetResult((pauseStatus)); + RaiseEvent((pauseStatus)); } public IAsyncOnApplicationPauseHandler GetOnApplicationPauseAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnApplicationPauseHandler GetOnApplicationPauseAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnApplicationPauseAsync() { - return ((IAsyncOnApplicationPauseHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnApplicationPauseAsync(); + return ((IAsyncOnApplicationPauseHandler)new AsyncTriggerHandler(this, true)).OnApplicationPauseAsync(); } public UniTask OnApplicationPauseAsync(CancellationToken cancellationToken) { - return ((IAsyncOnApplicationPauseHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnApplicationPauseAsync(); + return ((IAsyncOnApplicationPauseHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnApplicationPauseAsync(); } } #endregion @@ -394,27 +394,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnApplicationQuit() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncOnApplicationQuitHandler GetOnApplicationQuitAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnApplicationQuitHandler GetOnApplicationQuitAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnApplicationQuitAsync() { - return ((IAsyncOnApplicationQuitHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnApplicationQuitAsync(); + return ((IAsyncOnApplicationQuitHandler)new AsyncTriggerHandler(this, true)).OnApplicationQuitAsync(); } public UniTask OnApplicationQuitAsync(CancellationToken cancellationToken) { - return ((IAsyncOnApplicationQuitHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnApplicationQuitAsync(); + return ((IAsyncOnApplicationQuitHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnApplicationQuitAsync(); } } #endregion @@ -453,27 +453,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnAudioFilterRead(float[] data, int channels) { - triggerEvent?.TrySetResult((data, channels)); + RaiseEvent((data, channels)); } public IAsyncOnAudioFilterReadHandler GetOnAudioFilterReadAsyncHandler() { - return new AsyncTriggerHandler<(float[] data, int channels)>(GetTriggerEvent(), false); + return new AsyncTriggerHandler<(float[] data, int channels)>(this, false); } public IAsyncOnAudioFilterReadHandler GetOnAudioFilterReadAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler<(float[] data, int channels)>(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler<(float[] data, int channels)>(this, cancellationToken, false); } public UniTask<(float[] data, int channels)> OnAudioFilterReadAsync() { - return ((IAsyncOnAudioFilterReadHandler)new AsyncTriggerHandler<(float[] data, int channels)>(GetTriggerEvent(), true)).OnAudioFilterReadAsync(); + return ((IAsyncOnAudioFilterReadHandler)new AsyncTriggerHandler<(float[] data, int channels)>(this, true)).OnAudioFilterReadAsync(); } public UniTask<(float[] data, int channels)> OnAudioFilterReadAsync(CancellationToken cancellationToken) { - return ((IAsyncOnAudioFilterReadHandler)new AsyncTriggerHandler<(float[] data, int channels)>(GetTriggerEvent(), cancellationToken, true)).OnAudioFilterReadAsync(); + return ((IAsyncOnAudioFilterReadHandler)new AsyncTriggerHandler<(float[] data, int channels)>(this, cancellationToken, true)).OnAudioFilterReadAsync(); } } #endregion @@ -512,27 +512,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnBecameInvisible() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncOnBecameInvisibleHandler GetOnBecameInvisibleAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnBecameInvisibleHandler GetOnBecameInvisibleAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnBecameInvisibleAsync() { - return ((IAsyncOnBecameInvisibleHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnBecameInvisibleAsync(); + return ((IAsyncOnBecameInvisibleHandler)new AsyncTriggerHandler(this, true)).OnBecameInvisibleAsync(); } public UniTask OnBecameInvisibleAsync(CancellationToken cancellationToken) { - return ((IAsyncOnBecameInvisibleHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnBecameInvisibleAsync(); + return ((IAsyncOnBecameInvisibleHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnBecameInvisibleAsync(); } } #endregion @@ -571,27 +571,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnBecameVisible() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncOnBecameVisibleHandler GetOnBecameVisibleAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnBecameVisibleHandler GetOnBecameVisibleAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnBecameVisibleAsync() { - return ((IAsyncOnBecameVisibleHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnBecameVisibleAsync(); + return ((IAsyncOnBecameVisibleHandler)new AsyncTriggerHandler(this, true)).OnBecameVisibleAsync(); } public UniTask OnBecameVisibleAsync(CancellationToken cancellationToken) { - return ((IAsyncOnBecameVisibleHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnBecameVisibleAsync(); + return ((IAsyncOnBecameVisibleHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnBecameVisibleAsync(); } } #endregion @@ -630,27 +630,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnBeforeTransformParentChanged() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncOnBeforeTransformParentChangedHandler GetOnBeforeTransformParentChangedAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnBeforeTransformParentChangedHandler GetOnBeforeTransformParentChangedAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnBeforeTransformParentChangedAsync() { - return ((IAsyncOnBeforeTransformParentChangedHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnBeforeTransformParentChangedAsync(); + return ((IAsyncOnBeforeTransformParentChangedHandler)new AsyncTriggerHandler(this, true)).OnBeforeTransformParentChangedAsync(); } public UniTask OnBeforeTransformParentChangedAsync(CancellationToken cancellationToken) { - return ((IAsyncOnBeforeTransformParentChangedHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnBeforeTransformParentChangedAsync(); + return ((IAsyncOnBeforeTransformParentChangedHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnBeforeTransformParentChangedAsync(); } } #endregion @@ -689,27 +689,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnCanvasGroupChanged() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncOnCanvasGroupChangedHandler GetOnCanvasGroupChangedAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnCanvasGroupChangedHandler GetOnCanvasGroupChangedAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnCanvasGroupChangedAsync() { - return ((IAsyncOnCanvasGroupChangedHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnCanvasGroupChangedAsync(); + return ((IAsyncOnCanvasGroupChangedHandler)new AsyncTriggerHandler(this, true)).OnCanvasGroupChangedAsync(); } public UniTask OnCanvasGroupChangedAsync(CancellationToken cancellationToken) { - return ((IAsyncOnCanvasGroupChangedHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnCanvasGroupChangedAsync(); + return ((IAsyncOnCanvasGroupChangedHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnCanvasGroupChangedAsync(); } } #endregion @@ -748,27 +748,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnCollisionEnter(Collision coll) { - triggerEvent?.TrySetResult((coll)); + RaiseEvent((coll)); } public IAsyncOnCollisionEnterHandler GetOnCollisionEnterAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnCollisionEnterHandler GetOnCollisionEnterAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnCollisionEnterAsync() { - return ((IAsyncOnCollisionEnterHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnCollisionEnterAsync(); + return ((IAsyncOnCollisionEnterHandler)new AsyncTriggerHandler(this, true)).OnCollisionEnterAsync(); } public UniTask OnCollisionEnterAsync(CancellationToken cancellationToken) { - return ((IAsyncOnCollisionEnterHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnCollisionEnterAsync(); + return ((IAsyncOnCollisionEnterHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnCollisionEnterAsync(); } } #endregion @@ -807,27 +807,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnCollisionEnter2D(Collision2D coll) { - triggerEvent?.TrySetResult((coll)); + RaiseEvent((coll)); } public IAsyncOnCollisionEnter2DHandler GetOnCollisionEnter2DAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnCollisionEnter2DHandler GetOnCollisionEnter2DAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnCollisionEnter2DAsync() { - return ((IAsyncOnCollisionEnter2DHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnCollisionEnter2DAsync(); + return ((IAsyncOnCollisionEnter2DHandler)new AsyncTriggerHandler(this, true)).OnCollisionEnter2DAsync(); } public UniTask OnCollisionEnter2DAsync(CancellationToken cancellationToken) { - return ((IAsyncOnCollisionEnter2DHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnCollisionEnter2DAsync(); + return ((IAsyncOnCollisionEnter2DHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnCollisionEnter2DAsync(); } } #endregion @@ -866,27 +866,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnCollisionExit(Collision coll) { - triggerEvent?.TrySetResult((coll)); + RaiseEvent((coll)); } public IAsyncOnCollisionExitHandler GetOnCollisionExitAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnCollisionExitHandler GetOnCollisionExitAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnCollisionExitAsync() { - return ((IAsyncOnCollisionExitHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnCollisionExitAsync(); + return ((IAsyncOnCollisionExitHandler)new AsyncTriggerHandler(this, true)).OnCollisionExitAsync(); } public UniTask OnCollisionExitAsync(CancellationToken cancellationToken) { - return ((IAsyncOnCollisionExitHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnCollisionExitAsync(); + return ((IAsyncOnCollisionExitHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnCollisionExitAsync(); } } #endregion @@ -925,27 +925,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnCollisionExit2D(Collision2D coll) { - triggerEvent?.TrySetResult((coll)); + RaiseEvent((coll)); } public IAsyncOnCollisionExit2DHandler GetOnCollisionExit2DAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnCollisionExit2DHandler GetOnCollisionExit2DAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnCollisionExit2DAsync() { - return ((IAsyncOnCollisionExit2DHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnCollisionExit2DAsync(); + return ((IAsyncOnCollisionExit2DHandler)new AsyncTriggerHandler(this, true)).OnCollisionExit2DAsync(); } public UniTask OnCollisionExit2DAsync(CancellationToken cancellationToken) { - return ((IAsyncOnCollisionExit2DHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnCollisionExit2DAsync(); + return ((IAsyncOnCollisionExit2DHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnCollisionExit2DAsync(); } } #endregion @@ -984,27 +984,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnCollisionStay(Collision coll) { - triggerEvent?.TrySetResult((coll)); + RaiseEvent((coll)); } public IAsyncOnCollisionStayHandler GetOnCollisionStayAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnCollisionStayHandler GetOnCollisionStayAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnCollisionStayAsync() { - return ((IAsyncOnCollisionStayHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnCollisionStayAsync(); + return ((IAsyncOnCollisionStayHandler)new AsyncTriggerHandler(this, true)).OnCollisionStayAsync(); } public UniTask OnCollisionStayAsync(CancellationToken cancellationToken) { - return ((IAsyncOnCollisionStayHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnCollisionStayAsync(); + return ((IAsyncOnCollisionStayHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnCollisionStayAsync(); } } #endregion @@ -1043,27 +1043,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnCollisionStay2D(Collision2D coll) { - triggerEvent?.TrySetResult((coll)); + RaiseEvent((coll)); } public IAsyncOnCollisionStay2DHandler GetOnCollisionStay2DAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnCollisionStay2DHandler GetOnCollisionStay2DAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnCollisionStay2DAsync() { - return ((IAsyncOnCollisionStay2DHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnCollisionStay2DAsync(); + return ((IAsyncOnCollisionStay2DHandler)new AsyncTriggerHandler(this, true)).OnCollisionStay2DAsync(); } public UniTask OnCollisionStay2DAsync(CancellationToken cancellationToken) { - return ((IAsyncOnCollisionStay2DHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnCollisionStay2DAsync(); + return ((IAsyncOnCollisionStay2DHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnCollisionStay2DAsync(); } } #endregion @@ -1102,27 +1102,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnControllerColliderHit(ControllerColliderHit hit) { - triggerEvent?.TrySetResult((hit)); + RaiseEvent((hit)); } public IAsyncOnControllerColliderHitHandler GetOnControllerColliderHitAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnControllerColliderHitHandler GetOnControllerColliderHitAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnControllerColliderHitAsync() { - return ((IAsyncOnControllerColliderHitHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnControllerColliderHitAsync(); + return ((IAsyncOnControllerColliderHitHandler)new AsyncTriggerHandler(this, true)).OnControllerColliderHitAsync(); } public UniTask OnControllerColliderHitAsync(CancellationToken cancellationToken) { - return ((IAsyncOnControllerColliderHitHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnControllerColliderHitAsync(); + return ((IAsyncOnControllerColliderHitHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnControllerColliderHitAsync(); } } #endregion @@ -1161,27 +1161,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnDisable() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncOnDisableHandler GetOnDisableAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnDisableHandler GetOnDisableAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnDisableAsync() { - return ((IAsyncOnDisableHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnDisableAsync(); + return ((IAsyncOnDisableHandler)new AsyncTriggerHandler(this, true)).OnDisableAsync(); } public UniTask OnDisableAsync(CancellationToken cancellationToken) { - return ((IAsyncOnDisableHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnDisableAsync(); + return ((IAsyncOnDisableHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnDisableAsync(); } } #endregion @@ -1220,27 +1220,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnDrawGizmos() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncOnDrawGizmosHandler GetOnDrawGizmosAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnDrawGizmosHandler GetOnDrawGizmosAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnDrawGizmosAsync() { - return ((IAsyncOnDrawGizmosHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnDrawGizmosAsync(); + return ((IAsyncOnDrawGizmosHandler)new AsyncTriggerHandler(this, true)).OnDrawGizmosAsync(); } public UniTask OnDrawGizmosAsync(CancellationToken cancellationToken) { - return ((IAsyncOnDrawGizmosHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnDrawGizmosAsync(); + return ((IAsyncOnDrawGizmosHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnDrawGizmosAsync(); } } #endregion @@ -1279,27 +1279,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnDrawGizmosSelected() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncOnDrawGizmosSelectedHandler GetOnDrawGizmosSelectedAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnDrawGizmosSelectedHandler GetOnDrawGizmosSelectedAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnDrawGizmosSelectedAsync() { - return ((IAsyncOnDrawGizmosSelectedHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnDrawGizmosSelectedAsync(); + return ((IAsyncOnDrawGizmosSelectedHandler)new AsyncTriggerHandler(this, true)).OnDrawGizmosSelectedAsync(); } public UniTask OnDrawGizmosSelectedAsync(CancellationToken cancellationToken) { - return ((IAsyncOnDrawGizmosSelectedHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnDrawGizmosSelectedAsync(); + return ((IAsyncOnDrawGizmosSelectedHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnDrawGizmosSelectedAsync(); } } #endregion @@ -1338,27 +1338,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnEnable() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncOnEnableHandler GetOnEnableAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnEnableHandler GetOnEnableAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnEnableAsync() { - return ((IAsyncOnEnableHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnEnableAsync(); + return ((IAsyncOnEnableHandler)new AsyncTriggerHandler(this, true)).OnEnableAsync(); } public UniTask OnEnableAsync(CancellationToken cancellationToken) { - return ((IAsyncOnEnableHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnEnableAsync(); + return ((IAsyncOnEnableHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnEnableAsync(); } } #endregion @@ -1397,27 +1397,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnGUI() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncOnGUIHandler GetOnGUIAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnGUIHandler GetOnGUIAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnGUIAsync() { - return ((IAsyncOnGUIHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnGUIAsync(); + return ((IAsyncOnGUIHandler)new AsyncTriggerHandler(this, true)).OnGUIAsync(); } public UniTask OnGUIAsync(CancellationToken cancellationToken) { - return ((IAsyncOnGUIHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnGUIAsync(); + return ((IAsyncOnGUIHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnGUIAsync(); } } #endregion @@ -1456,27 +1456,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnJointBreak(float breakForce) { - triggerEvent?.TrySetResult((breakForce)); + RaiseEvent((breakForce)); } public IAsyncOnJointBreakHandler GetOnJointBreakAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnJointBreakHandler GetOnJointBreakAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnJointBreakAsync() { - return ((IAsyncOnJointBreakHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnJointBreakAsync(); + return ((IAsyncOnJointBreakHandler)new AsyncTriggerHandler(this, true)).OnJointBreakAsync(); } public UniTask OnJointBreakAsync(CancellationToken cancellationToken) { - return ((IAsyncOnJointBreakHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnJointBreakAsync(); + return ((IAsyncOnJointBreakHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnJointBreakAsync(); } } #endregion @@ -1515,27 +1515,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnJointBreak2D(Joint2D brokenJoint) { - triggerEvent?.TrySetResult((brokenJoint)); + RaiseEvent((brokenJoint)); } public IAsyncOnJointBreak2DHandler GetOnJointBreak2DAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnJointBreak2DHandler GetOnJointBreak2DAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnJointBreak2DAsync() { - return ((IAsyncOnJointBreak2DHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnJointBreak2DAsync(); + return ((IAsyncOnJointBreak2DHandler)new AsyncTriggerHandler(this, true)).OnJointBreak2DAsync(); } public UniTask OnJointBreak2DAsync(CancellationToken cancellationToken) { - return ((IAsyncOnJointBreak2DHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnJointBreak2DAsync(); + return ((IAsyncOnJointBreak2DHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnJointBreak2DAsync(); } } #endregion @@ -1574,27 +1574,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnMouseDown() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncOnMouseDownHandler GetOnMouseDownAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnMouseDownHandler GetOnMouseDownAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnMouseDownAsync() { - return ((IAsyncOnMouseDownHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnMouseDownAsync(); + return ((IAsyncOnMouseDownHandler)new AsyncTriggerHandler(this, true)).OnMouseDownAsync(); } public UniTask OnMouseDownAsync(CancellationToken cancellationToken) { - return ((IAsyncOnMouseDownHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnMouseDownAsync(); + return ((IAsyncOnMouseDownHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnMouseDownAsync(); } } #endregion @@ -1633,27 +1633,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnMouseDrag() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncOnMouseDragHandler GetOnMouseDragAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnMouseDragHandler GetOnMouseDragAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnMouseDragAsync() { - return ((IAsyncOnMouseDragHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnMouseDragAsync(); + return ((IAsyncOnMouseDragHandler)new AsyncTriggerHandler(this, true)).OnMouseDragAsync(); } public UniTask OnMouseDragAsync(CancellationToken cancellationToken) { - return ((IAsyncOnMouseDragHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnMouseDragAsync(); + return ((IAsyncOnMouseDragHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnMouseDragAsync(); } } #endregion @@ -1692,27 +1692,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnMouseEnter() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncOnMouseEnterHandler GetOnMouseEnterAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnMouseEnterHandler GetOnMouseEnterAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnMouseEnterAsync() { - return ((IAsyncOnMouseEnterHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnMouseEnterAsync(); + return ((IAsyncOnMouseEnterHandler)new AsyncTriggerHandler(this, true)).OnMouseEnterAsync(); } public UniTask OnMouseEnterAsync(CancellationToken cancellationToken) { - return ((IAsyncOnMouseEnterHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnMouseEnterAsync(); + return ((IAsyncOnMouseEnterHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnMouseEnterAsync(); } } #endregion @@ -1751,27 +1751,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnMouseExit() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncOnMouseExitHandler GetOnMouseExitAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnMouseExitHandler GetOnMouseExitAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnMouseExitAsync() { - return ((IAsyncOnMouseExitHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnMouseExitAsync(); + return ((IAsyncOnMouseExitHandler)new AsyncTriggerHandler(this, true)).OnMouseExitAsync(); } public UniTask OnMouseExitAsync(CancellationToken cancellationToken) { - return ((IAsyncOnMouseExitHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnMouseExitAsync(); + return ((IAsyncOnMouseExitHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnMouseExitAsync(); } } #endregion @@ -1810,27 +1810,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnMouseOver() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncOnMouseOverHandler GetOnMouseOverAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnMouseOverHandler GetOnMouseOverAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnMouseOverAsync() { - return ((IAsyncOnMouseOverHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnMouseOverAsync(); + return ((IAsyncOnMouseOverHandler)new AsyncTriggerHandler(this, true)).OnMouseOverAsync(); } public UniTask OnMouseOverAsync(CancellationToken cancellationToken) { - return ((IAsyncOnMouseOverHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnMouseOverAsync(); + return ((IAsyncOnMouseOverHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnMouseOverAsync(); } } #endregion @@ -1869,27 +1869,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnMouseUp() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncOnMouseUpHandler GetOnMouseUpAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnMouseUpHandler GetOnMouseUpAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnMouseUpAsync() { - return ((IAsyncOnMouseUpHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnMouseUpAsync(); + return ((IAsyncOnMouseUpHandler)new AsyncTriggerHandler(this, true)).OnMouseUpAsync(); } public UniTask OnMouseUpAsync(CancellationToken cancellationToken) { - return ((IAsyncOnMouseUpHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnMouseUpAsync(); + return ((IAsyncOnMouseUpHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnMouseUpAsync(); } } #endregion @@ -1928,27 +1928,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnMouseUpAsButton() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncOnMouseUpAsButtonHandler GetOnMouseUpAsButtonAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnMouseUpAsButtonHandler GetOnMouseUpAsButtonAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnMouseUpAsButtonAsync() { - return ((IAsyncOnMouseUpAsButtonHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnMouseUpAsButtonAsync(); + return ((IAsyncOnMouseUpAsButtonHandler)new AsyncTriggerHandler(this, true)).OnMouseUpAsButtonAsync(); } public UniTask OnMouseUpAsButtonAsync(CancellationToken cancellationToken) { - return ((IAsyncOnMouseUpAsButtonHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnMouseUpAsButtonAsync(); + return ((IAsyncOnMouseUpAsButtonHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnMouseUpAsButtonAsync(); } } #endregion @@ -1987,27 +1987,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnParticleCollision(GameObject other) { - triggerEvent?.TrySetResult((other)); + RaiseEvent((other)); } public IAsyncOnParticleCollisionHandler GetOnParticleCollisionAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnParticleCollisionHandler GetOnParticleCollisionAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnParticleCollisionAsync() { - return ((IAsyncOnParticleCollisionHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnParticleCollisionAsync(); + return ((IAsyncOnParticleCollisionHandler)new AsyncTriggerHandler(this, true)).OnParticleCollisionAsync(); } public UniTask OnParticleCollisionAsync(CancellationToken cancellationToken) { - return ((IAsyncOnParticleCollisionHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnParticleCollisionAsync(); + return ((IAsyncOnParticleCollisionHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnParticleCollisionAsync(); } } #endregion @@ -2046,27 +2046,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnParticleSystemStopped() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncOnParticleSystemStoppedHandler GetOnParticleSystemStoppedAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnParticleSystemStoppedHandler GetOnParticleSystemStoppedAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnParticleSystemStoppedAsync() { - return ((IAsyncOnParticleSystemStoppedHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnParticleSystemStoppedAsync(); + return ((IAsyncOnParticleSystemStoppedHandler)new AsyncTriggerHandler(this, true)).OnParticleSystemStoppedAsync(); } public UniTask OnParticleSystemStoppedAsync(CancellationToken cancellationToken) { - return ((IAsyncOnParticleSystemStoppedHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnParticleSystemStoppedAsync(); + return ((IAsyncOnParticleSystemStoppedHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnParticleSystemStoppedAsync(); } } #endregion @@ -2105,27 +2105,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnParticleTrigger() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncOnParticleTriggerHandler GetOnParticleTriggerAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnParticleTriggerHandler GetOnParticleTriggerAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnParticleTriggerAsync() { - return ((IAsyncOnParticleTriggerHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnParticleTriggerAsync(); + return ((IAsyncOnParticleTriggerHandler)new AsyncTriggerHandler(this, true)).OnParticleTriggerAsync(); } public UniTask OnParticleTriggerAsync(CancellationToken cancellationToken) { - return ((IAsyncOnParticleTriggerHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnParticleTriggerAsync(); + return ((IAsyncOnParticleTriggerHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnParticleTriggerAsync(); } } #endregion @@ -2165,27 +2165,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnParticleUpdateJobScheduled(UnityEngine.ParticleSystemJobs.ParticleSystemJobData particles) { - triggerEvent?.TrySetResult((particles)); + RaiseEvent((particles)); } public IAsyncOnParticleUpdateJobScheduledHandler GetOnParticleUpdateJobScheduledAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnParticleUpdateJobScheduledHandler GetOnParticleUpdateJobScheduledAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnParticleUpdateJobScheduledAsync() { - return ((IAsyncOnParticleUpdateJobScheduledHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnParticleUpdateJobScheduledAsync(); + return ((IAsyncOnParticleUpdateJobScheduledHandler)new AsyncTriggerHandler(this, true)).OnParticleUpdateJobScheduledAsync(); } public UniTask OnParticleUpdateJobScheduledAsync(CancellationToken cancellationToken) { - return ((IAsyncOnParticleUpdateJobScheduledHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnParticleUpdateJobScheduledAsync(); + return ((IAsyncOnParticleUpdateJobScheduledHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnParticleUpdateJobScheduledAsync(); } } #endif @@ -2225,27 +2225,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnPostRender() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncOnPostRenderHandler GetOnPostRenderAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnPostRenderHandler GetOnPostRenderAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnPostRenderAsync() { - return ((IAsyncOnPostRenderHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnPostRenderAsync(); + return ((IAsyncOnPostRenderHandler)new AsyncTriggerHandler(this, true)).OnPostRenderAsync(); } public UniTask OnPostRenderAsync(CancellationToken cancellationToken) { - return ((IAsyncOnPostRenderHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnPostRenderAsync(); + return ((IAsyncOnPostRenderHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnPostRenderAsync(); } } #endregion @@ -2284,27 +2284,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnPreCull() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncOnPreCullHandler GetOnPreCullAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnPreCullHandler GetOnPreCullAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnPreCullAsync() { - return ((IAsyncOnPreCullHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnPreCullAsync(); + return ((IAsyncOnPreCullHandler)new AsyncTriggerHandler(this, true)).OnPreCullAsync(); } public UniTask OnPreCullAsync(CancellationToken cancellationToken) { - return ((IAsyncOnPreCullHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnPreCullAsync(); + return ((IAsyncOnPreCullHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnPreCullAsync(); } } #endregion @@ -2343,27 +2343,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnPreRender() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncOnPreRenderHandler GetOnPreRenderAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnPreRenderHandler GetOnPreRenderAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnPreRenderAsync() { - return ((IAsyncOnPreRenderHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnPreRenderAsync(); + return ((IAsyncOnPreRenderHandler)new AsyncTriggerHandler(this, true)).OnPreRenderAsync(); } public UniTask OnPreRenderAsync(CancellationToken cancellationToken) { - return ((IAsyncOnPreRenderHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnPreRenderAsync(); + return ((IAsyncOnPreRenderHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnPreRenderAsync(); } } #endregion @@ -2402,27 +2402,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnRectTransformDimensionsChange() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncOnRectTransformDimensionsChangeHandler GetOnRectTransformDimensionsChangeAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnRectTransformDimensionsChangeHandler GetOnRectTransformDimensionsChangeAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnRectTransformDimensionsChangeAsync() { - return ((IAsyncOnRectTransformDimensionsChangeHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnRectTransformDimensionsChangeAsync(); + return ((IAsyncOnRectTransformDimensionsChangeHandler)new AsyncTriggerHandler(this, true)).OnRectTransformDimensionsChangeAsync(); } public UniTask OnRectTransformDimensionsChangeAsync(CancellationToken cancellationToken) { - return ((IAsyncOnRectTransformDimensionsChangeHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnRectTransformDimensionsChangeAsync(); + return ((IAsyncOnRectTransformDimensionsChangeHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnRectTransformDimensionsChangeAsync(); } } #endregion @@ -2461,27 +2461,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnRectTransformRemoved() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncOnRectTransformRemovedHandler GetOnRectTransformRemovedAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnRectTransformRemovedHandler GetOnRectTransformRemovedAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnRectTransformRemovedAsync() { - return ((IAsyncOnRectTransformRemovedHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnRectTransformRemovedAsync(); + return ((IAsyncOnRectTransformRemovedHandler)new AsyncTriggerHandler(this, true)).OnRectTransformRemovedAsync(); } public UniTask OnRectTransformRemovedAsync(CancellationToken cancellationToken) { - return ((IAsyncOnRectTransformRemovedHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnRectTransformRemovedAsync(); + return ((IAsyncOnRectTransformRemovedHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnRectTransformRemovedAsync(); } } #endregion @@ -2520,27 +2520,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnRenderImage(RenderTexture source, RenderTexture destination) { - triggerEvent?.TrySetResult((source, destination)); + RaiseEvent((source, destination)); } public IAsyncOnRenderImageHandler GetOnRenderImageAsyncHandler() { - return new AsyncTriggerHandler<(RenderTexture source, RenderTexture destination)>(GetTriggerEvent(), false); + return new AsyncTriggerHandler<(RenderTexture source, RenderTexture destination)>(this, false); } public IAsyncOnRenderImageHandler GetOnRenderImageAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler<(RenderTexture source, RenderTexture destination)>(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler<(RenderTexture source, RenderTexture destination)>(this, cancellationToken, false); } public UniTask<(RenderTexture source, RenderTexture destination)> OnRenderImageAsync() { - return ((IAsyncOnRenderImageHandler)new AsyncTriggerHandler<(RenderTexture source, RenderTexture destination)>(GetTriggerEvent(), true)).OnRenderImageAsync(); + return ((IAsyncOnRenderImageHandler)new AsyncTriggerHandler<(RenderTexture source, RenderTexture destination)>(this, true)).OnRenderImageAsync(); } public UniTask<(RenderTexture source, RenderTexture destination)> OnRenderImageAsync(CancellationToken cancellationToken) { - return ((IAsyncOnRenderImageHandler)new AsyncTriggerHandler<(RenderTexture source, RenderTexture destination)>(GetTriggerEvent(), cancellationToken, true)).OnRenderImageAsync(); + return ((IAsyncOnRenderImageHandler)new AsyncTriggerHandler<(RenderTexture source, RenderTexture destination)>(this, cancellationToken, true)).OnRenderImageAsync(); } } #endregion @@ -2579,27 +2579,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnRenderObject() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncOnRenderObjectHandler GetOnRenderObjectAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnRenderObjectHandler GetOnRenderObjectAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnRenderObjectAsync() { - return ((IAsyncOnRenderObjectHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnRenderObjectAsync(); + return ((IAsyncOnRenderObjectHandler)new AsyncTriggerHandler(this, true)).OnRenderObjectAsync(); } public UniTask OnRenderObjectAsync(CancellationToken cancellationToken) { - return ((IAsyncOnRenderObjectHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnRenderObjectAsync(); + return ((IAsyncOnRenderObjectHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnRenderObjectAsync(); } } #endregion @@ -2638,27 +2638,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnServerInitialized() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncOnServerInitializedHandler GetOnServerInitializedAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnServerInitializedHandler GetOnServerInitializedAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnServerInitializedAsync() { - return ((IAsyncOnServerInitializedHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnServerInitializedAsync(); + return ((IAsyncOnServerInitializedHandler)new AsyncTriggerHandler(this, true)).OnServerInitializedAsync(); } public UniTask OnServerInitializedAsync(CancellationToken cancellationToken) { - return ((IAsyncOnServerInitializedHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnServerInitializedAsync(); + return ((IAsyncOnServerInitializedHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnServerInitializedAsync(); } } #endregion @@ -2697,27 +2697,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnTransformChildrenChanged() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncOnTransformChildrenChangedHandler GetOnTransformChildrenChangedAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnTransformChildrenChangedHandler GetOnTransformChildrenChangedAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnTransformChildrenChangedAsync() { - return ((IAsyncOnTransformChildrenChangedHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnTransformChildrenChangedAsync(); + return ((IAsyncOnTransformChildrenChangedHandler)new AsyncTriggerHandler(this, true)).OnTransformChildrenChangedAsync(); } public UniTask OnTransformChildrenChangedAsync(CancellationToken cancellationToken) { - return ((IAsyncOnTransformChildrenChangedHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnTransformChildrenChangedAsync(); + return ((IAsyncOnTransformChildrenChangedHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnTransformChildrenChangedAsync(); } } #endregion @@ -2756,27 +2756,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnTransformParentChanged() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncOnTransformParentChangedHandler GetOnTransformParentChangedAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnTransformParentChangedHandler GetOnTransformParentChangedAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnTransformParentChangedAsync() { - return ((IAsyncOnTransformParentChangedHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnTransformParentChangedAsync(); + return ((IAsyncOnTransformParentChangedHandler)new AsyncTriggerHandler(this, true)).OnTransformParentChangedAsync(); } public UniTask OnTransformParentChangedAsync(CancellationToken cancellationToken) { - return ((IAsyncOnTransformParentChangedHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnTransformParentChangedAsync(); + return ((IAsyncOnTransformParentChangedHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnTransformParentChangedAsync(); } } #endregion @@ -2815,27 +2815,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnTriggerEnter(Collider other) { - triggerEvent?.TrySetResult((other)); + RaiseEvent((other)); } public IAsyncOnTriggerEnterHandler GetOnTriggerEnterAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnTriggerEnterHandler GetOnTriggerEnterAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnTriggerEnterAsync() { - return ((IAsyncOnTriggerEnterHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnTriggerEnterAsync(); + return ((IAsyncOnTriggerEnterHandler)new AsyncTriggerHandler(this, true)).OnTriggerEnterAsync(); } public UniTask OnTriggerEnterAsync(CancellationToken cancellationToken) { - return ((IAsyncOnTriggerEnterHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnTriggerEnterAsync(); + return ((IAsyncOnTriggerEnterHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnTriggerEnterAsync(); } } #endregion @@ -2874,27 +2874,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnTriggerEnter2D(Collider2D other) { - triggerEvent?.TrySetResult((other)); + RaiseEvent((other)); } public IAsyncOnTriggerEnter2DHandler GetOnTriggerEnter2DAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnTriggerEnter2DHandler GetOnTriggerEnter2DAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnTriggerEnter2DAsync() { - return ((IAsyncOnTriggerEnter2DHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnTriggerEnter2DAsync(); + return ((IAsyncOnTriggerEnter2DHandler)new AsyncTriggerHandler(this, true)).OnTriggerEnter2DAsync(); } public UniTask OnTriggerEnter2DAsync(CancellationToken cancellationToken) { - return ((IAsyncOnTriggerEnter2DHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnTriggerEnter2DAsync(); + return ((IAsyncOnTriggerEnter2DHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnTriggerEnter2DAsync(); } } #endregion @@ -2933,27 +2933,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnTriggerExit(Collider other) { - triggerEvent?.TrySetResult((other)); + RaiseEvent((other)); } public IAsyncOnTriggerExitHandler GetOnTriggerExitAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnTriggerExitHandler GetOnTriggerExitAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnTriggerExitAsync() { - return ((IAsyncOnTriggerExitHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnTriggerExitAsync(); + return ((IAsyncOnTriggerExitHandler)new AsyncTriggerHandler(this, true)).OnTriggerExitAsync(); } public UniTask OnTriggerExitAsync(CancellationToken cancellationToken) { - return ((IAsyncOnTriggerExitHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnTriggerExitAsync(); + return ((IAsyncOnTriggerExitHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnTriggerExitAsync(); } } #endregion @@ -2992,27 +2992,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnTriggerExit2D(Collider2D other) { - triggerEvent?.TrySetResult((other)); + RaiseEvent((other)); } public IAsyncOnTriggerExit2DHandler GetOnTriggerExit2DAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnTriggerExit2DHandler GetOnTriggerExit2DAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnTriggerExit2DAsync() { - return ((IAsyncOnTriggerExit2DHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnTriggerExit2DAsync(); + return ((IAsyncOnTriggerExit2DHandler)new AsyncTriggerHandler(this, true)).OnTriggerExit2DAsync(); } public UniTask OnTriggerExit2DAsync(CancellationToken cancellationToken) { - return ((IAsyncOnTriggerExit2DHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnTriggerExit2DAsync(); + return ((IAsyncOnTriggerExit2DHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnTriggerExit2DAsync(); } } #endregion @@ -3051,27 +3051,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnTriggerStay(Collider other) { - triggerEvent?.TrySetResult((other)); + RaiseEvent((other)); } public IAsyncOnTriggerStayHandler GetOnTriggerStayAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnTriggerStayHandler GetOnTriggerStayAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnTriggerStayAsync() { - return ((IAsyncOnTriggerStayHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnTriggerStayAsync(); + return ((IAsyncOnTriggerStayHandler)new AsyncTriggerHandler(this, true)).OnTriggerStayAsync(); } public UniTask OnTriggerStayAsync(CancellationToken cancellationToken) { - return ((IAsyncOnTriggerStayHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnTriggerStayAsync(); + return ((IAsyncOnTriggerStayHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnTriggerStayAsync(); } } #endregion @@ -3110,27 +3110,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnTriggerStay2D(Collider2D other) { - triggerEvent?.TrySetResult((other)); + RaiseEvent((other)); } public IAsyncOnTriggerStay2DHandler GetOnTriggerStay2DAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnTriggerStay2DHandler GetOnTriggerStay2DAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnTriggerStay2DAsync() { - return ((IAsyncOnTriggerStay2DHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnTriggerStay2DAsync(); + return ((IAsyncOnTriggerStay2DHandler)new AsyncTriggerHandler(this, true)).OnTriggerStay2DAsync(); } public UniTask OnTriggerStay2DAsync(CancellationToken cancellationToken) { - return ((IAsyncOnTriggerStay2DHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnTriggerStay2DAsync(); + return ((IAsyncOnTriggerStay2DHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnTriggerStay2DAsync(); } } #endregion @@ -3169,27 +3169,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnValidate() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncOnValidateHandler GetOnValidateAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnValidateHandler GetOnValidateAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnValidateAsync() { - return ((IAsyncOnValidateHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnValidateAsync(); + return ((IAsyncOnValidateHandler)new AsyncTriggerHandler(this, true)).OnValidateAsync(); } public UniTask OnValidateAsync(CancellationToken cancellationToken) { - return ((IAsyncOnValidateHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnValidateAsync(); + return ((IAsyncOnValidateHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnValidateAsync(); } } #endregion @@ -3228,27 +3228,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void OnWillRenderObject() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncOnWillRenderObjectHandler GetOnWillRenderObjectAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnWillRenderObjectHandler GetOnWillRenderObjectAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnWillRenderObjectAsync() { - return ((IAsyncOnWillRenderObjectHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnWillRenderObjectAsync(); + return ((IAsyncOnWillRenderObjectHandler)new AsyncTriggerHandler(this, true)).OnWillRenderObjectAsync(); } public UniTask OnWillRenderObjectAsync(CancellationToken cancellationToken) { - return ((IAsyncOnWillRenderObjectHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnWillRenderObjectAsync(); + return ((IAsyncOnWillRenderObjectHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnWillRenderObjectAsync(); } } #endregion @@ -3287,27 +3287,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void Reset() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncResetHandler GetResetAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncResetHandler GetResetAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask ResetAsync() { - return ((IAsyncResetHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).ResetAsync(); + return ((IAsyncResetHandler)new AsyncTriggerHandler(this, true)).ResetAsync(); } public UniTask ResetAsync(CancellationToken cancellationToken) { - return ((IAsyncResetHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).ResetAsync(); + return ((IAsyncResetHandler)new AsyncTriggerHandler(this, cancellationToken, true)).ResetAsync(); } } #endregion @@ -3346,27 +3346,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void Update() { - triggerEvent?.TrySetResult(AsyncUnit.Default); + RaiseEvent(AsyncUnit.Default); } public IAsyncUpdateHandler GetUpdateAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncUpdateHandler GetUpdateAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask UpdateAsync() { - return ((IAsyncUpdateHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).UpdateAsync(); + return ((IAsyncUpdateHandler)new AsyncTriggerHandler(this, true)).UpdateAsync(); } public UniTask UpdateAsync(CancellationToken cancellationToken) { - return ((IAsyncUpdateHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).UpdateAsync(); + return ((IAsyncUpdateHandler)new AsyncTriggerHandler(this, cancellationToken, true)).UpdateAsync(); } } #endregion @@ -3405,27 +3405,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void IBeginDragHandler.OnBeginDrag(PointerEventData eventData) { - triggerEvent?.TrySetResult((eventData)); + RaiseEvent((eventData)); } public IAsyncOnBeginDragHandler GetOnBeginDragAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnBeginDragHandler GetOnBeginDragAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnBeginDragAsync() { - return ((IAsyncOnBeginDragHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnBeginDragAsync(); + return ((IAsyncOnBeginDragHandler)new AsyncTriggerHandler(this, true)).OnBeginDragAsync(); } public UniTask OnBeginDragAsync(CancellationToken cancellationToken) { - return ((IAsyncOnBeginDragHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnBeginDragAsync(); + return ((IAsyncOnBeginDragHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnBeginDragAsync(); } } #endregion @@ -3464,27 +3464,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void ICancelHandler.OnCancel(BaseEventData eventData) { - triggerEvent?.TrySetResult((eventData)); + RaiseEvent((eventData)); } public IAsyncOnCancelHandler GetOnCancelAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnCancelHandler GetOnCancelAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnCancelAsync() { - return ((IAsyncOnCancelHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnCancelAsync(); + return ((IAsyncOnCancelHandler)new AsyncTriggerHandler(this, true)).OnCancelAsync(); } public UniTask OnCancelAsync(CancellationToken cancellationToken) { - return ((IAsyncOnCancelHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnCancelAsync(); + return ((IAsyncOnCancelHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnCancelAsync(); } } #endregion @@ -3523,27 +3523,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void IDeselectHandler.OnDeselect(BaseEventData eventData) { - triggerEvent?.TrySetResult((eventData)); + RaiseEvent((eventData)); } public IAsyncOnDeselectHandler GetOnDeselectAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnDeselectHandler GetOnDeselectAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnDeselectAsync() { - return ((IAsyncOnDeselectHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnDeselectAsync(); + return ((IAsyncOnDeselectHandler)new AsyncTriggerHandler(this, true)).OnDeselectAsync(); } public UniTask OnDeselectAsync(CancellationToken cancellationToken) { - return ((IAsyncOnDeselectHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnDeselectAsync(); + return ((IAsyncOnDeselectHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnDeselectAsync(); } } #endregion @@ -3582,27 +3582,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void IDragHandler.OnDrag(PointerEventData eventData) { - triggerEvent?.TrySetResult((eventData)); + RaiseEvent((eventData)); } public IAsyncOnDragHandler GetOnDragAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnDragHandler GetOnDragAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnDragAsync() { - return ((IAsyncOnDragHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnDragAsync(); + return ((IAsyncOnDragHandler)new AsyncTriggerHandler(this, true)).OnDragAsync(); } public UniTask OnDragAsync(CancellationToken cancellationToken) { - return ((IAsyncOnDragHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnDragAsync(); + return ((IAsyncOnDragHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnDragAsync(); } } #endregion @@ -3641,27 +3641,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void IDropHandler.OnDrop(PointerEventData eventData) { - triggerEvent?.TrySetResult((eventData)); + RaiseEvent((eventData)); } public IAsyncOnDropHandler GetOnDropAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnDropHandler GetOnDropAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnDropAsync() { - return ((IAsyncOnDropHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnDropAsync(); + return ((IAsyncOnDropHandler)new AsyncTriggerHandler(this, true)).OnDropAsync(); } public UniTask OnDropAsync(CancellationToken cancellationToken) { - return ((IAsyncOnDropHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnDropAsync(); + return ((IAsyncOnDropHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnDropAsync(); } } #endregion @@ -3700,27 +3700,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void IEndDragHandler.OnEndDrag(PointerEventData eventData) { - triggerEvent?.TrySetResult((eventData)); + RaiseEvent((eventData)); } public IAsyncOnEndDragHandler GetOnEndDragAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnEndDragHandler GetOnEndDragAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnEndDragAsync() { - return ((IAsyncOnEndDragHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnEndDragAsync(); + return ((IAsyncOnEndDragHandler)new AsyncTriggerHandler(this, true)).OnEndDragAsync(); } public UniTask OnEndDragAsync(CancellationToken cancellationToken) { - return ((IAsyncOnEndDragHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnEndDragAsync(); + return ((IAsyncOnEndDragHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnEndDragAsync(); } } #endregion @@ -3759,27 +3759,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void IInitializePotentialDragHandler.OnInitializePotentialDrag(PointerEventData eventData) { - triggerEvent?.TrySetResult((eventData)); + RaiseEvent((eventData)); } public IAsyncOnInitializePotentialDragHandler GetOnInitializePotentialDragAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnInitializePotentialDragHandler GetOnInitializePotentialDragAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnInitializePotentialDragAsync() { - return ((IAsyncOnInitializePotentialDragHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnInitializePotentialDragAsync(); + return ((IAsyncOnInitializePotentialDragHandler)new AsyncTriggerHandler(this, true)).OnInitializePotentialDragAsync(); } public UniTask OnInitializePotentialDragAsync(CancellationToken cancellationToken) { - return ((IAsyncOnInitializePotentialDragHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnInitializePotentialDragAsync(); + return ((IAsyncOnInitializePotentialDragHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnInitializePotentialDragAsync(); } } #endregion @@ -3818,27 +3818,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void IMoveHandler.OnMove(AxisEventData eventData) { - triggerEvent?.TrySetResult((eventData)); + RaiseEvent((eventData)); } public IAsyncOnMoveHandler GetOnMoveAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnMoveHandler GetOnMoveAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnMoveAsync() { - return ((IAsyncOnMoveHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnMoveAsync(); + return ((IAsyncOnMoveHandler)new AsyncTriggerHandler(this, true)).OnMoveAsync(); } public UniTask OnMoveAsync(CancellationToken cancellationToken) { - return ((IAsyncOnMoveHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnMoveAsync(); + return ((IAsyncOnMoveHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnMoveAsync(); } } #endregion @@ -3877,27 +3877,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void IPointerClickHandler.OnPointerClick(PointerEventData eventData) { - triggerEvent?.TrySetResult((eventData)); + RaiseEvent((eventData)); } public IAsyncOnPointerClickHandler GetOnPointerClickAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnPointerClickHandler GetOnPointerClickAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnPointerClickAsync() { - return ((IAsyncOnPointerClickHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnPointerClickAsync(); + return ((IAsyncOnPointerClickHandler)new AsyncTriggerHandler(this, true)).OnPointerClickAsync(); } public UniTask OnPointerClickAsync(CancellationToken cancellationToken) { - return ((IAsyncOnPointerClickHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnPointerClickAsync(); + return ((IAsyncOnPointerClickHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnPointerClickAsync(); } } #endregion @@ -3936,27 +3936,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void IPointerDownHandler.OnPointerDown(PointerEventData eventData) { - triggerEvent?.TrySetResult((eventData)); + RaiseEvent((eventData)); } public IAsyncOnPointerDownHandler GetOnPointerDownAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnPointerDownHandler GetOnPointerDownAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnPointerDownAsync() { - return ((IAsyncOnPointerDownHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnPointerDownAsync(); + return ((IAsyncOnPointerDownHandler)new AsyncTriggerHandler(this, true)).OnPointerDownAsync(); } public UniTask OnPointerDownAsync(CancellationToken cancellationToken) { - return ((IAsyncOnPointerDownHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnPointerDownAsync(); + return ((IAsyncOnPointerDownHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnPointerDownAsync(); } } #endregion @@ -3995,27 +3995,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData) { - triggerEvent?.TrySetResult((eventData)); + RaiseEvent((eventData)); } public IAsyncOnPointerEnterHandler GetOnPointerEnterAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnPointerEnterHandler GetOnPointerEnterAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnPointerEnterAsync() { - return ((IAsyncOnPointerEnterHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnPointerEnterAsync(); + return ((IAsyncOnPointerEnterHandler)new AsyncTriggerHandler(this, true)).OnPointerEnterAsync(); } public UniTask OnPointerEnterAsync(CancellationToken cancellationToken) { - return ((IAsyncOnPointerEnterHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnPointerEnterAsync(); + return ((IAsyncOnPointerEnterHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnPointerEnterAsync(); } } #endregion @@ -4054,27 +4054,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void IPointerExitHandler.OnPointerExit(PointerEventData eventData) { - triggerEvent?.TrySetResult((eventData)); + RaiseEvent((eventData)); } public IAsyncOnPointerExitHandler GetOnPointerExitAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnPointerExitHandler GetOnPointerExitAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnPointerExitAsync() { - return ((IAsyncOnPointerExitHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnPointerExitAsync(); + return ((IAsyncOnPointerExitHandler)new AsyncTriggerHandler(this, true)).OnPointerExitAsync(); } public UniTask OnPointerExitAsync(CancellationToken cancellationToken) { - return ((IAsyncOnPointerExitHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnPointerExitAsync(); + return ((IAsyncOnPointerExitHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnPointerExitAsync(); } } #endregion @@ -4113,27 +4113,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void IPointerUpHandler.OnPointerUp(PointerEventData eventData) { - triggerEvent?.TrySetResult((eventData)); + RaiseEvent((eventData)); } public IAsyncOnPointerUpHandler GetOnPointerUpAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnPointerUpHandler GetOnPointerUpAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnPointerUpAsync() { - return ((IAsyncOnPointerUpHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnPointerUpAsync(); + return ((IAsyncOnPointerUpHandler)new AsyncTriggerHandler(this, true)).OnPointerUpAsync(); } public UniTask OnPointerUpAsync(CancellationToken cancellationToken) { - return ((IAsyncOnPointerUpHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnPointerUpAsync(); + return ((IAsyncOnPointerUpHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnPointerUpAsync(); } } #endregion @@ -4172,27 +4172,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void IScrollHandler.OnScroll(PointerEventData eventData) { - triggerEvent?.TrySetResult((eventData)); + RaiseEvent((eventData)); } public IAsyncOnScrollHandler GetOnScrollAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnScrollHandler GetOnScrollAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnScrollAsync() { - return ((IAsyncOnScrollHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnScrollAsync(); + return ((IAsyncOnScrollHandler)new AsyncTriggerHandler(this, true)).OnScrollAsync(); } public UniTask OnScrollAsync(CancellationToken cancellationToken) { - return ((IAsyncOnScrollHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnScrollAsync(); + return ((IAsyncOnScrollHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnScrollAsync(); } } #endregion @@ -4231,27 +4231,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void ISelectHandler.OnSelect(BaseEventData eventData) { - triggerEvent?.TrySetResult((eventData)); + RaiseEvent((eventData)); } public IAsyncOnSelectHandler GetOnSelectAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnSelectHandler GetOnSelectAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnSelectAsync() { - return ((IAsyncOnSelectHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnSelectAsync(); + return ((IAsyncOnSelectHandler)new AsyncTriggerHandler(this, true)).OnSelectAsync(); } public UniTask OnSelectAsync(CancellationToken cancellationToken) { - return ((IAsyncOnSelectHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnSelectAsync(); + return ((IAsyncOnSelectHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnSelectAsync(); } } #endregion @@ -4290,27 +4290,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void ISubmitHandler.OnSubmit(BaseEventData eventData) { - triggerEvent?.TrySetResult((eventData)); + RaiseEvent((eventData)); } public IAsyncOnSubmitHandler GetOnSubmitAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnSubmitHandler GetOnSubmitAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnSubmitAsync() { - return ((IAsyncOnSubmitHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnSubmitAsync(); + return ((IAsyncOnSubmitHandler)new AsyncTriggerHandler(this, true)).OnSubmitAsync(); } public UniTask OnSubmitAsync(CancellationToken cancellationToken) { - return ((IAsyncOnSubmitHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnSubmitAsync(); + return ((IAsyncOnSubmitHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnSubmitAsync(); } } #endregion @@ -4349,27 +4349,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void IUpdateSelectedHandler.OnUpdateSelected(BaseEventData eventData) { - triggerEvent?.TrySetResult((eventData)); + RaiseEvent((eventData)); } public IAsyncOnUpdateSelectedHandler GetOnUpdateSelectedAsyncHandler() { - return new AsyncTriggerHandler(GetTriggerEvent(), false); + return new AsyncTriggerHandler(this, false); } public IAsyncOnUpdateSelectedHandler GetOnUpdateSelectedAsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler(this, cancellationToken, false); } public UniTask OnUpdateSelectedAsync() { - return ((IAsyncOnUpdateSelectedHandler)new AsyncTriggerHandler(GetTriggerEvent(), true)).OnUpdateSelectedAsync(); + return ((IAsyncOnUpdateSelectedHandler)new AsyncTriggerHandler(this, true)).OnUpdateSelectedAsync(); } public UniTask OnUpdateSelectedAsync(CancellationToken cancellationToken) { - return ((IAsyncOnUpdateSelectedHandler)new AsyncTriggerHandler(GetTriggerEvent(), cancellationToken, true)).OnUpdateSelectedAsync(); + return ((IAsyncOnUpdateSelectedHandler)new AsyncTriggerHandler(this, cancellationToken, true)).OnUpdateSelectedAsync(); } } #endregion diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/Triggers/MonoBehaviourMessagesTriggers.tt b/src/UniTask/Assets/Plugins/UniTask/Runtime/Triggers/MonoBehaviourMessagesTriggers.tt index 5d8de56..ce86b6f 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/Triggers/MonoBehaviourMessagesTriggers.tt +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/Triggers/MonoBehaviourMessagesTriggers.tt @@ -151,27 +151,27 @@ namespace Cysharp.Threading.Tasks.Triggers { void <#= (t.handlerInterface == null) ? "" : $"{t.handlerInterface}." #><#= t.methodName #>(<#= BuildMethodArgument(t.arguments) #>) { - triggerEvent?.TrySetResult(<#= BuildResultParameter(t.arguments) #>); + RaiseEvent(<#= BuildResultParameter(t.arguments) #>); } public <#= ToInterfaceName(t.methodName) #> Get<#= t.methodName #>AsyncHandler() { - return new AsyncTriggerHandler<<#= t.returnType #>>(GetTriggerEvent(), false); + return new AsyncTriggerHandler<<#= t.returnType #>>(this, false); } public <#= ToInterfaceName(t.methodName) #> Get<#= t.methodName #>AsyncHandler(CancellationToken cancellationToken) { - return new AsyncTriggerHandler<<#= t.returnType #>>(GetTriggerEvent(), cancellationToken, false); + return new AsyncTriggerHandler<<#= t.returnType #>>(this, cancellationToken, false); } public <#= ToUniTaskName(t.returnType) #> <#= t.methodName #>Async() { - return ((<#= ToInterfaceName(t.methodName) #>)new AsyncTriggerHandler<<#= t.returnType #>>(GetTriggerEvent(), true)).<#= t.methodName #>Async(); + return ((<#= ToInterfaceName(t.methodName) #>)new AsyncTriggerHandler<<#= t.returnType #>>(this, true)).<#= t.methodName #>Async(); } public <#= ToUniTaskName(t.returnType) #> <#= t.methodName #>Async(CancellationToken cancellationToken) { - return ((<#= ToInterfaceName(t.methodName) #>)new AsyncTriggerHandler<<#= t.returnType #>>(GetTriggerEvent(), cancellationToken, true)).<#= t.methodName #>Async(); + return ((<#= ToInterfaceName(t.methodName) #>)new AsyncTriggerHandler<<#= t.returnType #>>(this, cancellationToken, true)).<#= t.methodName #>Async(); } } <# if(Is2019_3(t.triggerName)) { #> diff --git a/src/UniTask/Assets/Scenes/SandboxMain.cs b/src/UniTask/Assets/Scenes/SandboxMain.cs index 38cd346..31d7740 100644 --- a/src/UniTask/Assets/Scenes/SandboxMain.cs +++ b/src/UniTask/Assets/Scenes/SandboxMain.cs @@ -37,6 +37,200 @@ public enum MyEnum A, B, C } + + +public interface IAsyncReadOnlyReactiveProperty : IUniTaskAsyncEnumerable +{ + T Value { get; } +} + + +public interface IAsyncReactiveProperty : IAsyncReadOnlyReactiveProperty +{ + new T Value { get; set; } +} + + +[Serializable] +public struct AsyncValueReactiveProperty : IUniTaskAsyncEnumerable +{ + TriggerEvent triggerEvent; + + [SerializeField] + T latestValue; + + public T Value + { + get + { + return latestValue; + } + set + { + this.latestValue = value; + triggerEvent.TrySetResult(value); + } + } + + public AsyncValueReactiveProperty(T value) + { + this.latestValue = value; + this.triggerEvent = default; + } + + public IUniTaskAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken) + { + return new Enumerator(triggerEvent, cancellationToken); + } + + public class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator, IResolveCancelPromise + { + static Action cancellationCallback = CancellationCallback; + + readonly TriggerEvent triggerEvent; + readonly CancellationToken cancellationToken; + readonly CancellationTokenRegistration cancellationTokenRegistration; + T value; + + public Enumerator(TriggerEvent triggerEvent, CancellationToken cancellationToken) + { + this.triggerEvent = triggerEvent; + this.cancellationToken = cancellationToken; + + triggerEvent.Add(this); + + if (cancellationToken.CanBeCanceled) + { + cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(cancellationCallback, this); + } + } + + public T Current => value; + + public UniTask MoveNextAsync() + { + completionSource.Reset(); + return new UniTask(this, completionSource.Version); + } + + public UniTask DisposeAsync() + { + triggerEvent.TrySetCanceled(cancellationToken); + triggerEvent.Remove(this); + return default; + } + + public bool TrySetResult(T value) + { + this.value = value; + return triggerEvent.TrySetResult(value); + } + + public bool TrySetCanceled(CancellationToken cancellationToken = default) + { + DisposeAsync().Forget(); + return true; + } + + static void CancellationCallback(object state) + { + var self = (Enumerator)state; + self.DisposeAsync().Forget(); + } + } +} + + +public static partial class UnityUIComponentExtensions +{ + public static void BindTo(this IUniTaskAsyncEnumerable source, Text text, bool rebindOnError = true) + { + BindToCore(source, text, text.GetCancellationTokenOnDestroy(), rebindOnError).Forget(); + } + + public static void BindTo(this IUniTaskAsyncEnumerable source, Text text, CancellationToken cancellationToken, bool rebindOnError = true) + { + BindToCore(source, text, cancellationToken, rebindOnError).Forget(); + } + + static async UniTaskVoid BindToCore(IUniTaskAsyncEnumerable source, Text text, CancellationToken cancellationToken, bool rebindOnError) + { + var repeat = false; + BIND_AGAIN: + var e = source.GetAsyncEnumerator(cancellationToken); + try + { + while (true) + { + bool moveNext; + try + { + moveNext = await e.MoveNextAsync(); + repeat = false; + } + catch (Exception ex) + { + if (ex is OperationCanceledException) return; + + if (rebindOnError && !repeat) + { + repeat = true; + if (e != null) + { + await e.DisposeAsync(); + } + + goto BIND_AGAIN; + } + else + { + throw; + } + } + + if (!moveNext) return; + + text.text = e.Current; + } + } + finally + { + if (e != null) + { + await e.DisposeAsync(); + } + } + } + + //public static IDisposable SubscribeToText(this IObservable source, Text text) + //{ + // return source.SubscribeWithState(text, (x, t) => t.text = x.ToString()); + //} + + //public static IDisposable SubscribeToText(this IObservable source, Text text, Func selector) + //{ + // return source.SubscribeWithState2(text, selector, (x, t, s) => t.text = s(x)); + //} + + //public static IDisposable SubscribeToInteractable(this IObservable source, Selectable selectable) + //{ + // return source.SubscribeWithState(selectable, (x, s) => s.interactable = x); + //} +} + + +public static class MyClass +{ + +} + + + + + + + + public class SandboxMain : MonoBehaviour { public Button okButton; @@ -148,16 +342,27 @@ public class SandboxMain : MonoBehaviour // UniTaskAsyncEnumerable.EveryUpdate(PlayerLoopTiming.FixedUpdate) - await UniTask.Yield(PlayerLoopTiming.Update); - Debug.Log("Start:" + Time.frameCount); + this.GetAsyncUpdateTrigger().ForEachAsync(_ => + { + UnityEngine.Debug.Log("Update Trigger 1"); + }).Forget(); - await UniTaskAsyncEnumerable.TimerFrame(3, 5, PlayerLoopTiming.PostLateUpdate) - .Select(x => x) - .Do(x => Debug.Log("DODODO")) - .ForEachAsync(_ => - { - Debug.Log("Call:" + Time.frameCount); - }, cancellationToken: this.GetCancellationTokenOnDestroy()); + + this.GetAsyncUpdateTrigger().ForEachAsync(_ => + { + UnityEngine.Debug.Log("Update Trigger 2"); + }).Forget(); + + //await UniTask.Yield(PlayerLoopTiming.Update); + //Debug.Log("Start:" + Time.frameCount); + + //await UniTaskAsyncEnumerable.TimerFrame(3, 5, PlayerLoopTiming.PostLateUpdate) + // .Select(x => x) + // .Do(x => Debug.Log("DODODO")) + // .ForEachAsync(_ => + // { + // Debug.Log("Call:" + Time.frameCount); + // }, cancellationToken: this.GetCancellationTokenOnDestroy()); //try //{