diff --git a/Assets/Tests/AsyncTest.cs b/Assets/Tests/AsyncTest.cs index 248ebad..12546a8 100644 --- a/Assets/Tests/AsyncTest.cs +++ b/Assets/Tests/AsyncTest.cs @@ -101,12 +101,12 @@ namespace UniRx.AsyncTests { var a = UniTask.FromResult(999); var b = UniTask.Yield(PlayerLoopTiming.Update, CancellationToken.None).AsAsyncUnitUniTask(); - var c = UniTask.DelayFrame(99); + var c = UniTask.DelayFrame(99).AsAsyncUnitUniTask(); var (a2, b2, c2) = await UniTask.WhenAll(a, b, c); a2.Should().Be(999); b2.Should().Be(AsyncUnit.Default); - c2.Should().Be(99); + c2.Should().Be(AsyncUnit.Default); }); [UnityTest] @@ -114,14 +114,11 @@ namespace UniRx.AsyncTests { var a = UniTask.FromResult(999); var b = UniTask.Yield(PlayerLoopTiming.Update, CancellationToken.None).AsAsyncUnitUniTask(); - var c = UniTask.DelayFrame(99); + var c = UniTask.DelayFrame(99).AsAsyncUnitUniTask(); var (win, a2, b2, c2) = await UniTask.WhenAny(a, b, c); win.Should().Be(0); - a2.hasResult.Should().Be(true); - a2.result0.Should().Be(999); - b2.hasResult.Should().Be(false); - c2.hasResult.Should().Be(false); + a2.Should().Be(999); }); [UnityTest] @@ -151,7 +148,7 @@ namespace UniRx.AsyncTests { bool t = false; - UniTask.DelayFrame(10, PlayerLoopTiming.PostLateUpdate).ContinueWith(_ => t = true).Forget(); + UniTask.DelayFrame(10, PlayerLoopTiming.PostLateUpdate).ContinueWith(() => t = true).Forget(); var startFrame = Time.frameCount; await UniTask.WaitUntil(() => t, PlayerLoopTiming.EarlyUpdate); @@ -165,7 +162,7 @@ namespace UniRx.AsyncTests { bool t = true; - UniTask.DelayFrame(10, PlayerLoopTiming.PostLateUpdate).ContinueWith(_ => t = false).Forget(); + UniTask.DelayFrame(10, PlayerLoopTiming.PostLateUpdate).ContinueWith(() => t = false).Forget(); var startFrame = Time.frameCount; await UniTask.WaitWhile(() => t, PlayerLoopTiming.EarlyUpdate); @@ -179,7 +176,7 @@ namespace UniRx.AsyncTests { var v = new MyMyClass { MyProperty = 99 }; - UniTask.DelayFrame(10, PlayerLoopTiming.PostLateUpdate).ContinueWith(_ => v.MyProperty = 1000).Forget(); + UniTask.DelayFrame(10, PlayerLoopTiming.PostLateUpdate).ContinueWith(() => v.MyProperty = 1000).Forget(); var startFrame = Time.frameCount; await UniTask.WaitUntilValueChanged(v, x => x.MyProperty, PlayerLoopTiming.EarlyUpdate); @@ -269,10 +266,10 @@ namespace UniRx.AsyncTests { var cts = new CancellationTokenSource(); - UniTask.DelayFrame(10).ContinueWith(_ => cts.Cancel()).Forget(); + UniTask.DelayFrame(10).ContinueWith(() => cts.Cancel()).Forget(); var first = Time.frameCount; - var (canceled, value) = await UniTask.DelayFrame(100, cancellationToken: cts.Token).SuppressCancellationThrow(); + var canceled = await UniTask.DelayFrame(100, cancellationToken: cts.Token).SuppressCancellationThrow(); (Time.frameCount - first).Should().Be(11); // 10 frame canceled canceled.Should().Be(true); @@ -283,12 +280,12 @@ namespace UniRx.AsyncTests { var cts = new CancellationTokenSource(); - UniTask.DelayFrame(10).ContinueWith(_ => cts.Cancel()).Forget(); + UniTask.DelayFrame(10).ContinueWith(() => cts.Cancel()).Forget(); bool occur = false; try { - var value = await UniTask.DelayFrame(100, cancellationToken: cts.Token); + await UniTask.DelayFrame(100, cancellationToken: cts.Token); } catch (OperationCanceledException) { @@ -407,7 +404,7 @@ namespace UniRx.AsyncTests completedTaskObserver.OnCompletedCalled.Should().BeTrue(); completedTaskObserver.OnErrorCalled.Should().BeFalse(); - var delayFrameTaskObserver = new ToObservableObserver(); + var delayFrameTaskObserver = new ToObservableObserver(); UniTask.DelayFrame(1).ToObservable().Subscribe(delayFrameTaskObserver); delayFrameTaskObserver.OnNextCalled.Should().BeFalse(); delayFrameTaskObserver.OnCompletedCalled.Should().BeFalse(); diff --git a/Assets/Tests/Editor/AsyncTestEditor.cs b/Assets/Tests/Editor/AsyncTestEditor.cs index a86271f..69720f4 100644 --- a/Assets/Tests/Editor/AsyncTestEditor.cs +++ b/Assets/Tests/Editor/AsyncTestEditor.cs @@ -101,12 +101,12 @@ namespace UniRx.AsyncTests { var a = UniTask.FromResult(999); var b = UniTask.Yield(PlayerLoopTiming.Update, CancellationToken.None).AsAsyncUnitUniTask(); - var c = UniTask.DelayFrame(99); + var c = UniTask.DelayFrame(99).AsAsyncUnitUniTask(); var (a2, b2, c2) = await UniTask.WhenAll(a, b, c); a2.Should().Be(999); b2.Should().Be(AsyncUnit.Default); - c2.Should().Be(99); + c2.Should().Be(AsyncUnit.Default); }); [UnityTest] @@ -114,14 +114,11 @@ namespace UniRx.AsyncTests { var a = UniTask.FromResult(999); var b = UniTask.Yield(PlayerLoopTiming.Update, CancellationToken.None).AsAsyncUnitUniTask(); - var c = UniTask.DelayFrame(99); + var c = UniTask.DelayFrame(99).AsAsyncUnitUniTask(); var (win, a2, b2, c2) = await UniTask.WhenAny(a, b, c); win.Should().Be(0); - a2.hasResult.Should().Be(true); - a2.result0.Should().Be(999); - b2.hasResult.Should().Be(false); - c2.hasResult.Should().Be(false); + a2.Should().Be(999); }); [UnityTest] @@ -153,7 +150,7 @@ namespace UniRx.AsyncTests await UniTask.Yield(PlayerLoopTiming.PostLateUpdate); - UniTask.DelayFrame(10,PlayerLoopTiming.PostLateUpdate).ContinueWith(_ => t = true).Forget(); + UniTask.DelayFrame(10,PlayerLoopTiming.PostLateUpdate).ContinueWith(() => t = true).Forget(); var startFrame = Time.frameCount; await UniTask.WaitUntil(() => t, PlayerLoopTiming.EarlyUpdate); @@ -167,7 +164,7 @@ namespace UniRx.AsyncTests { bool t = true; - UniTask.DelayFrame(10, PlayerLoopTiming.PostLateUpdate).ContinueWith(_ => t = false).Forget(); + UniTask.DelayFrame(10, PlayerLoopTiming.PostLateUpdate).ContinueWith(() => t = false).Forget(); var startFrame = Time.frameCount; await UniTask.WaitWhile(() => t, PlayerLoopTiming.EarlyUpdate); @@ -181,7 +178,7 @@ namespace UniRx.AsyncTests { var v = new MyMyClass { MyProperty = 99 }; - UniTask.DelayFrame(10, PlayerLoopTiming.PostLateUpdate).ContinueWith(_ => v.MyProperty = 1000).Forget(); + UniTask.DelayFrame(10, PlayerLoopTiming.PostLateUpdate).ContinueWith(() => v.MyProperty = 1000).Forget(); var startFrame = Time.frameCount; await UniTask.WaitUntilValueChanged(v, x => x.MyProperty, PlayerLoopTiming.EarlyUpdate); @@ -271,10 +268,10 @@ namespace UniRx.AsyncTests { var cts = new CancellationTokenSource(); - UniTask.DelayFrame(10).ContinueWith(_ => cts.Cancel()).Forget(); + UniTask.DelayFrame(10).ContinueWith(() => cts.Cancel()).Forget(); var first = Time.frameCount; - var (canceled, value) = await UniTask.DelayFrame(100, cancellationToken: cts.Token).SuppressCancellationThrow(); + var canceled = await UniTask.DelayFrame(100, cancellationToken: cts.Token).SuppressCancellationThrow(); (Time.frameCount - first).Should().Be(11); // 10 frame canceled canceled.Should().Be(true); @@ -285,12 +282,12 @@ namespace UniRx.AsyncTests { var cts = new CancellationTokenSource(); - UniTask.DelayFrame(10).ContinueWith(_ => cts.Cancel()).Forget(); + UniTask.DelayFrame(10).ContinueWith(() => cts.Cancel()).Forget(); bool occur = false; try { - var value = await UniTask.DelayFrame(100, cancellationToken: cts.Token); + await UniTask.DelayFrame(100, cancellationToken: cts.Token); } catch (OperationCanceledException) { diff --git a/Assets/UniRx.Async/CancellationTokenSourceExtensions.cs b/Assets/UniRx.Async/CancellationTokenSourceExtensions.cs index 96cc03b..4b943b0 100644 --- a/Assets/UniRx.Async/CancellationTokenSourceExtensions.cs +++ b/Assets/UniRx.Async/CancellationTokenSourceExtensions.cs @@ -40,7 +40,11 @@ namespace UniRx.Async public static void RegisterRaiseCancelOnDestroy(this CancellationTokenSource cts, GameObject gameObject) { var trigger = gameObject.GetAsyncDestroyTrigger(); - trigger.AddCancellationTriggerOnDestroy(cts); + trigger.CancellationToken.RegisterWithoutCaptureExecutionContext(state => + { + var cts2 = (CancellationTokenSource)state; + cts2.Cancel(); + }, cts); } } } diff --git a/Assets/UniRx.Async/Editor/UniTaskTrackerTreeView.cs b/Assets/UniRx.Async/Editor/UniTaskTrackerTreeView.cs index 7e5e3cd..661b4c0 100644 --- a/Assets/UniRx.Async/Editor/UniTaskTrackerTreeView.cs +++ b/Assets/UniRx.Async/Editor/UniTaskTrackerTreeView.cs @@ -132,7 +132,7 @@ namespace UniRx.Async.Editor var children = new List(); - TaskTracker2.ForEachActiveTask((trackingId, awaiterType, status, created, stackTrace) => + TaskTracker.ForEachActiveTask((trackingId, awaiterType, status, created, stackTrace) => { children.Add(new UniTaskTrackerViewItem(trackingId) { TaskType = awaiterType, Status = status.ToString(), Elapsed = (DateTime.UtcNow - created).TotalSeconds.ToString("00.00"), Position = stackTrace }); }); diff --git a/Assets/UniRx.Async/Editor/UniTaskTrackerWindow.cs b/Assets/UniRx.Async/Editor/UniTaskTrackerWindow.cs index f35e1f8..9f5447e 100644 --- a/Assets/UniRx.Async/Editor/UniTaskTrackerWindow.cs +++ b/Assets/UniRx.Async/Editor/UniTaskTrackerWindow.cs @@ -12,7 +12,6 @@ using UniRx.Async.Internal; namespace UniRx.Async.Editor { - // TODO:Remove public class UniTaskTrackerWindow : EditorWindow { static int interval; @@ -171,202 +170,6 @@ namespace UniRx.Async.Editor static GUIStyle detailsStyle; Vector2 detailsScroll; - void RenderDetailsPanel() - { - if (detailsStyle == null) - { - detailsStyle = new GUIStyle(EditorStyles.wordWrappedLabel); - detailsStyle.wordWrap = false; - detailsStyle.stretchHeight = true; - detailsStyle.margin.right = 15; - } - - string message = ""; - var selected = treeView.state.selectedIDs; - if (selected.Count > 0) - { - var first = selected[0]; - var item = treeView.CurrentBindingItems.FirstOrDefault(x => x.id == first) as UniTaskTrackerViewItem; - if (item != null) - { - message = item.Position; - } - } - - detailsScroll = EditorGUILayout.BeginScrollView(this.detailsScroll, EmptyLayoutOption); - var vector = detailsStyle.CalcSize(new GUIContent(message)); - EditorGUILayout.SelectableLabel(message, detailsStyle, new GUILayoutOption[] - { - GUILayout.ExpandHeight(true), - GUILayout.ExpandWidth(true), - GUILayout.MinWidth(vector.x), - GUILayout.MinHeight(vector.y) - }); - EditorGUILayout.EndScrollView(); - } - - #endregion - } - - public class UniTaskTrackerWindow2 : EditorWindow - { - static int interval; - - static UniTaskTrackerWindow2 window; - - // TODO:Remove 2 - [MenuItem("Window/UniTask Tracker 2")] - public static void OpenWindow() - { - if (window != null) - { - window.Close(); - } - - // will called OnEnable(singleton instance will be set). - GetWindow("UniTask Tracker").Show(); - } - - static readonly GUILayoutOption[] EmptyLayoutOption = new GUILayoutOption[0]; - - UniTaskTrackerTreeView treeView; - object splitterState; - - void OnEnable() - { - window = this; // set singleton. - splitterState = SplitterGUILayout.CreateSplitterState(new float[] { 75f, 25f }, new int[] { 32, 32 }, null); - treeView = new UniTaskTrackerTreeView(); - TaskTracker2.EditorEnableState.EnableAutoReload = EditorPrefs.GetBool(TaskTracker2.EnableAutoReloadKey, false); - TaskTracker2.EditorEnableState.EnableTracking = EditorPrefs.GetBool(TaskTracker2.EnableTrackingKey, false); - TaskTracker2.EditorEnableState.EnableStackTrace = EditorPrefs.GetBool(TaskTracker2.EnableStackTraceKey, false); - } - - void OnGUI() - { - // Head - RenderHeadPanel(); - - // Splittable - SplitterGUILayout.BeginVerticalSplit(this.splitterState, EmptyLayoutOption); - { - // Column Tabble - RenderTable(); - - // StackTrace details - RenderDetailsPanel(); - } - SplitterGUILayout.EndVerticalSplit(); - } - - #region HeadPanel - - public static bool EnableAutoReload => TaskTracker2.EditorEnableState.EnableAutoReload; - public static bool EnableTracking => TaskTracker2.EditorEnableState.EnableTracking; - public static bool EnableStackTrace => TaskTracker2.EditorEnableState.EnableStackTrace; - static readonly GUIContent EnableAutoReloadHeadContent = EditorGUIUtility.TrTextContent("Enable AutoReload", "Reload automatically.", (Texture)null); - static readonly GUIContent ReloadHeadContent = EditorGUIUtility.TrTextContent("Reload", "Reload View.", (Texture)null); - static readonly GUIContent GCHeadContent = EditorGUIUtility.TrTextContent("GC.Collect", "Invoke GC.Collect.", (Texture)null); - static readonly GUIContent EnableTrackingHeadContent = EditorGUIUtility.TrTextContent("Enable Tracking", "Start to track async/await UniTask. Performance impact: low", (Texture)null); - static readonly GUIContent EnableStackTraceHeadContent = EditorGUIUtility.TrTextContent("Enable StackTrace", "Capture StackTrace when task is started. Performance impact: high", (Texture)null); - - // [Enable Tracking] | [Enable StackTrace] - void RenderHeadPanel() - { - EditorGUILayout.BeginVertical(EmptyLayoutOption); - EditorGUILayout.BeginHorizontal(EditorStyles.toolbar, EmptyLayoutOption); - - if (GUILayout.Toggle(EnableAutoReload, EnableAutoReloadHeadContent, EditorStyles.toolbarButton, EmptyLayoutOption) != EnableAutoReload) - { - TaskTracker2.EditorEnableState.EnableAutoReload = !EnableAutoReload; - } - - if (GUILayout.Toggle(EnableTracking, EnableTrackingHeadContent, EditorStyles.toolbarButton, EmptyLayoutOption) != EnableTracking) - { - TaskTracker2.EditorEnableState.EnableTracking = !EnableTracking; - } - - if (GUILayout.Toggle(EnableStackTrace, EnableStackTraceHeadContent, EditorStyles.toolbarButton, EmptyLayoutOption) != EnableStackTrace) - { - TaskTracker2.EditorEnableState.EnableStackTrace = !EnableStackTrace; - } - - GUILayout.FlexibleSpace(); - - if (GUILayout.Button(ReloadHeadContent, EditorStyles.toolbarButton, EmptyLayoutOption)) - { - TaskTracker2.CheckAndResetDirty(); - treeView.ReloadAndSort(); - Repaint(); - } - - if (GUILayout.Button(GCHeadContent, EditorStyles.toolbarButton, EmptyLayoutOption)) - { - GC.Collect(0); - } - - EditorGUILayout.EndHorizontal(); - EditorGUILayout.EndVertical(); - } - - #endregion - - #region TableColumn - - Vector2 tableScroll; - GUIStyle tableListStyle; - - void RenderTable() - { - if (tableListStyle == null) - { - tableListStyle = new GUIStyle("CN Box"); - tableListStyle.margin.top = 0; - tableListStyle.padding.left = 3; - } - - EditorGUILayout.BeginVertical(tableListStyle, EmptyLayoutOption); - - this.tableScroll = EditorGUILayout.BeginScrollView(this.tableScroll, new GUILayoutOption[] - { - GUILayout.ExpandWidth(true), - GUILayout.MaxWidth(2000f) - }); - var controlRect = EditorGUILayout.GetControlRect(new GUILayoutOption[] - { - GUILayout.ExpandHeight(true), - GUILayout.ExpandWidth(true) - }); - - - treeView?.OnGUI(controlRect); - - EditorGUILayout.EndScrollView(); - EditorGUILayout.EndVertical(); - } - - private void Update() - { - if (EnableAutoReload) - { - if (interval++ % 120 == 0) - { - if (TaskTracker2.CheckAndResetDirty()) - { - treeView.ReloadAndSort(); - Repaint(); - } - } - } - } - - #endregion - - #region Details - - static GUIStyle detailsStyle; - Vector2 detailsScroll; - void RenderDetailsPanel() { if (detailsStyle == null) diff --git a/Assets/UniRx.Async/EnumeratorAsyncExtensions.cs b/Assets/UniRx.Async/EnumeratorAsyncExtensions.cs index f5f4b33..4c66bbb 100644 --- a/Assets/UniRx.Async/EnumeratorAsyncExtensions.cs +++ b/Assets/UniRx.Async/EnumeratorAsyncExtensions.cs @@ -53,7 +53,7 @@ namespace UniRx.Async result.innerEnumerator = ConsumeEnumerator(innerEnumerator); result.cancellationToken = cancellationToken; - TaskTracker2.TrackActiveTask(result, 3); + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -65,7 +65,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); core.GetResult(token); } finally diff --git a/Assets/UniRx.Async/IUniTaskSource.cs b/Assets/UniRx.Async/IUniTaskSource.cs index 2aa12a4..d346b36 100644 --- a/Assets/UniRx.Async/IUniTaskSource.cs +++ b/Assets/UniRx.Async/IUniTaskSource.cs @@ -35,28 +35,28 @@ namespace UniRx.Async public static class UniTaskStatusExtensions { - /// != Pending. + /// status != Pending. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsCompleted(this UniTaskStatus status) { return status != UniTaskStatus.Pending; } - /// == Succeeded. + /// status == Succeeded. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsCompletedSuccessfully(this UniTaskStatus status) { return status == UniTaskStatus.Succeeded; } - /// == Canceled. + /// status == Canceled. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsCanceled(this UniTaskStatus status) { return status == UniTaskStatus.Canceled; } - /// == Faulted. + /// status == Faulted. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFaulted(this UniTaskStatus status) { diff --git a/Assets/UniRx.Async/Internal/ArrayPoolUtil.cs b/Assets/UniRx.Async/Internal/ArrayPoolUtil.cs index ee58010..2112582 100644 --- a/Assets/UniRx.Async/Internal/ArrayPoolUtil.cs +++ b/Assets/UniRx.Async/Internal/ArrayPoolUtil.cs @@ -33,13 +33,8 @@ namespace UniRx.Async.Internal } } - public static RentArray Materialize(IEnumerable source) + public static RentArray CopyToRentArray(IEnumerable source) { - if (source is T[] array) - { - return new RentArray(array, array.Length, null); - } - var defaultCount = 32; if (source is ICollection coll) { diff --git a/Assets/UniRx.Async/Internal/CancellationTokenHelper.cs b/Assets/UniRx.Async/Internal/CancellationTokenHelper.cs deleted file mode 100644 index 26bad0f..0000000 --- a/Assets/UniRx.Async/Internal/CancellationTokenHelper.cs +++ /dev/null @@ -1,32 +0,0 @@ -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Threading; - -namespace UniRx.Async.Internal -{ - internal static class CancellationTokenHelper - { - public static bool TrySetOrLinkCancellationToken(ref CancellationToken field, CancellationToken newCancellationToken) - { - if (newCancellationToken == CancellationToken.None) - { - return false; - } - else if (field == CancellationToken.None) - { - field = newCancellationToken; - return true; - } - else if (field == newCancellationToken) - { - return false; - } - - field = CancellationTokenSource.CreateLinkedTokenSource(field, newCancellationToken).Token; - return true; - } - } -} - -#endif \ No newline at end of file diff --git a/Assets/UniRx.Async/Internal/CancellationTokenHelper.cs.meta b/Assets/UniRx.Async/Internal/CancellationTokenHelper.cs.meta deleted file mode 100644 index bf09591..0000000 --- a/Assets/UniRx.Async/Internal/CancellationTokenHelper.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 53d1b536fc7e2d4458294ee2c7d9b743 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Internal/MinimumQueue.cs b/Assets/UniRx.Async/Internal/MinimumQueue.cs index 5f3b589..8638a47 100644 --- a/Assets/UniRx.Async/Internal/MinimumQueue.cs +++ b/Assets/UniRx.Async/Internal/MinimumQueue.cs @@ -8,8 +8,7 @@ using System.Runtime.CompilerServices; namespace UniRx.Async.Internal { // optimized version of Standard Queue. - // TODO: to internal. - public class MinimumQueue + internal class MinimumQueue { const int MinimumGrow = 4; const int GrowFactor = 200; @@ -28,9 +27,7 @@ namespace UniRx.Async.Internal public int Count { -#if NET_4_6 || NET_STANDARD_2_0 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif get { return size; } } @@ -40,9 +37,7 @@ namespace UniRx.Async.Internal return array[head]; } -#if NET_4_6 || NET_STANDARD_2_0 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif public void Enqueue(T item) { if (size == array.Length) @@ -55,9 +50,7 @@ namespace UniRx.Async.Internal size++; } -#if NET_4_6 || NET_STANDARD_2_0 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif public T Dequeue() { if (size == 0) ThrowForEmptyQueue(); @@ -102,9 +95,7 @@ namespace UniRx.Async.Internal tail = (size == capacity) ? 0 : size; } -#if NET_4_6 || NET_STANDARD_2_0 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif void MoveNext(ref int index) { int tmp = index + 1; diff --git a/Assets/UniRx.Async/Internal/PromiseHelper.cs b/Assets/UniRx.Async/Internal/PromiseHelper.cs deleted file mode 100644 index a303b11..0000000 --- a/Assets/UniRx.Async/Internal/PromiseHelper.cs +++ /dev/null @@ -1,34 +0,0 @@ -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; - -namespace UniRx.Async.Internal -{ - internal static class PromiseHelper - { - internal static void TrySetResultAll(IEnumerable source, T value) - where TPromise : class, IResolvePromise - { - var rentArray = ArrayPoolUtil.Materialize(source); - var clearArray = true; - try - { - var array = rentArray.Array; - var len = rentArray.Length; - for (int i = 0; i < len; i++) - { - array[i].TrySetResult(value); - array[i] = null; - } - clearArray = false; - } - finally - { - rentArray.DisposeManually(clearArray); - } - } - } -} - -#endif \ No newline at end of file diff --git a/Assets/UniRx.Async/Internal/PromiseHelper.cs.meta b/Assets/UniRx.Async/Internal/PromiseHelper.cs.meta deleted file mode 100644 index dfc1c50..0000000 --- a/Assets/UniRx.Async/Internal/PromiseHelper.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 173f9b763911bf847b7dfbf31ee87fc4 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Internal/TaskTracker.cs b/Assets/UniRx.Async/Internal/TaskTracker.cs index e69df26..2ef81bb 100644 --- a/Assets/UniRx.Async/Internal/TaskTracker.cs +++ b/Assets/UniRx.Async/Internal/TaskTracker.cs @@ -5,12 +5,12 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Threading; +using UniRx.Async.Internal; -namespace UniRx.Async.Internal +namespace UniRx.Async { // public for add user custom. - // TODO: Remove public static class TaskTracker { #if UNITY_EDITOR @@ -60,144 +60,6 @@ namespace UniRx.Async.Internal #endif - static List> listPool = new List>(); - - static readonly WeakDictionary tracking = new WeakDictionary(); - - [Conditional("UNITY_EDITOR")] - public static void TrackActiveTask(IAwaiter task, int skipFrame = 1) - { -#if UNITY_EDITOR - dirty = true; - if (!EditorEnableState.EnableTracking) return; - var stackTrace = EditorEnableState.EnableStackTrace ? new StackTrace(skipFrame, true).CleanupAsyncStackTrace() : ""; - tracking.TryAdd(task, (Interlocked.Increment(ref trackingId), DateTime.UtcNow, stackTrace)); -#endif - } - - [Conditional("UNITY_EDITOR")] - public static void TrackActiveTask(IAwaiter task, string stackTrace) - { -#if UNITY_EDITOR - dirty = true; - if (!EditorEnableState.EnableTracking) return; - var success = tracking.TryAdd(task, (Interlocked.Increment(ref trackingId), DateTime.UtcNow, stackTrace)); -#endif - } - - public static string CaptureStackTrace(int skipFrame) - { -#if UNITY_EDITOR - if (!EditorEnableState.EnableTracking) return ""; - var stackTrace = EditorEnableState.EnableStackTrace ? new StackTrace(skipFrame + 1, true).CleanupAsyncStackTrace() : ""; - return stackTrace; -#else - return null; -#endif - } - - [Conditional("UNITY_EDITOR")] - public static void RemoveTracking(IAwaiter task) - { -#if UNITY_EDITOR - dirty = true; - if (!EditorEnableState.EnableTracking) return; - var success = tracking.TryRemove(task); -#endif - } - - static bool dirty; - - public static bool CheckAndResetDirty() - { - var current = dirty; - dirty = false; - return current; - } - - /// (trackingId, awaiterType, awaiterStatus, createdTime, stackTrace) - public static void ForEachActiveTask(Action action) - { - lock (listPool) - { - var count = tracking.ToList(ref listPool, clear: false); - try - { - for (int i = 0; i < count; i++) - { - string typeName = null; - var keyType = listPool[i].Key.GetType(); - if (keyType.IsNested) - { - typeName = keyType.DeclaringType.Name + "." + keyType.Name; - } - else - { - typeName = keyType.Name; - } - - action(listPool[i].Value.trackingId, typeName, listPool[i].Key.Status, listPool[i].Value.addTime, listPool[i].Value.stackTrace); - listPool[i] = new KeyValuePair(null, (0, default(DateTime), null)); // clear - } - } - catch - { - listPool.Clear(); - throw; - } - } - } - } - - public static class TaskTracker2 - { -#if UNITY_EDITOR - - static int trackingId = 0; - - public const string EnableAutoReloadKey = "UniTaskTrackerWindow_EnableAutoReloadKey"; - public const string EnableTrackingKey = "UniTaskTrackerWindow_EnableTrackingKey"; - public const string EnableStackTraceKey = "UniTaskTrackerWindow_EnableStackTraceKey"; - - public static class EditorEnableState - { - static bool enableAutoReload; - public static bool EnableAutoReload - { - get { return enableAutoReload; } - set - { - enableAutoReload = value; - UnityEditor.EditorPrefs.SetBool(EnableAutoReloadKey, value); - } - } - - static bool enableTracking; - public static bool EnableTracking - { - get { return enableTracking; } - set - { - enableTracking = value; - UnityEditor.EditorPrefs.SetBool(EnableTrackingKey, value); - } - } - - static bool enableStackTrace; - public static bool EnableStackTrace - { - get { return enableStackTrace; } - set - { - enableStackTrace = value; - UnityEditor.EditorPrefs.SetBool(EnableStackTraceKey, value); - } - } - } - -#endif - - static List> listPool = new List>(); static readonly WeakDictionary tracking = new WeakDictionary(); diff --git a/Assets/UniRx.Async/Triggers/AsyncAnimatorTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncAnimatorTrigger.cs deleted file mode 100644 index 2a294d7..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncAnimatorTrigger.cs +++ /dev/null @@ -1,54 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncAnimatorTrigger : AsyncTriggerBase - { - AsyncTriggerPromise onAnimatorIK; - AsyncTriggerPromiseDictionary onAnimatorIKs; - AsyncTriggerPromise onAnimatorMove; - AsyncTriggerPromiseDictionary onAnimatorMoves; - - - protected override IEnumerable GetPromises() - { - return Concat(onAnimatorIK, onAnimatorIKs, onAnimatorMove, onAnimatorMoves); - } - - - void OnAnimatorIK(int layerIndex) - { - TrySetResult(onAnimatorIK, onAnimatorIKs, layerIndex); - } - - - public UniTask OnAnimatorIKAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onAnimatorIK, ref onAnimatorIKs, cancellationToken); - } - - - void OnAnimatorMove() - { - TrySetResult(onAnimatorMove, onAnimatorMoves, AsyncUnit.Default); - } - - - public UniTask OnAnimatorMoveAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onAnimatorMove, ref onAnimatorMoves, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncAnimatorTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncAnimatorTrigger.cs.meta deleted file mode 100644 index 29b2826..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncAnimatorTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: ae912c37ac7f4cd42b25f22452435103 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncAwakeTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncAwakeTrigger.cs index 0710dcb..82661b2 100644 --- a/Assets/UniRx.Async/Triggers/AsyncAwakeTrigger.cs +++ b/Assets/UniRx.Async/Triggers/AsyncAwakeTrigger.cs @@ -1,32 +1,54 @@ #if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member +using System.Threading; using UnityEngine; namespace UniRx.Async.Triggers { + public static partial class AsyncTriggerExtensions + { + public static AsyncAwakeTrigger GetAsyncAwakeTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncAwakeTrigger GetAsyncAwakeTrigger(this Component component) + { + return component.gameObject.GetAsyncAwakeTrigger(); + } + } + [DisallowMultipleComponent] public class AsyncAwakeTrigger : MonoBehaviour { bool called = false; - UniTaskCompletionSource promise; + TriggerEvent triggerEvent; void Awake() { called = true; - promise?.TrySetResult(); + triggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent = null; } public UniTask AwakeAsync() { if (called) return UniTask.CompletedTask; + PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, new AwakeMonitor(this)); - return new UniTask(promise ?? (promise = new UniTaskCompletionSource())); + + if (triggerEvent == null) + { + triggerEvent = new TriggerEvent(); + } + + return ((IAsyncOneShotTrigger)new AsyncTriggerHandler(triggerEvent, true)).OneShotAsync(); } private void OnDestroy() { - promise?.TrySetCanceled(); + triggerEvent?.TrySetCanceled(CancellationToken.None); } class AwakeMonitor : IPlayerLoopItem diff --git a/Assets/UniRx.Async/Triggers/AsyncBeginDragTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncBeginDragTrigger.cs deleted file mode 100644 index bbecbea..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncBeginDragTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncBeginDragTrigger : AsyncTriggerBase, IBeginDragHandler - { - AsyncTriggerPromise onBeginDrag; - AsyncTriggerPromiseDictionary onBeginDrags; - - - protected override IEnumerable GetPromises() - { - return Concat(onBeginDrag, onBeginDrags); - } - - - void IBeginDragHandler.OnBeginDrag(PointerEventData eventData) - { - TrySetResult(onBeginDrag, onBeginDrags, eventData); - } - - - public UniTask OnBeginDragAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onBeginDrag, ref onBeginDrags, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncBeginDragTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncBeginDragTrigger.cs.meta deleted file mode 100644 index d4a44e9..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncBeginDragTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 171fd2191eb22af4fbd92b51815ca757 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncCancelTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncCancelTrigger.cs deleted file mode 100644 index 9b14689..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncCancelTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncCancelTrigger : AsyncTriggerBase, ICancelHandler - { - AsyncTriggerPromise onCancel; - AsyncTriggerPromiseDictionary onCancels; - - - protected override IEnumerable GetPromises() - { - return Concat(onCancel, onCancels); - } - - - void ICancelHandler.OnCancel(BaseEventData eventData) - { - TrySetResult(onCancel, onCancels, eventData); - } - - - public UniTask OnCancelAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onCancel, ref onCancels, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncCancelTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncCancelTrigger.cs.meta deleted file mode 100644 index 285efd5..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncCancelTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 291886b6e5f2d044a85b2a4dedcaca97 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncCanvasGroupChangedTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncCanvasGroupChangedTrigger.cs deleted file mode 100644 index 98fb776..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncCanvasGroupChangedTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncCanvasGroupChangedTrigger : AsyncTriggerBase - { - AsyncTriggerPromise onCanvasGroupChanged; - AsyncTriggerPromiseDictionary onCanvasGroupChangeds; - - - protected override IEnumerable GetPromises() - { - return Concat(onCanvasGroupChanged, onCanvasGroupChangeds); - } - - - void OnCanvasGroupChanged() - { - TrySetResult(onCanvasGroupChanged, onCanvasGroupChangeds, AsyncUnit.Default); - } - - - public UniTask OnCanvasGroupChangedAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onCanvasGroupChanged, ref onCanvasGroupChangeds, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncCanvasGroupChangedTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncCanvasGroupChangedTrigger.cs.meta deleted file mode 100644 index d0ebc56..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncCanvasGroupChangedTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: eddba832648f83046a320ffcacfc771d -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncCollision2DTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncCollision2DTrigger.cs deleted file mode 100644 index 0f0b747..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncCollision2DTrigger.cs +++ /dev/null @@ -1,69 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncCollision2DTrigger : AsyncTriggerBase - { - AsyncTriggerPromise onCollisionEnter2D; - AsyncTriggerPromiseDictionary onCollisionEnter2Ds; - AsyncTriggerPromise onCollisionExit2D; - AsyncTriggerPromiseDictionary onCollisionExit2Ds; - AsyncTriggerPromise onCollisionStay2D; - AsyncTriggerPromiseDictionary onCollisionStay2Ds; - - - protected override IEnumerable GetPromises() - { - return Concat(onCollisionEnter2D, onCollisionEnter2Ds, onCollisionExit2D, onCollisionExit2Ds, onCollisionStay2D, onCollisionStay2Ds); - } - - - void OnCollisionEnter2D(Collision2D coll) - { - TrySetResult(onCollisionEnter2D, onCollisionEnter2Ds, coll); - } - - - public UniTask OnCollisionEnter2DAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onCollisionEnter2D, ref onCollisionEnter2Ds, cancellationToken); - } - - - void OnCollisionExit2D(Collision2D coll) - { - TrySetResult(onCollisionExit2D, onCollisionExit2Ds, coll); - } - - - public UniTask OnCollisionExit2DAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onCollisionExit2D, ref onCollisionExit2Ds, cancellationToken); - } - - - void OnCollisionStay2D(Collision2D coll) - { - TrySetResult(onCollisionStay2D, onCollisionStay2Ds, coll); - } - - - public UniTask OnCollisionStay2DAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onCollisionStay2D, ref onCollisionStay2Ds, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncCollision2DTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncCollision2DTrigger.cs.meta deleted file mode 100644 index ad81300..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncCollision2DTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: fbeb63f69bedec44f8003730887f914b -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncCollisionTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncCollisionTrigger.cs deleted file mode 100644 index 71306df..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncCollisionTrigger.cs +++ /dev/null @@ -1,69 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncCollisionTrigger : AsyncTriggerBase - { - AsyncTriggerPromise onCollisionEnter; - AsyncTriggerPromiseDictionary onCollisionEnters; - AsyncTriggerPromise onCollisionExit; - AsyncTriggerPromiseDictionary onCollisionExits; - AsyncTriggerPromise onCollisionStay; - AsyncTriggerPromiseDictionary onCollisionStays; - - - protected override IEnumerable GetPromises() - { - return Concat(onCollisionEnter, onCollisionEnters, onCollisionExit, onCollisionExits, onCollisionStay, onCollisionStays); - } - - - void OnCollisionEnter(Collision collision) - { - TrySetResult(onCollisionEnter, onCollisionEnters, collision); - } - - - public UniTask OnCollisionEnterAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onCollisionEnter, ref onCollisionEnters, cancellationToken); - } - - - void OnCollisionExit(Collision collisionInfo) - { - TrySetResult(onCollisionExit, onCollisionExits, collisionInfo); - } - - - public UniTask OnCollisionExitAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onCollisionExit, ref onCollisionExits, cancellationToken); - } - - - void OnCollisionStay(Collision collisionInfo) - { - TrySetResult(onCollisionStay, onCollisionStays, collisionInfo); - } - - - public UniTask OnCollisionStayAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onCollisionStay, ref onCollisionStays, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncCollisionTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncCollisionTrigger.cs.meta deleted file mode 100644 index ebcc28e..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncCollisionTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 72db4a683be8f6a428823502599014a9 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncDeselectTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncDeselectTrigger.cs deleted file mode 100644 index a76b421..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncDeselectTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncDeselectTrigger : AsyncTriggerBase, IDeselectHandler - { - AsyncTriggerPromise onDeselect; - AsyncTriggerPromiseDictionary onDeselects; - - - protected override IEnumerable GetPromises() - { - return Concat(onDeselect, onDeselects); - } - - - void IDeselectHandler.OnDeselect(BaseEventData eventData) - { - TrySetResult(onDeselect, onDeselects, eventData); - } - - - public UniTask OnDeselectAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onDeselect, ref onDeselects, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncDeselectTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncDeselectTrigger.cs.meta deleted file mode 100644 index 9509524..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncDeselectTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 30faa9be5bd883e488bdc52f4825c4da -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncDestroyTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncDestroyTrigger.cs index 245126f..2eaf42b 100644 --- a/Assets/UniRx.Async/Triggers/AsyncDestroyTrigger.cs +++ b/Assets/UniRx.Async/Triggers/AsyncDestroyTrigger.cs @@ -2,18 +2,30 @@ #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member using System.Threading; -using UniRx.Async.Internal; using UnityEngine; namespace UniRx.Async.Triggers { + public static partial class AsyncTriggerExtensions + { + public static AsyncDestroyTrigger GetAsyncDestroyTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncDestroyTrigger GetAsyncDestroyTrigger(this Component component) + { + return component.gameObject.GetAsyncDestroyTrigger(); + } + } + [DisallowMultipleComponent] public class AsyncDestroyTrigger : MonoBehaviour { + bool awakeCalled = false; bool called = false; - UniTaskCompletionSource promise; - CancellationTokenSource cancellationTokenSource; // main cancellation - object canellationTokenSourceOrQueue; // external from AddCancellationTriggerOnDestroy + TriggerEvent triggerEvent; + CancellationTokenSource cancellationTokenSource; public CancellationToken CancellationToken { @@ -27,64 +39,57 @@ namespace UniRx.Async.Triggers } } - /// This function is called when the MonoBehaviour will be destroyed. + void Awake() + { + awakeCalled = true; + } + void OnDestroy() { called = true; - promise?.TrySetResult(); + + triggerEvent?.TrySetResult(AsyncUnit.Default); cancellationTokenSource?.Cancel(); cancellationTokenSource?.Dispose(); - if (canellationTokenSourceOrQueue != null) - { - if (canellationTokenSourceOrQueue is CancellationTokenSource cts) - { - cts.Cancel(); - cts.Dispose(); - } - else - { - var q = (MinimumQueue)canellationTokenSourceOrQueue; - while (q.Count != 0) - { - var c = q.Dequeue(); - c.Cancel(); - c.Dispose(); - } - } - canellationTokenSourceOrQueue = null; - } + + triggerEvent = null; } - /// This function is called when the MonoBehaviour will be destroyed. public UniTask OnDestroyAsync() { if (called) return UniTask.CompletedTask; - return new UniTask(promise ?? (promise = new UniTaskCompletionSource())); + + if (!awakeCalled) + { + PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, new AwakeMonitor(this)); + } + + if (triggerEvent == null) + { + triggerEvent = new TriggerEvent(); + } + + return ((IAsyncOneShotTrigger)new AsyncTriggerHandler(triggerEvent, true)).OneShotAsync(); } - /// Add Cancellation Triggers on destroy - public void AddCancellationTriggerOnDestroy(CancellationTokenSource cts) + class AwakeMonitor : IPlayerLoopItem { - if (called) + readonly AsyncDestroyTrigger trigger; + + public AwakeMonitor(AsyncDestroyTrigger trigger) { - cts.Cancel(); - cts.Dispose(); + this.trigger = trigger; } - if (canellationTokenSourceOrQueue == null) + public bool MoveNext() { - canellationTokenSourceOrQueue = cts; - } - else if (canellationTokenSourceOrQueue is CancellationTokenSource c) - { - var q = new MinimumQueue(4); - q.Enqueue(c); - q.Enqueue(cts); - canellationTokenSourceOrQueue = q; - } - else - { - ((MinimumQueue)canellationTokenSourceOrQueue).Enqueue(cts); + if (trigger.called) return false; + if (trigger == null) + { + trigger.OnDestroy(); + return false; + } + return true; } } } diff --git a/Assets/UniRx.Async/Triggers/AsyncDragTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncDragTrigger.cs deleted file mode 100644 index 0a36282..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncDragTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncDragTrigger : AsyncTriggerBase, IDragHandler - { - AsyncTriggerPromise onDrag; - AsyncTriggerPromiseDictionary onDrags; - - - protected override IEnumerable GetPromises() - { - return Concat(onDrag, onDrags); - } - - - void IDragHandler.OnDrag(PointerEventData eventData) - { - TrySetResult(onDrag, onDrags, eventData); - } - - - public UniTask OnDragAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onDrag, ref onDrags, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncDragTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncDragTrigger.cs.meta deleted file mode 100644 index d259f40..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncDragTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 52242547ba60ea74f8a2e3bbab5fcdfa -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncDropTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncDropTrigger.cs deleted file mode 100644 index 25b6217..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncDropTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncDropTrigger : AsyncTriggerBase, IDropHandler - { - AsyncTriggerPromise onDrop; - AsyncTriggerPromiseDictionary onDrops; - - - protected override IEnumerable GetPromises() - { - return Concat(onDrop, onDrops); - } - - - void IDropHandler.OnDrop(PointerEventData eventData) - { - TrySetResult(onDrop, onDrops, eventData); - } - - - public UniTask OnDropAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onDrop, ref onDrops, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncDropTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncDropTrigger.cs.meta deleted file mode 100644 index 2a15847..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncDropTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 42d65fd5e4be25f41a927eca25b0acf7 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncEnableDisableTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncEnableDisableTrigger.cs deleted file mode 100644 index 092b97f..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncEnableDisableTrigger.cs +++ /dev/null @@ -1,55 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncEnableDisableTrigger : AsyncTriggerBase - { - AsyncTriggerPromise onEnable; - AsyncTriggerPromiseDictionary onEnables; - AsyncTriggerPromise onDisable; - AsyncTriggerPromiseDictionary onDisables; - - - protected override IEnumerable GetPromises() - { - return Concat(onEnable, onEnables, onDisable, onDisables); - } - - - void OnEnable() - { - TrySetResult(onEnable, onEnables, AsyncUnit.Default); - } - - - public UniTask OnEnableAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onEnable, ref onEnables, cancellationToken); - } - - - void OnDisable() - { - TrySetResult(onDisable, onDisables, AsyncUnit.Default); - } - - - public UniTask OnDisableAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onDisable, ref onDisables, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncEnableDisableTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncEnableDisableTrigger.cs.meta deleted file mode 100644 index 8e61a0f..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncEnableDisableTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: d0bf9142b63b4cb43b693f0b83b3dbe7 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncEndDragTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncEndDragTrigger.cs deleted file mode 100644 index 0e8f27c..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncEndDragTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncEndDragTrigger : AsyncTriggerBase, IEndDragHandler - { - AsyncTriggerPromise onEndDrag; - AsyncTriggerPromiseDictionary onEndDrags; - - - protected override IEnumerable GetPromises() - { - return Concat(onEndDrag, onEndDrags); - } - - - void IEndDragHandler.OnEndDrag(PointerEventData eventData) - { - TrySetResult(onEndDrag, onEndDrags, eventData); - } - - - public UniTask OnEndDragAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onEndDrag, ref onEndDrags, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncEndDragTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncEndDragTrigger.cs.meta deleted file mode 100644 index 98f67b8..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncEndDragTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 8298d43de348acc4aa4e7dbf30472dbf -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncEventTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncEventTrigger.cs deleted file mode 100644 index 17568d2..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncEventTrigger.cs +++ /dev/null @@ -1,264 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncEventTrigger : AsyncTriggerBase - { - AsyncTriggerPromise onDeselect; - AsyncTriggerPromiseDictionary onDeselects; - AsyncTriggerPromise onMove; - AsyncTriggerPromiseDictionary onMoves; - AsyncTriggerPromise onPointerDown; - AsyncTriggerPromiseDictionary onPointerDowns; - AsyncTriggerPromise onPointerEnter; - AsyncTriggerPromiseDictionary onPointerEnters; - AsyncTriggerPromise onPointerExit; - AsyncTriggerPromiseDictionary onPointerExits; - AsyncTriggerPromise onPointerUp; - AsyncTriggerPromiseDictionary onPointerUps; - AsyncTriggerPromise onSelect; - AsyncTriggerPromiseDictionary onSelects; - AsyncTriggerPromise onPointerClick; - AsyncTriggerPromiseDictionary onPointerClicks; - AsyncTriggerPromise onSubmit; - AsyncTriggerPromiseDictionary onSubmits; - AsyncTriggerPromise onDrag; - AsyncTriggerPromiseDictionary onDrags; - AsyncTriggerPromise onBeginDrag; - AsyncTriggerPromiseDictionary onBeginDrags; - AsyncTriggerPromise onEndDrag; - AsyncTriggerPromiseDictionary onEndDrags; - AsyncTriggerPromise onDrop; - AsyncTriggerPromiseDictionary onDrops; - AsyncTriggerPromise onUpdateSelected; - AsyncTriggerPromiseDictionary onUpdateSelecteds; - AsyncTriggerPromise onInitializePotentialDrag; - AsyncTriggerPromiseDictionary onInitializePotentialDrags; - AsyncTriggerPromise onCancel; - AsyncTriggerPromiseDictionary onCancels; - AsyncTriggerPromise onScroll; - AsyncTriggerPromiseDictionary onScrolls; - - - protected override IEnumerable GetPromises() - { - return Concat(onDeselect, onDeselects, onMove, onMoves, onPointerDown, onPointerDowns, onPointerEnter, onPointerEnters, onPointerExit, onPointerExits, onPointerUp, onPointerUps, onSelect, onSelects, onPointerClick, onPointerClicks, onSubmit, onSubmits, onDrag, onDrags, onBeginDrag, onBeginDrags, onEndDrag, onEndDrags, onDrop, onDrops, onUpdateSelected, onUpdateSelecteds, onInitializePotentialDrag, onInitializePotentialDrags, onCancel, onCancels, onScroll, onScrolls); - } - - void OnDeselect(BaseEventData eventData) - { - TrySetResult(onDeselect, onDeselects, eventData); - } - - - public UniTask OnDeselectAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onDeselect, ref onDeselects, cancellationToken); - } - - - void OnMove(AxisEventData eventData) - { - TrySetResult(onMove, onMoves, eventData); - } - - - public UniTask OnMoveAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onMove, ref onMoves, cancellationToken); - } - - - void OnPointerDown(PointerEventData eventData) - { - TrySetResult(onPointerDown, onPointerDowns, eventData); - } - - - public UniTask OnPointerDownAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onPointerDown, ref onPointerDowns, cancellationToken); - } - - - void OnPointerEnter(PointerEventData eventData) - { - TrySetResult(onPointerEnter, onPointerEnters, eventData); - } - - - public UniTask OnPointerEnterAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onPointerEnter, ref onPointerEnters, cancellationToken); - } - - - void OnPointerExit(PointerEventData eventData) - { - TrySetResult(onPointerExit, onPointerExits, eventData); - } - - - public UniTask OnPointerExitAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onPointerExit, ref onPointerExits, cancellationToken); - } - - - void OnPointerUp(PointerEventData eventData) - { - TrySetResult(onPointerUp, onPointerUps, eventData); - } - - - public UniTask OnPointerUpAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onPointerUp, ref onPointerUps, cancellationToken); - } - - - void OnSelect(BaseEventData eventData) - { - TrySetResult(onSelect, onSelects, eventData); - } - - - public UniTask OnSelectAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onSelect, ref onSelects, cancellationToken); - } - - - void OnPointerClick(PointerEventData eventData) - { - TrySetResult(onPointerClick, onPointerClicks, eventData); - } - - - public UniTask OnPointerClickAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onPointerClick, ref onPointerClicks, cancellationToken); - } - - - void OnSubmit(BaseEventData eventData) - { - TrySetResult(onSubmit, onSubmits, eventData); - } - - - public UniTask OnSubmitAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onSubmit, ref onSubmits, cancellationToken); - } - - - void OnDrag(PointerEventData eventData) - { - TrySetResult(onDrag, onDrags, eventData); - } - - - public UniTask OnDragAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onDrag, ref onDrags, cancellationToken); - } - - - void OnBeginDrag(PointerEventData eventData) - { - TrySetResult(onBeginDrag, onBeginDrags, eventData); - } - - - public UniTask OnBeginDragAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onBeginDrag, ref onBeginDrags, cancellationToken); - } - - - void OnEndDrag(PointerEventData eventData) - { - TrySetResult(onEndDrag, onEndDrags, eventData); - } - - - public UniTask OnEndDragAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onEndDrag, ref onEndDrags, cancellationToken); - } - - - void OnDrop(PointerEventData eventData) - { - TrySetResult(onDrop, onDrops, eventData); - } - - - public UniTask OnDropAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onDrop, ref onDrops, cancellationToken); - } - - - void OnUpdateSelected(BaseEventData eventData) - { - TrySetResult(onUpdateSelected, onUpdateSelecteds, eventData); - } - - - public UniTask OnUpdateSelectedAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onUpdateSelected, ref onUpdateSelecteds, cancellationToken); - } - - - void OnInitializePotentialDrag(PointerEventData eventData) - { - TrySetResult(onInitializePotentialDrag, onInitializePotentialDrags, eventData); - } - - - public UniTask OnInitializePotentialDragAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onInitializePotentialDrag, ref onInitializePotentialDrags, cancellationToken); - } - - - void OnCancel(BaseEventData eventData) - { - TrySetResult(onCancel, onCancels, eventData); - } - - - public UniTask OnCancelAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onCancel, ref onCancels, cancellationToken); - } - - - void OnScroll(PointerEventData eventData) - { - TrySetResult(onScroll, onScrolls, eventData); - } - - - public UniTask OnScrollAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onScroll, ref onScrolls, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncEventTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncEventTrigger.cs.meta deleted file mode 100644 index c901478..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncEventTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 89997820797ad6d43b17971a8bd0d8fe -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncFixedUpdateTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncFixedUpdateTrigger.cs deleted file mode 100644 index 8cfc821..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncFixedUpdateTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncFixedUpdateTrigger : AsyncTriggerBase - { - AsyncTriggerPromise fixedUpdate; - AsyncTriggerPromiseDictionary fixedUpdates; - - - protected override IEnumerable GetPromises() - { - return Concat(fixedUpdate, fixedUpdates); - } - - - void FixedUpdate() - { - TrySetResult(fixedUpdate, fixedUpdates, AsyncUnit.Default); - } - - - public UniTask FixedUpdateAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref fixedUpdate, ref fixedUpdates, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncFixedUpdateTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncFixedUpdateTrigger.cs.meta deleted file mode 100644 index 7154af6..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncFixedUpdateTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: c74b906c4294aaa4e900f6e7f8b36df6 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncInitializePotentialDragTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncInitializePotentialDragTrigger.cs deleted file mode 100644 index 8dda82a..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncInitializePotentialDragTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncInitializePotentialDragTrigger : AsyncTriggerBase, IInitializePotentialDragHandler - { - AsyncTriggerPromise onInitializePotentialDrag; - AsyncTriggerPromiseDictionary onInitializePotentialDrags; - - - protected override IEnumerable GetPromises() - { - return Concat(onInitializePotentialDrag, onInitializePotentialDrags); - } - - - void IInitializePotentialDragHandler.OnInitializePotentialDrag(PointerEventData eventData) - { - TrySetResult(onInitializePotentialDrag, onInitializePotentialDrags, eventData); - } - - - public UniTask OnInitializePotentialDragAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onInitializePotentialDrag, ref onInitializePotentialDrags, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncInitializePotentialDragTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncInitializePotentialDragTrigger.cs.meta deleted file mode 100644 index 0df8a5b..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncInitializePotentialDragTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: ae0733adc239a324f8b934ffb119abd8 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncJointTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncJointTrigger.cs deleted file mode 100644 index bf33407..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncJointTrigger.cs +++ /dev/null @@ -1,55 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncJointTrigger : AsyncTriggerBase - { - AsyncTriggerPromise onJointBreak; - AsyncTriggerPromiseDictionary onJointBreaks; - AsyncTriggerPromise onJointBreak2D; - AsyncTriggerPromiseDictionary onJointBreak2Ds; - - - protected override IEnumerable GetPromises() - { - return Concat(onJointBreak, onJointBreaks, onJointBreak2D, onJointBreak2Ds); - } - - - void OnJointBreak(float breakForce) - { - TrySetResult(onJointBreak, onJointBreaks, breakForce); - } - - - public UniTask OnJointBreakAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onJointBreak, ref onJointBreaks, cancellationToken); - } - - - void OnJointBreak2D(Joint2D brokenJoint) - { - TrySetResult(onJointBreak2D, onJointBreak2Ds, brokenJoint); - } - - - public UniTask OnJointBreak2DAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onJointBreak2D, ref onJointBreak2Ds, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncJointTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncJointTrigger.cs.meta deleted file mode 100644 index 8220736..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncJointTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 04dc74e7b2368094f9153921804a1fb7 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncLateUpdateTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncLateUpdateTrigger.cs deleted file mode 100644 index e88dfd8..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncLateUpdateTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncLateUpdateTrigger : AsyncTriggerBase - { - AsyncTriggerPromise lateUpdate; - AsyncTriggerPromiseDictionary lateUpdates; - - - protected override IEnumerable GetPromises() - { - return Concat(lateUpdate, lateUpdates); - } - - - void LateUpdate() - { - TrySetResult(lateUpdate, lateUpdates, AsyncUnit.Default); - } - - - public UniTask LateUpdateAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref lateUpdate, ref lateUpdates, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncLateUpdateTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncLateUpdateTrigger.cs.meta deleted file mode 100644 index 391059d..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncLateUpdateTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: a4fb2b4c09cb4ec4a82b934f2038eb36 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncMouseTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncMouseTrigger.cs deleted file mode 100644 index 243fb00..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncMouseTrigger.cs +++ /dev/null @@ -1,129 +0,0 @@ - -#if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO) - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncMouseTrigger : AsyncTriggerBase - { - AsyncTriggerPromise onMouseDown; - AsyncTriggerPromiseDictionary onMouseDowns; - AsyncTriggerPromise onMouseDrag; - AsyncTriggerPromiseDictionary onMouseDrags; - AsyncTriggerPromise onMouseEnter; - AsyncTriggerPromiseDictionary onMouseEnters; - AsyncTriggerPromise onMouseExit; - AsyncTriggerPromiseDictionary onMouseExits; - AsyncTriggerPromise onMouseOver; - AsyncTriggerPromiseDictionary onMouseOvers; - AsyncTriggerPromise onMouseUp; - AsyncTriggerPromiseDictionary onMouseUps; - AsyncTriggerPromise onMouseUpAsButton; - AsyncTriggerPromiseDictionary onMouseUpAsButtons; - - - protected override IEnumerable GetPromises() - { - return Concat(onMouseDown, onMouseDowns, onMouseDrag, onMouseDrags, onMouseEnter, onMouseEnters, onMouseExit, onMouseExits, onMouseOver, onMouseOvers, onMouseUp, onMouseUps, onMouseUpAsButton, onMouseUpAsButtons); - } - - - void OnMouseDown() - { - TrySetResult(onMouseDown, onMouseDowns, AsyncUnit.Default); - } - - - public UniTask OnMouseDownAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onMouseDown, ref onMouseDowns, cancellationToken); - } - - - void OnMouseDrag() - { - TrySetResult(onMouseDrag, onMouseDrags, AsyncUnit.Default); - } - - - public UniTask OnMouseDragAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onMouseDrag, ref onMouseDrags, cancellationToken); - } - - - void OnMouseEnter() - { - TrySetResult(onMouseEnter, onMouseEnters, AsyncUnit.Default); - } - - - public UniTask OnMouseEnterAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onMouseEnter, ref onMouseEnters, cancellationToken); - } - - - void OnMouseExit() - { - TrySetResult(onMouseExit, onMouseExits, AsyncUnit.Default); - } - - - public UniTask OnMouseExitAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onMouseExit, ref onMouseExits, cancellationToken); - } - - - void OnMouseOver() - { - TrySetResult(onMouseOver, onMouseOvers, AsyncUnit.Default); - } - - - public UniTask OnMouseOverAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onMouseOver, ref onMouseOvers, cancellationToken); - } - - - void OnMouseUp() - { - TrySetResult(onMouseUp, onMouseUps, AsyncUnit.Default); - } - - - public UniTask OnMouseUpAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onMouseUp, ref onMouseUps, cancellationToken); - } - - - void OnMouseUpAsButton() - { - TrySetResult(onMouseUpAsButton, onMouseUpAsButtons, AsyncUnit.Default); - } - - - public UniTask OnMouseUpAsButtonAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onMouseUpAsButton, ref onMouseUpAsButtons, cancellationToken); - } - - - } -} - -#endif - - -#endif diff --git a/Assets/UniRx.Async/Triggers/AsyncMouseTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncMouseTrigger.cs.meta deleted file mode 100644 index 9e8706f..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncMouseTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 57ad5120e9c4d424484c963791467272 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncMoveTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncMoveTrigger.cs deleted file mode 100644 index 19d0f56..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncMoveTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncMoveTrigger : AsyncTriggerBase, IMoveHandler - { - AsyncTriggerPromise onMove; - AsyncTriggerPromiseDictionary onMoves; - - - protected override IEnumerable GetPromises() - { - return Concat(onMove, onMoves); - } - - - void IMoveHandler.OnMove(AxisEventData eventData) - { - TrySetResult(onMove, onMoves, eventData); - } - - - public UniTask OnMoveAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onMove, ref onMoves, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncMoveTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncMoveTrigger.cs.meta deleted file mode 100644 index 2ea01b7..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncMoveTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 1699926e875c24d4aa34bc8817f96f0e -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncParticleTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncParticleTrigger.cs deleted file mode 100644 index 284461a..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncParticleTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncParticleTrigger : AsyncTriggerBase - { - AsyncTriggerPromise onParticleCollision; - AsyncTriggerPromiseDictionary onParticleCollisions; - - - protected override IEnumerable GetPromises() - { - return Concat(onParticleCollision, onParticleCollisions); - } - - - void OnParticleCollision(GameObject other) - { - TrySetResult(onParticleCollision, onParticleCollisions, other); - } - - - public UniTask OnParticleCollisionAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onParticleCollision, ref onParticleCollisions, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncParticleTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncParticleTrigger.cs.meta deleted file mode 100644 index 4a162c7..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncParticleTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 27d3f2efd47fb1d4fb2e9130f97ea8aa -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncPointerClickTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncPointerClickTrigger.cs deleted file mode 100644 index b4ed576..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncPointerClickTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncPointerClickTrigger : AsyncTriggerBase, IPointerClickHandler - { - AsyncTriggerPromise onPointerClick; - AsyncTriggerPromiseDictionary onPointerClicks; - - - protected override IEnumerable GetPromises() - { - return Concat(onPointerClick, onPointerClicks); - } - - - void IPointerClickHandler.OnPointerClick(PointerEventData eventData) - { - TrySetResult(onPointerClick, onPointerClicks, eventData); - } - - - public UniTask OnPointerClickAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onPointerClick, ref onPointerClicks, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncPointerClickTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncPointerClickTrigger.cs.meta deleted file mode 100644 index 67447a7..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncPointerClickTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 9f8865abf2db3d248b3730cdb18bb8b7 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncPointerDownTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncPointerDownTrigger.cs deleted file mode 100644 index aa6bc36..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncPointerDownTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncPointerDownTrigger : AsyncTriggerBase, IPointerDownHandler - { - AsyncTriggerPromise onPointerDown; - AsyncTriggerPromiseDictionary onPointerDowns; - - - protected override IEnumerable GetPromises() - { - return Concat(onPointerDown, onPointerDowns); - } - - - void IPointerDownHandler.OnPointerDown(PointerEventData eventData) - { - TrySetResult(onPointerDown, onPointerDowns, eventData); - } - - - public UniTask OnPointerDownAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onPointerDown, ref onPointerDowns, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncPointerDownTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncPointerDownTrigger.cs.meta deleted file mode 100644 index 851cfe4..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncPointerDownTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 7c5132395605eaa498a7efedee5acdd7 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncPointerEnterTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncPointerEnterTrigger.cs deleted file mode 100644 index 179766d..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncPointerEnterTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncPointerEnterTrigger : AsyncTriggerBase, IPointerEnterHandler - { - AsyncTriggerPromise onPointerEnter; - AsyncTriggerPromiseDictionary onPointerEnters; - - - protected override IEnumerable GetPromises() - { - return Concat(onPointerEnter, onPointerEnters); - } - - - void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData) - { - TrySetResult(onPointerEnter, onPointerEnters, eventData); - } - - - public UniTask OnPointerEnterAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onPointerEnter, ref onPointerEnters, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncPointerEnterTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncPointerEnterTrigger.cs.meta deleted file mode 100644 index 9a01b93..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncPointerEnterTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 18887d476d48533498efd14224a2f651 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncPointerExitTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncPointerExitTrigger.cs deleted file mode 100644 index 4d0051e..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncPointerExitTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncPointerExitTrigger : AsyncTriggerBase, IPointerExitHandler - { - AsyncTriggerPromise onPointerExit; - AsyncTriggerPromiseDictionary onPointerExits; - - - protected override IEnumerable GetPromises() - { - return Concat(onPointerExit, onPointerExits); - } - - - void IPointerExitHandler.OnPointerExit(PointerEventData eventData) - { - TrySetResult(onPointerExit, onPointerExits, eventData); - } - - - public UniTask OnPointerExitAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onPointerExit, ref onPointerExits, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncPointerExitTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncPointerExitTrigger.cs.meta deleted file mode 100644 index 39ab381..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncPointerExitTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 9e3ed09876a11a84794795809ebee243 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncPointerUpTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncPointerUpTrigger.cs deleted file mode 100644 index 11e5d66..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncPointerUpTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncPointerUpTrigger : AsyncTriggerBase, IPointerUpHandler - { - AsyncTriggerPromise onPointerUp; - AsyncTriggerPromiseDictionary onPointerUps; - - - protected override IEnumerable GetPromises() - { - return Concat(onPointerUp, onPointerUps); - } - - - void IPointerUpHandler.OnPointerUp(PointerEventData eventData) - { - TrySetResult(onPointerUp, onPointerUps, eventData); - } - - - public UniTask OnPointerUpAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onPointerUp, ref onPointerUps, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncPointerUpTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncPointerUpTrigger.cs.meta deleted file mode 100644 index 7be4e27..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncPointerUpTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 7a0493ea32f81314cbbaf2b635ba3167 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncRectTransformTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncRectTransformTrigger.cs deleted file mode 100644 index 4fab679..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncRectTransformTrigger.cs +++ /dev/null @@ -1,55 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncRectTransformTrigger : AsyncTriggerBase - { - AsyncTriggerPromise onRectTransformDimensionsChange; - AsyncTriggerPromiseDictionary onRectTransformDimensionsChanges; - AsyncTriggerPromise onRectTransformRemoved; - AsyncTriggerPromiseDictionary onRectTransformRemoveds; - - - protected override IEnumerable GetPromises() - { - return Concat(onRectTransformDimensionsChange, onRectTransformDimensionsChanges, onRectTransformRemoved, onRectTransformRemoveds); - } - - - void OnRectTransformDimensionsChange() - { - TrySetResult(onRectTransformDimensionsChange, onRectTransformDimensionsChanges, AsyncUnit.Default); - } - - - public UniTask OnRectTransformDimensionsChangeAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onRectTransformDimensionsChange, ref onRectTransformDimensionsChanges, cancellationToken); - } - - - void OnRectTransformRemoved() - { - TrySetResult(onRectTransformRemoved, onRectTransformRemoveds, AsyncUnit.Default); - } - - - public UniTask OnRectTransformRemovedAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onRectTransformRemoved, ref onRectTransformRemoveds, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncRectTransformTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncRectTransformTrigger.cs.meta deleted file mode 100644 index 98c4f70..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncRectTransformTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: dfe3470221c66c84397c0783c62b24e7 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncScrollTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncScrollTrigger.cs deleted file mode 100644 index 6908ff9..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncScrollTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncScrollTrigger : AsyncTriggerBase, IScrollHandler - { - AsyncTriggerPromise onScroll; - AsyncTriggerPromiseDictionary onScrolls; - - - protected override IEnumerable GetPromises() - { - return Concat(onScroll, onScrolls); - } - - - void IScrollHandler.OnScroll(PointerEventData eventData) - { - TrySetResult(onScroll, onScrolls, eventData); - } - - - public UniTask OnScrollAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onScroll, ref onScrolls, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncScrollTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncScrollTrigger.cs.meta deleted file mode 100644 index 541bdbe..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncScrollTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 7c751e9d3deb97d4d8691a8a583c2afd -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncSelectTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncSelectTrigger.cs deleted file mode 100644 index ad4e99f..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncSelectTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncSelectTrigger : AsyncTriggerBase, ISelectHandler - { - AsyncTriggerPromise onSelect; - AsyncTriggerPromiseDictionary onSelects; - - - protected override IEnumerable GetPromises() - { - return Concat(onSelect, onSelects); - } - - - void ISelectHandler.OnSelect(BaseEventData eventData) - { - TrySetResult(onSelect, onSelects, eventData); - } - - - public UniTask OnSelectAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onSelect, ref onSelects, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncSelectTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncSelectTrigger.cs.meta deleted file mode 100644 index dd4563b..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncSelectTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: fcc2347251a4fc5498a03f0c17382920 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncStartTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncStartTrigger.cs index 4c65c8c..53a859e 100644 --- a/Assets/UniRx.Async/Triggers/AsyncStartTrigger.cs +++ b/Assets/UniRx.Async/Triggers/AsyncStartTrigger.cs @@ -1,16 +1,30 @@ #if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member +using System.Threading; using UnityEngine; namespace UniRx.Async.Triggers { + public static partial class AsyncTriggerExtensions + { + public static AsyncStartTrigger GetAsyncStartTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncStartTrigger GetAsyncStartTrigger(this Component component) + { + return component.gameObject.GetAsyncStartTrigger(); + } + } + [DisallowMultipleComponent] public class AsyncStartTrigger : MonoBehaviour { bool awakeCalled = false; bool called = false; - UniTaskCompletionSource promise; + TriggerEvent triggerEvent; void Awake() { @@ -20,22 +34,30 @@ namespace UniRx.Async.Triggers void Start() { called = true; - promise?.TrySetResult(); + triggerEvent?.TrySetResult(AsyncUnit.Default); + triggerEvent = null; } public UniTask StartAsync() { if (called) return UniTask.CompletedTask; + if (!awakeCalled) { PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, new AwakeMonitor(this)); } - return new UniTask(promise ?? (promise = new UniTaskCompletionSource())); + + if (triggerEvent == null) + { + triggerEvent = new TriggerEvent(); + } + + return ((IAsyncOneShotTrigger)new AsyncTriggerHandler(triggerEvent, true)).OneShotAsync(); } private void OnDestroy() { - promise?.TrySetCanceled(); + triggerEvent?.TrySetCanceled(CancellationToken.None); } class AwakeMonitor : IPlayerLoopItem @@ -49,7 +71,7 @@ namespace UniRx.Async.Triggers public bool MoveNext() { - if (trigger.awakeCalled) return false; + if (trigger.called) return false; if (trigger == null) { trigger.OnDestroy(); @@ -59,6 +81,7 @@ namespace UniRx.Async.Triggers } } } + } #endif \ No newline at end of file diff --git a/Assets/UniRx.Async/Triggers/AsyncSubmitTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncSubmitTrigger.cs deleted file mode 100644 index 22a00fa..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncSubmitTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncSubmitTrigger : AsyncTriggerBase, ISubmitHandler - { - AsyncTriggerPromise onSubmit; - AsyncTriggerPromiseDictionary onSubmits; - - - protected override IEnumerable GetPromises() - { - return Concat(onSubmit, onSubmits); - } - - - void ISubmitHandler.OnSubmit(BaseEventData eventData) - { - TrySetResult(onSubmit, onSubmits, eventData); - } - - - public UniTask OnSubmitAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onSubmit, ref onSubmits, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncSubmitTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncSubmitTrigger.cs.meta deleted file mode 100644 index 16b6b05..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncSubmitTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 97e85abc2d7ec0c44adfbe5ee971aad3 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncTransformChangedTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncTransformChangedTrigger.cs deleted file mode 100644 index acad97e..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncTransformChangedTrigger.cs +++ /dev/null @@ -1,69 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncTransformChangedTrigger : AsyncTriggerBase - { - AsyncTriggerPromise onBeforeTransformParentChanged; - AsyncTriggerPromiseDictionary onBeforeTransformParentChangeds; - AsyncTriggerPromise onTransformParentChanged; - AsyncTriggerPromiseDictionary onTransformParentChangeds; - AsyncTriggerPromise onTransformChildrenChanged; - AsyncTriggerPromiseDictionary onTransformChildrenChangeds; - - - protected override IEnumerable GetPromises() - { - return Concat(onBeforeTransformParentChanged, onBeforeTransformParentChangeds, onTransformParentChanged, onTransformParentChangeds, onTransformChildrenChanged, onTransformChildrenChangeds); - } - - - void OnBeforeTransformParentChanged() - { - TrySetResult(onBeforeTransformParentChanged, onBeforeTransformParentChangeds, AsyncUnit.Default); - } - - - public UniTask OnBeforeTransformParentChangedAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onBeforeTransformParentChanged, ref onBeforeTransformParentChangeds, cancellationToken); - } - - - void OnTransformParentChanged() - { - TrySetResult(onTransformParentChanged, onTransformParentChangeds, AsyncUnit.Default); - } - - - public UniTask OnTransformParentChangedAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onTransformParentChanged, ref onTransformParentChangeds, cancellationToken); - } - - - void OnTransformChildrenChanged() - { - TrySetResult(onTransformChildrenChanged, onTransformChildrenChangeds, AsyncUnit.Default); - } - - - public UniTask OnTransformChildrenChangedAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onTransformChildrenChanged, ref onTransformChildrenChangeds, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncTransformChangedTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncTransformChangedTrigger.cs.meta deleted file mode 100644 index 60b6c38..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncTransformChangedTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 053f983cd760f5e4394be8fd657243c1 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncTrigger2DTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncTrigger2DTrigger.cs deleted file mode 100644 index fb3cfe5..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncTrigger2DTrigger.cs +++ /dev/null @@ -1,69 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncTrigger2DTrigger : AsyncTriggerBase - { - AsyncTriggerPromise onTriggerEnter2D; - AsyncTriggerPromiseDictionary onTriggerEnter2Ds; - AsyncTriggerPromise onTriggerExit2D; - AsyncTriggerPromiseDictionary onTriggerExit2Ds; - AsyncTriggerPromise onTriggerStay2D; - AsyncTriggerPromiseDictionary onTriggerStay2Ds; - - - protected override IEnumerable GetPromises() - { - return Concat(onTriggerEnter2D, onTriggerEnter2Ds, onTriggerExit2D, onTriggerExit2Ds, onTriggerStay2D, onTriggerStay2Ds); - } - - - void OnTriggerEnter2D(Collider2D other) - { - TrySetResult(onTriggerEnter2D, onTriggerEnter2Ds, other); - } - - - public UniTask OnTriggerEnter2DAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onTriggerEnter2D, ref onTriggerEnter2Ds, cancellationToken); - } - - - void OnTriggerExit2D(Collider2D other) - { - TrySetResult(onTriggerExit2D, onTriggerExit2Ds, other); - } - - - public UniTask OnTriggerExit2DAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onTriggerExit2D, ref onTriggerExit2Ds, cancellationToken); - } - - - void OnTriggerStay2D(Collider2D other) - { - TrySetResult(onTriggerStay2D, onTriggerStay2Ds, other); - } - - - public UniTask OnTriggerStay2DAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onTriggerStay2D, ref onTriggerStay2Ds, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncTrigger2DTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncTrigger2DTrigger.cs.meta deleted file mode 100644 index 8d88bad..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncTrigger2DTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 102f8eba36bc2a54e878e67aca9686e5 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncTriggerBase.cs b/Assets/UniRx.Async/Triggers/AsyncTriggerBase.cs index a7b0d7a..a1294a6 100644 --- a/Assets/UniRx.Async/Triggers/AsyncTriggerBase.cs +++ b/Assets/UniRx.Async/Triggers/AsyncTriggerBase.cs @@ -9,202 +9,47 @@ using UnityEngine; namespace UniRx.Async.Triggers { - public interface ICancelablePromise - { - CancellationToken RegisteredCancellationToken { get; } - bool TrySetCanceled(); - } - - - public interface ICancellationTokenKeyDictionary - { - void Remove(CancellationToken token); - } - - public class AsyncTriggerPromiseDictionary : - Dictionary>, - ICancellationTokenKeyDictionary, - IEnumerable - { - public AsyncTriggerPromiseDictionary() - : base(CancellationTokenEqualityComparer.Default) - { - } - - IEnumerator IEnumerable.GetEnumerator() - { - // TODO: - throw new NotImplementedException(); - //return Values.GetEnumerator(); - } - - void ICancellationTokenKeyDictionary.Remove(CancellationToken token) - { - this.Remove(token); - } - } - public abstract class AsyncTriggerBase : MonoBehaviour { - static readonly Action Callback = CancelCallback; - - bool calledAwake = false; - bool destroyCalled = false; - CancellationTokenRegistration[] registeredCancellations; - int registeredCancellationsCount; - - protected abstract IEnumerable GetPromises(); - - static protected IEnumerable Concat(ICancelablePromise p1, IEnumerable p1s) - { - if (p1 != null) yield return p1; - if (p1s != null) foreach (var item in p1s) yield return item; - } - - static protected IEnumerable Concat( - ICancelablePromise p1, IEnumerable p1s, - ICancelablePromise p2, IEnumerable p2s) - { - if (p1 != null) yield return p1; - if (p1s != null) foreach (var item in p1s) yield return item; - if (p2 != null) yield return p2; - if (p2s != null) foreach (var item in p2s) yield return item; - } - - static protected IEnumerable Concat( - ICancelablePromise p1, IEnumerable p1s, - ICancelablePromise p2, IEnumerable p2s, - ICancelablePromise p3, IEnumerable p3s) - { - if (p1 != null) yield return p1; - if (p1s != null) foreach (var item in p1s) yield return item; - if (p2 != null) yield return p2; - if (p2s != null) foreach (var item in p2s) yield return item; - if (p3 != null) yield return p3; - if (p3s != null) foreach (var item in p3s) yield return item; - } - - static protected IEnumerable Concat( - ICancelablePromise p1, IEnumerable p1s, - ICancelablePromise p2, IEnumerable p2s, - ICancelablePromise p3, IEnumerable p3s, - ICancelablePromise p4, IEnumerable p4s) - { - if (p1 != null) yield return p1; - if (p1s != null) foreach (var item in p1s) yield return item; - if (p2 != null) yield return p2; - if (p2s != null) foreach (var item in p2s) yield return item; - if (p3 != null) yield return p3; - if (p3s != null) foreach (var item in p3s) yield return item; - if (p4 != null) yield return p4; - if (p4s != null) foreach (var item in p4s) yield return item; - } - - // otherwise... - static protected IEnumerable Concat(params object[] promises) - { - foreach (var item in promises) - { - if (item is ICancelablePromise p) - { - yield return p; - } - else if (item is IEnumerable ps) - { - foreach (var p2 in ps) - { - yield return p2; - } - } - } - } - - protected UniTask GetOrAddPromise(ref AsyncTriggerPromise promise, ref AsyncTriggerPromiseDictionary promises, CancellationToken cancellationToken) - { - if (destroyCalled) return UniTask.FromCanceled(); - - if (!cancellationToken.CanBeCanceled) - { - if (promise == null) - { - promise = new AsyncTriggerPromise(); - if (!calledAwake) - { - PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, new AwakeMonitor(this)); - } - } - return promise.Task; - } - - if (promises == null) promises = new AsyncTriggerPromiseDictionary(); - - if (promises.TryGetValue(cancellationToken, out var cancellablePromise)) - { - return cancellablePromise.Task; - } - - cancellablePromise = new AsyncTriggerPromise(); - promises.Add(cancellationToken, cancellablePromise); - if (!calledAwake) - { - PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, new AwakeMonitor(this)); - } - - var registrationToken = cancellationToken.RegisterWithoutCaptureExecutionContext(Callback, Tuple.Create((ICancellationTokenKeyDictionary)promises, (ICancelablePromise)cancellablePromise)); - if (registeredCancellations == null) - { - registeredCancellations = ArrayPool.Shared.Rent(4); - } - ArrayPoolUtil.EnsureCapacity(ref registeredCancellations, registeredCancellationsCount + 1, ArrayPool.Shared); - registeredCancellations[registeredCancellationsCount++] = registrationToken; - - return cancellablePromise.Task; - } - - static void CancelCallback(object state) - { - var tuple = (Tuple)state; - var dict = tuple.Item1; - var promise = tuple.Item2; - - promise.TrySetCanceled(); - dict.Remove(promise.RegisteredCancellationToken); - } - - protected void TrySetResult(ReusablePromise promise, AsyncTriggerPromiseDictionary promises, T value) - { - if (promise != null) - { - promise.TrySetResult(value); - } - if (promises != null) - { - PromiseHelper.TrySetResultAll(promises.Values, value); - } - } + bool calledAwake; + bool calledDestroy; + ICancelPromise triggerSlot; void Awake() { calledAwake = true; } + protected TriggerEvent SetTriggerEvent(ref TriggerEvent field) + { + if (field == null) + { + field = new TriggerEvent(); + if (triggerSlot == null) + { + triggerSlot = field; + } + else + { + throw new InvalidOperationException("triggerSlot is already filled."); + } + } + + if (!calledAwake) + { + PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, new AwakeMonitor(this)); + } + + return field; + } + void OnDestroy() { - if (destroyCalled) return; - destroyCalled = true; - foreach (var item in GetPromises()) - { - item.TrySetCanceled(); - } - if (registeredCancellations != null) - { - for (int i = 0; i < registeredCancellationsCount; i++) - { - registeredCancellations[i].Dispose(); - registeredCancellations[i] = default(CancellationTokenRegistration); - } - ArrayPool.Shared.Return(registeredCancellations); - } + if (calledDestroy) return; + calledDestroy = true; + + triggerSlot?.TrySetCanceled(); + triggerSlot = null; } class AwakeMonitor : IPlayerLoopItem @@ -228,6 +73,313 @@ namespace UniRx.Async.Triggers } } } + + public interface IAsyncOneShotTrigger + { + UniTask OneShotAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOneShotTrigger + { + UniTask IAsyncOneShotTrigger.OneShotAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)this, core.Version); + } + } + + public sealed partial class AsyncTriggerHandler : IUniTaskSource, IResolvePromise, ICancelPromise, IDisposable + { + static Action cancellationCallback = CancellationCallback; + + readonly TriggerEvent trigger; + + CancellationToken cancellationToken; + CancellationTokenRegistration registration; + bool isDisposed; + bool callOnce; + + UniTaskCompletionSourceCore core; + + internal CancellationToken CancellationToken => cancellationToken; + + public AsyncTriggerHandler(TriggerEvent trigger, bool callOnce) + { + if (cancellationToken.IsCancellationRequested) + { + isDisposed = true; + return; + } + + this.trigger = trigger; + this.cancellationToken = default; + this.registration = default; + this.callOnce = callOnce; + + trigger.Add(this); + + TaskTracker.TrackActiveTask(this, 3); + } + + public AsyncTriggerHandler(TriggerEvent trigger, CancellationToken cancellationToken, bool callOnce) + { + if (cancellationToken.IsCancellationRequested) + { + isDisposed = true; + return; + } + + this.trigger = trigger; + this.cancellationToken = cancellationToken; + this.callOnce = callOnce; + + trigger.Add(this); + + if (cancellationToken.CanBeCanceled) + { + registration = cancellationToken.RegisterWithoutCaptureExecutionContext(cancellationCallback, this); + } + + TaskTracker.TrackActiveTask(this, 3); + } + + static void CancellationCallback(object state) + { + var self = (AsyncTriggerHandler)state; + self.Dispose(); + + self.core.TrySetCanceled(self.cancellationToken); + } + + public void Dispose() + { + if (!isDisposed) + { + isDisposed = true; + TaskTracker.RemoveTracking(this); + registration.Dispose(); + trigger.Remove(this); + } + } + + T IUniTaskSource.GetResult(short token) + { + try + { + return core.GetResult(token); + } + finally + { + if (callOnce) + { + Dispose(); + } + } + } + + bool IResolvePromise.TrySetResult(T result) + { + return core.TrySetResult(result); + } + + bool ICancelPromise.TrySetCanceled(CancellationToken cancellationToken) + { + return core.TrySetCanceled(cancellationToken); + } + + void IUniTaskSource.GetResult(short token) + { + ((IUniTaskSource)this).GetResult(token); + } + + UniTaskStatus IUniTaskSource.GetStatus(short token) + { + return core.GetStatus(token); + } + + UniTaskStatus IUniTaskSource.UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + void IUniTaskSource.OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + } + + public sealed class TriggerEvent : IResolvePromise, ICancelPromise + { + // optimize: many cases, handler is single. + AsyncTriggerHandler singleHandler; + + List> handlers; + + public bool TrySetResult(T value) + { + List exceptions = null; + + if (singleHandler != null) + { + try + { + ((IResolvePromise)singleHandler).TrySetResult(value); + } + catch (Exception ex) + { + if (handlers == null) + { + throw; + } + else + { + exceptions = new List(); + exceptions.Add(ex); + } + } + } + + if (handlers != null) + { + // make snapshot + var rentArray = ArrayPoolUtil.CopyToRentArray(handlers); + var clearArray = true; + try + { + var array = rentArray.Array; + var len = rentArray.Length; + for (int i = 0; i < len; i++) + { + try + { + ((IResolvePromise)array[i]).TrySetResult(value); + } + catch (Exception ex) + { + if (exceptions == null) + { + exceptions = new List(); + } + exceptions.Add(ex); + } + finally + { + array[i] = null; + } + } + } + finally + { + rentArray.DisposeManually(clearArray); + } + } + + if (exceptions != null) + { + throw new AggregateException(exceptions); + } + + return true; + } + + public bool TrySetCanceled(CancellationToken cancellationToken) + { + List exceptions = null; + + if (singleHandler != null) + { + try + { + ((ICancelPromise)singleHandler).TrySetCanceled(cancellationToken); + } + catch (Exception ex) + { + if (handlers == null) + { + throw; + } + else + { + exceptions = new List(); + exceptions.Add(ex); + } + } + } + + if (handlers != null) + { + // make snapshot + var rentArray = ArrayPoolUtil.CopyToRentArray(handlers); + var clearArray = true; + try + { + var array = rentArray.Array; + var len = rentArray.Length; + for (int i = 0; i < len; i++) + { + try + { + ((ICancelPromise)array[i]).TrySetCanceled(cancellationToken); + } + catch (Exception ex) + { + if (exceptions == null) + { + exceptions = new List(); + } + exceptions.Add(ex); + } + finally + { + array[i] = null; + } + } + } + finally + { + rentArray.DisposeManually(clearArray); + } + } + + if (exceptions != null) + { + throw new AggregateException(exceptions); + } + + return true; + } + + public void Add(AsyncTriggerHandler handler) + { + if (singleHandler == null) + { + singleHandler = handler; + } + else + { + if (handlers != null) + { + handlers = new List>(); + handlers.Add(handler); + } + } + } + + public void Remove(AsyncTriggerHandler handler) + { + if (singleHandler == handler) + { + singleHandler = null; + } + else + { + if (handlers != null) + { + handlers.Remove(handler); + } + } + } + } } #endif \ No newline at end of file diff --git a/Assets/UniRx.Async/Triggers/AsyncTriggerExtensions.cs b/Assets/UniRx.Async/Triggers/AsyncTriggerExtensions.cs index e3dab78..8516cd9 100644 --- a/Assets/UniRx.Async/Triggers/AsyncTriggerExtensions.cs +++ b/Assets/UniRx.Async/Triggers/AsyncTriggerExtensions.cs @@ -25,7 +25,7 @@ namespace UniRx.Async namespace UniRx.Async.Triggers { - public static class AsyncTriggerExtensions + public static partial class AsyncTriggerExtensions { // Util. @@ -74,444 +74,6 @@ namespace UniRx.Async.Triggers { return component.GetAsyncAwakeTrigger().AwakeAsync(); } - - // Get Triggers. - - /// Get for OnAnimatorIKAsync | OnAnimatorMoveAsync. - public static AsyncAnimatorTrigger GetAsyncAnimatorTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnAnimatorIKAsync | OnAnimatorMoveAsync. - public static AsyncAnimatorTrigger GetAsyncAnimatorTrigger(this Component component) - { - return component.gameObject.GetAsyncAnimatorTrigger(); - } - - /// Get for AwakeAsync. - public static AsyncAwakeTrigger GetAsyncAwakeTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for AwakeAsync. - public static AsyncAwakeTrigger GetAsyncAwakeTrigger(this Component component) - { - return component.gameObject.GetAsyncAwakeTrigger(); - } - - /// Get for OnBeginDragAsync. - public static AsyncBeginDragTrigger GetAsyncBeginDragTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnBeginDragAsync. - public static AsyncBeginDragTrigger GetAsyncBeginDragTrigger(this Component component) - { - return component.gameObject.GetAsyncBeginDragTrigger(); - } - - /// Get for OnCancelAsync. - public static AsyncCancelTrigger GetAsyncCancelTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnCancelAsync. - public static AsyncCancelTrigger GetAsyncCancelTrigger(this Component component) - { - return component.gameObject.GetAsyncCancelTrigger(); - } - - /// Get for OnCanvasGroupChangedAsync. - public static AsyncCanvasGroupChangedTrigger GetAsyncCanvasGroupChangedTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnCanvasGroupChangedAsync. - public static AsyncCanvasGroupChangedTrigger GetAsyncCanvasGroupChangedTrigger(this Component component) - { - return component.gameObject.GetAsyncCanvasGroupChangedTrigger(); - } - - /// Get for OnCollisionEnter2DAsync | OnCollisionExit2DAsync | OnCollisionStay2DAsync. - public static AsyncCollision2DTrigger GetAsyncCollision2DTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnCollisionEnter2DAsync | OnCollisionExit2DAsync | OnCollisionStay2DAsync. - public static AsyncCollision2DTrigger GetAsyncCollision2DTrigger(this Component component) - { - return component.gameObject.GetAsyncCollision2DTrigger(); - } - - /// Get for OnCollisionEnterAsync | OnCollisionExitAsync | OnCollisionStayAsync. - public static AsyncCollisionTrigger GetAsyncCollisionTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnCollisionEnterAsync | OnCollisionExitAsync | OnCollisionStayAsync. - public static AsyncCollisionTrigger GetAsyncCollisionTrigger(this Component component) - { - return component.gameObject.GetAsyncCollisionTrigger(); - } - - /// Get for OnDeselectAsync. - public static AsyncDeselectTrigger GetAsyncDeselectTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnDeselectAsync. - public static AsyncDeselectTrigger GetAsyncDeselectTrigger(this Component component) - { - return component.gameObject.GetAsyncDeselectTrigger(); - } - - /// Get for OnDestroyAsync. - public static AsyncDestroyTrigger GetAsyncDestroyTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnDestroyAsync. - public static AsyncDestroyTrigger GetAsyncDestroyTrigger(this Component component) - { - return component.gameObject.GetAsyncDestroyTrigger(); - } - - /// Get for OnDragAsync. - public static AsyncDragTrigger GetAsyncDragTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnDragAsync. - public static AsyncDragTrigger GetAsyncDragTrigger(this Component component) - { - return component.gameObject.GetAsyncDragTrigger(); - } - - /// Get for OnDropAsync. - public static AsyncDropTrigger GetAsyncDropTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnDropAsync. - public static AsyncDropTrigger GetAsyncDropTrigger(this Component component) - { - return component.gameObject.GetAsyncDropTrigger(); - } - - /// Get for OnEnableAsync | OnDisableAsync. - public static AsyncEnableDisableTrigger GetAsyncEnableDisableTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnEnableAsync | OnDisableAsync. - public static AsyncEnableDisableTrigger GetAsyncEnableDisableTrigger(this Component component) - { - return component.gameObject.GetAsyncEnableDisableTrigger(); - } - - /// Get for OnEndDragAsync. - public static AsyncEndDragTrigger GetAsyncEndDragTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnEndDragAsync. - public static AsyncEndDragTrigger GetAsyncEndDragTrigger(this Component component) - { - return component.gameObject.GetAsyncEndDragTrigger(); - } - - /// Get for FixedUpdateAsync. - public static AsyncFixedUpdateTrigger GetAsyncFixedUpdateTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for FixedUpdateAsync. - public static AsyncFixedUpdateTrigger GetAsyncFixedUpdateTrigger(this Component component) - { - return component.gameObject.GetAsyncFixedUpdateTrigger(); - } - - /// Get for OnInitializePotentialDragAsync. - public static AsyncInitializePotentialDragTrigger GetAsyncInitializePotentialDragTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnInitializePotentialDragAsync. - public static AsyncInitializePotentialDragTrigger GetAsyncInitializePotentialDragTrigger(this Component component) - { - return component.gameObject.GetAsyncInitializePotentialDragTrigger(); - } - - /// Get for OnJointBreakAsync. - public static AsyncJointTrigger GetAsyncJointTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnJointBreakAsync. - public static AsyncJointTrigger GetAsyncJointTrigger(this Component component) - { - return component.gameObject.GetAsyncJointTrigger(); - } - - /// Get for LateUpdateAsync. - public static AsyncLateUpdateTrigger GetAsyncLateUpdateTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for LateUpdateAsync. - public static AsyncLateUpdateTrigger GetAsyncLateUpdateTrigger(this Component component) - { - return component.gameObject.GetAsyncLateUpdateTrigger(); - } - -#if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO) - - /// Get for OnMouseDownAsync | OnMouseDragAsync | OnMouseEnterAsync | OnMouseExitAsync | OnMouseOverAsync | OnMouseUpAsync | OnMouseUpAsButtonAsync. - public static AsyncMouseTrigger GetAsyncMouseTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnMouseDownAsync | OnMouseDragAsync | OnMouseEnterAsync | OnMouseExitAsync | OnMouseOverAsync | OnMouseUpAsync | OnMouseUpAsButtonAsync. - public static AsyncMouseTrigger GetAsyncMouseTrigger(this Component component) - { - return component.gameObject.GetAsyncMouseTrigger(); - } - -#endif - - /// Get for OnMoveAsync. - public static AsyncMoveTrigger GetAsyncMoveTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnMoveAsync. - public static AsyncMoveTrigger GetAsyncMoveTrigger(this Component component) - { - return component.gameObject.GetAsyncMoveTrigger(); - } - - /// Get for OnParticleCollisionAsync | OnParticleTriggerAsync. - public static AsyncParticleTrigger GetAsyncParticleTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnParticleCollisionAsync | OnParticleTriggerAsync. - public static AsyncParticleTrigger GetAsyncParticleTrigger(this Component component) - { - return component.gameObject.GetAsyncParticleTrigger(); - } - - /// Get for OnPointerClickAsync. - public static AsyncPointerClickTrigger GetAsyncPointerClickTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnPointerClickAsync. - public static AsyncPointerClickTrigger GetAsyncPointerClickTrigger(this Component component) - { - return component.gameObject.GetAsyncPointerClickTrigger(); - } - - /// Get for OnPointerDownAsync. - public static AsyncPointerDownTrigger GetAsyncPointerDownTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnPointerDownAsync. - public static AsyncPointerDownTrigger GetAsyncPointerDownTrigger(this Component component) - { - return component.gameObject.GetAsyncPointerDownTrigger(); - } - - /// Get for OnPointerEnterAsync. - public static AsyncPointerEnterTrigger GetAsyncPointerEnterTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnPointerEnterAsync. - public static AsyncPointerEnterTrigger GetAsyncPointerEnterTrigger(this Component component) - { - return component.gameObject.GetAsyncPointerEnterTrigger(); - } - - /// Get for OnPointerExitAsync. - public static AsyncPointerExitTrigger GetAsyncPointerExitTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnPointerExitAsync. - public static AsyncPointerExitTrigger GetAsyncPointerExitTrigger(this Component component) - { - return component.gameObject.GetAsyncPointerExitTrigger(); - } - - /// Get for OnPointerUpAsync. - public static AsyncPointerUpTrigger GetAsyncPointerUpTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnPointerUpAsync. - public static AsyncPointerUpTrigger GetAsyncPointerUpTrigger(this Component component) - { - return component.gameObject.GetAsyncPointerUpTrigger(); - } - - /// Get for OnRectTransformDimensionsChange | OnRectTransformDimensionsChangeAsync | OnRectTransformRemoved | OnRectTransformRemovedAsync. - public static AsyncRectTransformTrigger GetAsyncRectTransformTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnRectTransformDimensionsChange | OnRectTransformDimensionsChangeAsync | OnRectTransformRemoved | OnRectTransformRemovedAsync. - public static AsyncRectTransformTrigger GetAsyncRectTransformTrigger(this Component component) - { - return component.gameObject.GetAsyncRectTransformTrigger(); - } - - /// Get for OnScrollAsync. - public static AsyncScrollTrigger GetAsyncScrollTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnScrollAsync. - public static AsyncScrollTrigger GetAsyncScrollTrigger(this Component component) - { - return component.gameObject.GetAsyncScrollTrigger(); - } - - /// Get for OnSelectAsync. - public static AsyncSelectTrigger GetAsyncSelectTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnSelectAsync. - public static AsyncSelectTrigger GetAsyncSelectTrigger(this Component component) - { - return component.gameObject.GetAsyncSelectTrigger(); - } - - /// Get for StartAsync. - public static AsyncStartTrigger GetAsyncStartTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for StartAsync. - public static AsyncStartTrigger GetAsyncStartTrigger(this Component component) - { - return component.gameObject.GetAsyncStartTrigger(); - } - - /// Get for OnSubmitAsync. - public static AsyncSubmitTrigger GetAsyncSubmitTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnSubmitAsync. - public static AsyncSubmitTrigger GetAsyncSubmitTrigger(this Component component) - { - return component.gameObject.GetAsyncSubmitTrigger(); - } - - /// Get for OnBeforeTransformParentChangedAsync | OnTransformParentChangedAsync | OnTransformChildrenChangedAsync. - public static AsyncTransformChangedTrigger GetAsyncTransformChangedTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnBeforeTransformParentChangedAsync | OnTransformParentChangedAsync | OnTransformChildrenChangedAsync. - public static AsyncTransformChangedTrigger GetAsyncTransformChangedTrigger(this Component component) - { - return component.gameObject.GetAsyncTransformChangedTrigger(); - } - - /// Get for OnTriggerEnter2DAsync | OnTriggerExit2DAsync | OnTriggerStay2DAsync. - public static AsyncTrigger2DTrigger GetAsyncTrigger2DTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnTriggerEnter2DAsync | OnTriggerExit2DAsync | OnTriggerStay2DAsync. - public static AsyncTrigger2DTrigger GetAsyncTrigger2DTrigger(this Component component) - { - return component.gameObject.GetAsyncTrigger2DTrigger(); - } - - /// Get for OnTriggerEnterAsync | OnTriggerExitAsync | OnTriggerStayAsync. - public static AsyncTriggerTrigger GetAsyncTriggerTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnTriggerEnterAsync | OnTriggerExitAsync | OnTriggerStayAsync. - public static AsyncTriggerTrigger GetAsyncTriggerTrigger(this Component component) - { - return component.gameObject.GetAsyncTriggerTrigger(); - } - - /// Get for OnUpdateSelectedAsync. - public static AsyncUpdateSelectedTrigger GetAsyncUpdateSelectedTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnUpdateSelectedAsync. - public static AsyncUpdateSelectedTrigger GetAsyncUpdateSelectedTrigger(this Component component) - { - return component.gameObject.GetAsyncUpdateSelectedTrigger(); - } - - /// Get for UpdateAsync. - public static AsyncUpdateTrigger GetAsyncUpdateTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for UpdateAsync. - public static AsyncUpdateTrigger GetAsyncUpdateTrigger(this Component component) - { - return component.gameObject.GetAsyncUpdateTrigger(); - } - - /// Get for OnBecameInvisibleAsync | OnBecameVisibleAsync. - public static AsyncVisibleTrigger GetAsyncVisibleTrigger(this GameObject gameObject) - { - return GetOrAddComponent(gameObject); - } - - /// Get for OnBecameInvisibleAsync | OnBecameVisibleAsync. - public static AsyncVisibleTrigger GetAsyncVisibleTrigger(this Component component) - { - return component.gameObject.GetAsyncVisibleTrigger(); - } } } diff --git a/Assets/UniRx.Async/Triggers/AsyncTriggerTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncTriggerTrigger.cs deleted file mode 100644 index 8ee5d62..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncTriggerTrigger.cs +++ /dev/null @@ -1,69 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncTriggerTrigger : AsyncTriggerBase - { - AsyncTriggerPromise onTriggerEnter; - AsyncTriggerPromiseDictionary onTriggerEnters; - AsyncTriggerPromise onTriggerExit; - AsyncTriggerPromiseDictionary onTriggerExits; - AsyncTriggerPromise onTriggerStay; - AsyncTriggerPromiseDictionary onTriggerStays; - - - protected override IEnumerable GetPromises() - { - return Concat(onTriggerEnter, onTriggerEnters, onTriggerExit, onTriggerExits, onTriggerStay, onTriggerStays); - } - - - void OnTriggerEnter(Collider other) - { - TrySetResult(onTriggerEnter, onTriggerEnters, other); - } - - - public UniTask OnTriggerEnterAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onTriggerEnter, ref onTriggerEnters, cancellationToken); - } - - - void OnTriggerExit(Collider other) - { - TrySetResult(onTriggerExit, onTriggerExits, other); - } - - - public UniTask OnTriggerExitAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onTriggerExit, ref onTriggerExits, cancellationToken); - } - - - void OnTriggerStay(Collider other) - { - TrySetResult(onTriggerStay, onTriggerStays, other); - } - - - public UniTask OnTriggerStayAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onTriggerStay, ref onTriggerStays, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncTriggerTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncTriggerTrigger.cs.meta deleted file mode 100644 index b9f7efb..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncTriggerTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 46bbbbaa910762c4786906e10b6b7b8e -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncUpdateSelectedTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncUpdateSelectedTrigger.cs deleted file mode 100644 index 025242c..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncUpdateSelectedTrigger.cs +++ /dev/null @@ -1,41 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncUpdateSelectedTrigger : AsyncTriggerBase, IUpdateSelectedHandler - { - AsyncTriggerPromise onUpdateSelected; - AsyncTriggerPromiseDictionary onUpdateSelecteds; - - - protected override IEnumerable GetPromises() - { - return Concat(onUpdateSelected, onUpdateSelecteds); - } - - - void IUpdateSelectedHandler.OnUpdateSelected(BaseEventData eventData) - { - TrySetResult(onUpdateSelected, onUpdateSelecteds, eventData); - } - - - public UniTask OnUpdateSelectedAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onUpdateSelected, ref onUpdateSelecteds, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncUpdateSelectedTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncUpdateSelectedTrigger.cs.meta deleted file mode 100644 index 395b43c..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncUpdateSelectedTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: ba5b0a4234e164e41b85f10b709d72e9 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncUpdateTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncUpdateTrigger.cs deleted file mode 100644 index 20df476..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncUpdateTrigger.cs +++ /dev/null @@ -1,200 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using UniRx.Async.Internal; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncUpdateTrigger : AsyncTriggerBase - { - AsyncTriggerPromise update; - AsyncTriggerPromiseDictionary updates; - - - protected override IEnumerable GetPromises() - { - return Concat(update, updates); - } - - - void Update() - { - TrySetResult(update, updates, AsyncUnit.Default); - } - - - public UniTask UpdateAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref update, ref updates, cancellationToken); - } - - - } - - - - // TODO:remove 2. - public abstract class AsyncTriggerBase2 : MonoBehaviour - { - static readonly Action Callback = CancelCallback; - - bool calledAwake = false; - bool destroyCalled = false; - CancellationTokenRegistration[] registeredCancellations; - int registeredCancellationsCount; - - protected abstract IEnumerable GetPromises(); - - void Awake() - { - calledAwake = true; - } - - void OnDestroy() - { - if (destroyCalled) return; - destroyCalled = true; - foreach (var item in GetPromises()) - { - item.TrySetCanceled(); - } - if (registeredCancellations != null) - { - for (int i = 0; i < registeredCancellationsCount; i++) - { - registeredCancellations[i].Dispose(); - registeredCancellations[i] = default(CancellationTokenRegistration); - } - ArrayPool.Shared.Return(registeredCancellations); - } - } - - protected void TrySetResult(MinimumQueue> promise, AsyncTriggerPromiseDictionary promises, T result) - { - if (promise != null) - { - // TODO: - } - - if (promises != null) - { - PromiseHelper.TrySetResultAll(promises.Values, result); - } - } - - public UniTask CreatePromise(ref MinimumQueue> promise, ref AsyncTriggerPromiseDictionary promises, CancellationToken cancellationToken) - { - if (destroyCalled) return UniTask.FromCanceled(); - - if (!calledAwake) - { - PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, new AwakeMonitor(this)); - } - - if (!cancellationToken.CanBeCanceled) - { - if (promise == null) - { - promise = new MinimumQueue>(4); // kakko kari.(ArrayPool?) - } - - var tcs = AutoResetUniTaskCompletionSource.Create(); - promise.Enqueue(tcs); - return tcs.Task; - } - - - CancellationTokenRegistration registrationToken = default; - // TODO:atode. - // var registrationToken = cancellationToken.RegisterWithoutCaptureExecutionContext(Callback, Tuple.Create((ICancellationTokenKeyDictionary)promises, (ICancelablePromise)cancellablePromise)); - if (registeredCancellations == null) - { - registeredCancellations = ArrayPool.Shared.Rent(4); - } - - ArrayPoolUtil.EnsureCapacity(ref registeredCancellations, registeredCancellationsCount + 1, ArrayPool.Shared); - registeredCancellations[registeredCancellationsCount++] = registrationToken; - - // TODO:use at registration - { - if (promises == null) - { - promises = new AsyncTriggerPromiseDictionary(); - } - - var tcs = AutoResetUniTaskCompletionSource.Create(); - promises.Add(cancellationToken, tcs); - return tcs.Task; - } - } - - static void CancelCallback(object state) - { - // TODO:nantokasuru. - - //var tuple = (Tuple)state; - //var dict = tuple.Item1; - //var promise = tuple.Item2; - - //promise.TrySetCanceled(); - //dict.Remove(promise.RegisteredCancellationToken); - } - - class AwakeMonitor : IPlayerLoopItem - { - readonly AsyncTriggerBase2 trigger; - - public AwakeMonitor(AsyncTriggerBase2 trigger) - { - this.trigger = trigger; - } - - public bool MoveNext() - { - if (trigger.calledAwake) return false; - if (trigger == null) - { - trigger.OnDestroy(); - return false; - } - return true; - } - } - } - - - // TODO:remove 2. - [DisallowMultipleComponent] - public class AsyncUpdateTrigger2 : AsyncTriggerBase2 - { - MinimumQueue> promise; - AsyncTriggerPromiseDictionary promises; - - protected override IEnumerable GetPromises() - { - // TODO: - throw new NotImplementedException(); - } - - void Update() - { - // TrySetResult - } - - public UniTask UpdateAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return CreatePromise(ref promise, ref promises, cancellationToken).AsUniTask(); - } - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncUpdateTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncUpdateTrigger.cs.meta deleted file mode 100644 index d2277f7..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncUpdateTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: c6053bbe25af0d6439712f7c5fc4afc7 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/AsyncVisibleTrigger.cs b/Assets/UniRx.Async/Triggers/AsyncVisibleTrigger.cs deleted file mode 100644 index df9596e..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncVisibleTrigger.cs +++ /dev/null @@ -1,55 +0,0 @@ - -#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - -using System.Collections.Generic; -using System.Threading; -using UnityEngine; -using UnityEngine.EventSystems; - -namespace UniRx.Async.Triggers -{ - [DisallowMultipleComponent] - public class AsyncVisibleTrigger : AsyncTriggerBase - { - AsyncTriggerPromise onBecameInvisible; - AsyncTriggerPromiseDictionary onBecameInvisibles; - AsyncTriggerPromise onBecameVisible; - AsyncTriggerPromiseDictionary onBecameVisibles; - - - protected override IEnumerable GetPromises() - { - return Concat(onBecameInvisible, onBecameInvisibles, onBecameVisible, onBecameVisibles); - } - - - void OnBecameInvisible() - { - TrySetResult(onBecameInvisible, onBecameInvisibles, AsyncUnit.Default); - } - - - public UniTask OnBecameInvisibleAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onBecameInvisible, ref onBecameInvisibles, cancellationToken); - } - - - void OnBecameVisible() - { - TrySetResult(onBecameVisible, onBecameVisibles, AsyncUnit.Default); - } - - - public UniTask OnBecameVisibleAsync(CancellationToken cancellationToken = default(CancellationToken)) - { - return GetOrAddPromise(ref onBecameVisible, ref onBecameVisibles, cancellationToken); - } - - - } -} - -#endif - diff --git a/Assets/UniRx.Async/Triggers/AsyncVisibleTrigger.cs.meta b/Assets/UniRx.Async/Triggers/AsyncVisibleTrigger.cs.meta deleted file mode 100644 index 24b33ec..0000000 --- a/Assets/UniRx.Async/Triggers/AsyncVisibleTrigger.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 57ebfef2a87c49c46ad6454db136f3ef -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniRx.Async/Triggers/MonoBehaviourMessagesTriggers.cs b/Assets/UniRx.Async/Triggers/MonoBehaviourMessagesTriggers.cs new file mode 100644 index 0000000..1eb35a8 --- /dev/null +++ b/Assets/UniRx.Async/Triggers/MonoBehaviourMessagesTriggers.cs @@ -0,0 +1,4525 @@ +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member + +using System.Threading; +using UnityEngine; +using UnityEngine.EventSystems; + +namespace UniRx.Async.Triggers +{ +#region FixedUpdate + + public interface IAsyncFixedUpdateHandler + { + UniTask FixedUpdateAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncFixedUpdateHandler + { + UniTask IAsyncFixedUpdateHandler.FixedUpdateAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncFixedUpdateTrigger GetAsyncFixedUpdateTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncFixedUpdateTrigger GetAsyncFixedUpdateTrigger(this Component component) + { + return component.gameObject.GetAsyncFixedUpdateTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncFixedUpdateTrigger : AsyncTriggerBase + { + TriggerEvent fixedUpdateTriggerEvent; + + void FixedUpdate() + { + fixedUpdateTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncFixedUpdateHandler GetFixedUpdateAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref fixedUpdateTriggerEvent), false); + } + + public IAsyncFixedUpdateHandler GetFixedUpdateAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref fixedUpdateTriggerEvent), cancellationToken, false); + } + + public UniTask FixedUpdateAsync() + { + return ((IAsyncFixedUpdateHandler)new AsyncTriggerHandler(SetTriggerEvent(ref fixedUpdateTriggerEvent), true)).FixedUpdateAsync(); + } + + public UniTask FixedUpdateAsync(CancellationToken cancellationToken) + { + return ((IAsyncFixedUpdateHandler)new AsyncTriggerHandler(SetTriggerEvent(ref fixedUpdateTriggerEvent), cancellationToken, true)).FixedUpdateAsync(); + } + } +#endregion + +#region LateUpdate + + public interface IAsyncLateUpdateHandler + { + UniTask LateUpdateAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncLateUpdateHandler + { + UniTask IAsyncLateUpdateHandler.LateUpdateAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncLateUpdateTrigger GetAsyncLateUpdateTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncLateUpdateTrigger GetAsyncLateUpdateTrigger(this Component component) + { + return component.gameObject.GetAsyncLateUpdateTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncLateUpdateTrigger : AsyncTriggerBase + { + TriggerEvent lateUpdateTriggerEvent; + + void LateUpdate() + { + lateUpdateTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncLateUpdateHandler GetLateUpdateAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref lateUpdateTriggerEvent), false); + } + + public IAsyncLateUpdateHandler GetLateUpdateAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref lateUpdateTriggerEvent), cancellationToken, false); + } + + public UniTask LateUpdateAsync() + { + return ((IAsyncLateUpdateHandler)new AsyncTriggerHandler(SetTriggerEvent(ref lateUpdateTriggerEvent), true)).LateUpdateAsync(); + } + + public UniTask LateUpdateAsync(CancellationToken cancellationToken) + { + return ((IAsyncLateUpdateHandler)new AsyncTriggerHandler(SetTriggerEvent(ref lateUpdateTriggerEvent), cancellationToken, true)).LateUpdateAsync(); + } + } +#endregion + +#region AnimatorIK + + public interface IAsyncOnAnimatorIKHandler + { + UniTask OnAnimatorIKAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnAnimatorIKHandler + { + UniTask IAsyncOnAnimatorIKHandler.OnAnimatorIKAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncAnimatorIKTrigger GetAsyncAnimatorIKTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncAnimatorIKTrigger GetAsyncAnimatorIKTrigger(this Component component) + { + return component.gameObject.GetAsyncAnimatorIKTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncAnimatorIKTrigger : AsyncTriggerBase + { + TriggerEvent onAnimatorIKTriggerEvent; + + void OnAnimatorIK(int layerIndex) + { + onAnimatorIKTriggerEvent?.TrySetResult((layerIndex)); + } + + public IAsyncOnAnimatorIKHandler GetOnAnimatorIKAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onAnimatorIKTriggerEvent), false); + } + + public IAsyncOnAnimatorIKHandler GetOnAnimatorIKAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onAnimatorIKTriggerEvent), cancellationToken, false); + } + + public UniTask OnAnimatorIKAsync() + { + return ((IAsyncOnAnimatorIKHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onAnimatorIKTriggerEvent), true)).OnAnimatorIKAsync(); + } + + public UniTask OnAnimatorIKAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnAnimatorIKHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onAnimatorIKTriggerEvent), cancellationToken, true)).OnAnimatorIKAsync(); + } + } +#endregion + +#region AnimatorMove + + public interface IAsyncOnAnimatorMoveHandler + { + UniTask OnAnimatorMoveAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnAnimatorMoveHandler + { + UniTask IAsyncOnAnimatorMoveHandler.OnAnimatorMoveAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncAnimatorMoveTrigger GetAsyncAnimatorMoveTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncAnimatorMoveTrigger GetAsyncAnimatorMoveTrigger(this Component component) + { + return component.gameObject.GetAsyncAnimatorMoveTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncAnimatorMoveTrigger : AsyncTriggerBase + { + TriggerEvent onAnimatorMoveTriggerEvent; + + void OnAnimatorMove() + { + onAnimatorMoveTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnAnimatorMoveHandler GetOnAnimatorMoveAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onAnimatorMoveTriggerEvent), false); + } + + public IAsyncOnAnimatorMoveHandler GetOnAnimatorMoveAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onAnimatorMoveTriggerEvent), cancellationToken, false); + } + + public UniTask OnAnimatorMoveAsync() + { + return ((IAsyncOnAnimatorMoveHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onAnimatorMoveTriggerEvent), true)).OnAnimatorMoveAsync(); + } + + public UniTask OnAnimatorMoveAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnAnimatorMoveHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onAnimatorMoveTriggerEvent), cancellationToken, true)).OnAnimatorMoveAsync(); + } + } +#endregion + +#region ApplicationFocus + + public interface IAsyncOnApplicationFocusHandler + { + UniTask OnApplicationFocusAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnApplicationFocusHandler + { + UniTask IAsyncOnApplicationFocusHandler.OnApplicationFocusAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncApplicationFocusTrigger GetAsyncApplicationFocusTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncApplicationFocusTrigger GetAsyncApplicationFocusTrigger(this Component component) + { + return component.gameObject.GetAsyncApplicationFocusTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncApplicationFocusTrigger : AsyncTriggerBase + { + TriggerEvent onApplicationFocusTriggerEvent; + + void OnApplicationFocus(bool hasFocus) + { + onApplicationFocusTriggerEvent?.TrySetResult((hasFocus)); + } + + public IAsyncOnApplicationFocusHandler GetOnApplicationFocusAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationFocusTriggerEvent), false); + } + + public IAsyncOnApplicationFocusHandler GetOnApplicationFocusAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationFocusTriggerEvent), cancellationToken, false); + } + + public UniTask OnApplicationFocusAsync() + { + return ((IAsyncOnApplicationFocusHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationFocusTriggerEvent), true)).OnApplicationFocusAsync(); + } + + public UniTask OnApplicationFocusAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnApplicationFocusHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationFocusTriggerEvent), cancellationToken, true)).OnApplicationFocusAsync(); + } + } +#endregion + +#region ApplicationPause + + public interface IAsyncOnApplicationPauseHandler + { + UniTask OnApplicationPauseAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnApplicationPauseHandler + { + UniTask IAsyncOnApplicationPauseHandler.OnApplicationPauseAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncApplicationPauseTrigger GetAsyncApplicationPauseTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncApplicationPauseTrigger GetAsyncApplicationPauseTrigger(this Component component) + { + return component.gameObject.GetAsyncApplicationPauseTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncApplicationPauseTrigger : AsyncTriggerBase + { + TriggerEvent onApplicationPauseTriggerEvent; + + void OnApplicationPause(bool pauseStatus) + { + onApplicationPauseTriggerEvent?.TrySetResult((pauseStatus)); + } + + public IAsyncOnApplicationPauseHandler GetOnApplicationPauseAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationPauseTriggerEvent), false); + } + + public IAsyncOnApplicationPauseHandler GetOnApplicationPauseAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationPauseTriggerEvent), cancellationToken, false); + } + + public UniTask OnApplicationPauseAsync() + { + return ((IAsyncOnApplicationPauseHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationPauseTriggerEvent), true)).OnApplicationPauseAsync(); + } + + public UniTask OnApplicationPauseAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnApplicationPauseHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationPauseTriggerEvent), cancellationToken, true)).OnApplicationPauseAsync(); + } + } +#endregion + +#region ApplicationQuit + + public interface IAsyncOnApplicationQuitHandler + { + UniTask OnApplicationQuitAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnApplicationQuitHandler + { + UniTask IAsyncOnApplicationQuitHandler.OnApplicationQuitAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncApplicationQuitTrigger GetAsyncApplicationQuitTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncApplicationQuitTrigger GetAsyncApplicationQuitTrigger(this Component component) + { + return component.gameObject.GetAsyncApplicationQuitTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncApplicationQuitTrigger : AsyncTriggerBase + { + TriggerEvent onApplicationQuitTriggerEvent; + + void OnApplicationQuit() + { + onApplicationQuitTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnApplicationQuitHandler GetOnApplicationQuitAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationQuitTriggerEvent), false); + } + + public IAsyncOnApplicationQuitHandler GetOnApplicationQuitAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationQuitTriggerEvent), cancellationToken, false); + } + + public UniTask OnApplicationQuitAsync() + { + return ((IAsyncOnApplicationQuitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationQuitTriggerEvent), true)).OnApplicationQuitAsync(); + } + + public UniTask OnApplicationQuitAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnApplicationQuitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onApplicationQuitTriggerEvent), cancellationToken, true)).OnApplicationQuitAsync(); + } + } +#endregion + +#region AudioFilterRead + + public interface IAsyncOnAudioFilterReadHandler + { + UniTask<(float[] data, int channels)> OnAudioFilterReadAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnAudioFilterReadHandler + { + UniTask<(float[] data, int channels)> IAsyncOnAudioFilterReadHandler.OnAudioFilterReadAsync() + { + core.Reset(); + return new UniTask<(float[] data, int channels)>((IUniTaskSource<(float[] data, int channels)>)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncAudioFilterReadTrigger GetAsyncAudioFilterReadTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncAudioFilterReadTrigger GetAsyncAudioFilterReadTrigger(this Component component) + { + return component.gameObject.GetAsyncAudioFilterReadTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncAudioFilterReadTrigger : AsyncTriggerBase + { + TriggerEvent<(float[] data, int channels)> onAudioFilterReadTriggerEvent; + + void OnAudioFilterRead(float[] data, int channels) + { + onAudioFilterReadTriggerEvent?.TrySetResult((data, channels)); + } + + public IAsyncOnAudioFilterReadHandler GetOnAudioFilterReadAsyncHandler() + { + return new AsyncTriggerHandler<(float[] data, int channels)>(SetTriggerEvent(ref onAudioFilterReadTriggerEvent), false); + } + + public IAsyncOnAudioFilterReadHandler GetOnAudioFilterReadAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler<(float[] data, int channels)>(SetTriggerEvent(ref onAudioFilterReadTriggerEvent), cancellationToken, false); + } + + public UniTask<(float[] data, int channels)> OnAudioFilterReadAsync() + { + return ((IAsyncOnAudioFilterReadHandler)new AsyncTriggerHandler<(float[] data, int channels)>(SetTriggerEvent(ref onAudioFilterReadTriggerEvent), true)).OnAudioFilterReadAsync(); + } + + public UniTask<(float[] data, int channels)> OnAudioFilterReadAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnAudioFilterReadHandler)new AsyncTriggerHandler<(float[] data, int channels)>(SetTriggerEvent(ref onAudioFilterReadTriggerEvent), cancellationToken, true)).OnAudioFilterReadAsync(); + } + } +#endregion + +#region BecameInvisible + + public interface IAsyncOnBecameInvisibleHandler + { + UniTask OnBecameInvisibleAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnBecameInvisibleHandler + { + UniTask IAsyncOnBecameInvisibleHandler.OnBecameInvisibleAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncBecameInvisibleTrigger GetAsyncBecameInvisibleTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncBecameInvisibleTrigger GetAsyncBecameInvisibleTrigger(this Component component) + { + return component.gameObject.GetAsyncBecameInvisibleTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncBecameInvisibleTrigger : AsyncTriggerBase + { + TriggerEvent onBecameInvisibleTriggerEvent; + + void OnBecameInvisible() + { + onBecameInvisibleTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnBecameInvisibleHandler GetOnBecameInvisibleAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onBecameInvisibleTriggerEvent), false); + } + + public IAsyncOnBecameInvisibleHandler GetOnBecameInvisibleAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onBecameInvisibleTriggerEvent), cancellationToken, false); + } + + public UniTask OnBecameInvisibleAsync() + { + return ((IAsyncOnBecameInvisibleHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onBecameInvisibleTriggerEvent), true)).OnBecameInvisibleAsync(); + } + + public UniTask OnBecameInvisibleAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnBecameInvisibleHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onBecameInvisibleTriggerEvent), cancellationToken, true)).OnBecameInvisibleAsync(); + } + } +#endregion + +#region BecameVisible + + public interface IAsyncOnBecameVisibleHandler + { + UniTask OnBecameVisibleAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnBecameVisibleHandler + { + UniTask IAsyncOnBecameVisibleHandler.OnBecameVisibleAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncBecameVisibleTrigger GetAsyncBecameVisibleTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncBecameVisibleTrigger GetAsyncBecameVisibleTrigger(this Component component) + { + return component.gameObject.GetAsyncBecameVisibleTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncBecameVisibleTrigger : AsyncTriggerBase + { + TriggerEvent onBecameVisibleTriggerEvent; + + void OnBecameVisible() + { + onBecameVisibleTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnBecameVisibleHandler GetOnBecameVisibleAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onBecameVisibleTriggerEvent), false); + } + + public IAsyncOnBecameVisibleHandler GetOnBecameVisibleAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onBecameVisibleTriggerEvent), cancellationToken, false); + } + + public UniTask OnBecameVisibleAsync() + { + return ((IAsyncOnBecameVisibleHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onBecameVisibleTriggerEvent), true)).OnBecameVisibleAsync(); + } + + public UniTask OnBecameVisibleAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnBecameVisibleHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onBecameVisibleTriggerEvent), cancellationToken, true)).OnBecameVisibleAsync(); + } + } +#endregion + +#region BeforeTransformParentChanged + + public interface IAsyncOnBeforeTransformParentChangedHandler + { + UniTask OnBeforeTransformParentChangedAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnBeforeTransformParentChangedHandler + { + UniTask IAsyncOnBeforeTransformParentChangedHandler.OnBeforeTransformParentChangedAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncBeforeTransformParentChangedTrigger GetAsyncBeforeTransformParentChangedTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncBeforeTransformParentChangedTrigger GetAsyncBeforeTransformParentChangedTrigger(this Component component) + { + return component.gameObject.GetAsyncBeforeTransformParentChangedTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncBeforeTransformParentChangedTrigger : AsyncTriggerBase + { + TriggerEvent onBeforeTransformParentChangedTriggerEvent; + + void OnBeforeTransformParentChanged() + { + onBeforeTransformParentChangedTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnBeforeTransformParentChangedHandler GetOnBeforeTransformParentChangedAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onBeforeTransformParentChangedTriggerEvent), false); + } + + public IAsyncOnBeforeTransformParentChangedHandler GetOnBeforeTransformParentChangedAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onBeforeTransformParentChangedTriggerEvent), cancellationToken, false); + } + + public UniTask OnBeforeTransformParentChangedAsync() + { + return ((IAsyncOnBeforeTransformParentChangedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onBeforeTransformParentChangedTriggerEvent), true)).OnBeforeTransformParentChangedAsync(); + } + + public UniTask OnBeforeTransformParentChangedAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnBeforeTransformParentChangedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onBeforeTransformParentChangedTriggerEvent), cancellationToken, true)).OnBeforeTransformParentChangedAsync(); + } + } +#endregion + +#region OnCanvasGroupChanged + + public interface IAsyncOnCanvasGroupChangedHandler + { + UniTask OnCanvasGroupChangedAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnCanvasGroupChangedHandler + { + UniTask IAsyncOnCanvasGroupChangedHandler.OnCanvasGroupChangedAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncOnCanvasGroupChangedTrigger GetAsyncOnCanvasGroupChangedTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncOnCanvasGroupChangedTrigger GetAsyncOnCanvasGroupChangedTrigger(this Component component) + { + return component.gameObject.GetAsyncOnCanvasGroupChangedTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncOnCanvasGroupChangedTrigger : AsyncTriggerBase + { + TriggerEvent onCanvasGroupChangedTriggerEvent; + + void OnCanvasGroupChanged() + { + onCanvasGroupChangedTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnCanvasGroupChangedHandler GetOnCanvasGroupChangedAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCanvasGroupChangedTriggerEvent), false); + } + + public IAsyncOnCanvasGroupChangedHandler GetOnCanvasGroupChangedAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCanvasGroupChangedTriggerEvent), cancellationToken, false); + } + + public UniTask OnCanvasGroupChangedAsync() + { + return ((IAsyncOnCanvasGroupChangedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCanvasGroupChangedTriggerEvent), true)).OnCanvasGroupChangedAsync(); + } + + public UniTask OnCanvasGroupChangedAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnCanvasGroupChangedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCanvasGroupChangedTriggerEvent), cancellationToken, true)).OnCanvasGroupChangedAsync(); + } + } +#endregion + +#region CollisionEnter + + public interface IAsyncOnCollisionEnterHandler + { + UniTask OnCollisionEnterAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnCollisionEnterHandler + { + UniTask IAsyncOnCollisionEnterHandler.OnCollisionEnterAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncCollisionEnterTrigger GetAsyncCollisionEnterTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncCollisionEnterTrigger GetAsyncCollisionEnterTrigger(this Component component) + { + return component.gameObject.GetAsyncCollisionEnterTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncCollisionEnterTrigger : AsyncTriggerBase + { + TriggerEvent onCollisionEnterTriggerEvent; + + void OnCollisionEnter(Collision coll) + { + onCollisionEnterTriggerEvent?.TrySetResult((coll)); + } + + public IAsyncOnCollisionEnterHandler GetOnCollisionEnterAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionEnterTriggerEvent), false); + } + + public IAsyncOnCollisionEnterHandler GetOnCollisionEnterAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionEnterTriggerEvent), cancellationToken, false); + } + + public UniTask OnCollisionEnterAsync() + { + return ((IAsyncOnCollisionEnterHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionEnterTriggerEvent), true)).OnCollisionEnterAsync(); + } + + public UniTask OnCollisionEnterAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnCollisionEnterHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionEnterTriggerEvent), cancellationToken, true)).OnCollisionEnterAsync(); + } + } +#endregion + +#region CollisionEnter2D + + public interface IAsyncOnCollisionEnter2DHandler + { + UniTask OnCollisionEnter2DAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnCollisionEnter2DHandler + { + UniTask IAsyncOnCollisionEnter2DHandler.OnCollisionEnter2DAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncCollisionEnter2DTrigger GetAsyncCollisionEnter2DTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncCollisionEnter2DTrigger GetAsyncCollisionEnter2DTrigger(this Component component) + { + return component.gameObject.GetAsyncCollisionEnter2DTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncCollisionEnter2DTrigger : AsyncTriggerBase + { + TriggerEvent onCollisionEnter2DTriggerEvent; + + void OnCollisionEnter2D(Collision2D coll) + { + onCollisionEnter2DTriggerEvent?.TrySetResult((coll)); + } + + public IAsyncOnCollisionEnter2DHandler GetOnCollisionEnter2DAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionEnter2DTriggerEvent), false); + } + + public IAsyncOnCollisionEnter2DHandler GetOnCollisionEnter2DAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionEnter2DTriggerEvent), cancellationToken, false); + } + + public UniTask OnCollisionEnter2DAsync() + { + return ((IAsyncOnCollisionEnter2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionEnter2DTriggerEvent), true)).OnCollisionEnter2DAsync(); + } + + public UniTask OnCollisionEnter2DAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnCollisionEnter2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionEnter2DTriggerEvent), cancellationToken, true)).OnCollisionEnter2DAsync(); + } + } +#endregion + +#region CollisionExit + + public interface IAsyncOnCollisionExitHandler + { + UniTask OnCollisionExitAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnCollisionExitHandler + { + UniTask IAsyncOnCollisionExitHandler.OnCollisionExitAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncCollisionExitTrigger GetAsyncCollisionExitTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncCollisionExitTrigger GetAsyncCollisionExitTrigger(this Component component) + { + return component.gameObject.GetAsyncCollisionExitTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncCollisionExitTrigger : AsyncTriggerBase + { + TriggerEvent onCollisionExitTriggerEvent; + + void OnCollisionExit(Collision coll) + { + onCollisionExitTriggerEvent?.TrySetResult((coll)); + } + + public IAsyncOnCollisionExitHandler GetOnCollisionExitAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionExitTriggerEvent), false); + } + + public IAsyncOnCollisionExitHandler GetOnCollisionExitAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionExitTriggerEvent), cancellationToken, false); + } + + public UniTask OnCollisionExitAsync() + { + return ((IAsyncOnCollisionExitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionExitTriggerEvent), true)).OnCollisionExitAsync(); + } + + public UniTask OnCollisionExitAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnCollisionExitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionExitTriggerEvent), cancellationToken, true)).OnCollisionExitAsync(); + } + } +#endregion + +#region CollisionExit2D + + public interface IAsyncOnCollisionExit2DHandler + { + UniTask OnCollisionExit2DAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnCollisionExit2DHandler + { + UniTask IAsyncOnCollisionExit2DHandler.OnCollisionExit2DAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncCollisionExit2DTrigger GetAsyncCollisionExit2DTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncCollisionExit2DTrigger GetAsyncCollisionExit2DTrigger(this Component component) + { + return component.gameObject.GetAsyncCollisionExit2DTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncCollisionExit2DTrigger : AsyncTriggerBase + { + TriggerEvent onCollisionExit2DTriggerEvent; + + void OnCollisionExit2D(Collision2D coll) + { + onCollisionExit2DTriggerEvent?.TrySetResult((coll)); + } + + public IAsyncOnCollisionExit2DHandler GetOnCollisionExit2DAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionExit2DTriggerEvent), false); + } + + public IAsyncOnCollisionExit2DHandler GetOnCollisionExit2DAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionExit2DTriggerEvent), cancellationToken, false); + } + + public UniTask OnCollisionExit2DAsync() + { + return ((IAsyncOnCollisionExit2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionExit2DTriggerEvent), true)).OnCollisionExit2DAsync(); + } + + public UniTask OnCollisionExit2DAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnCollisionExit2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionExit2DTriggerEvent), cancellationToken, true)).OnCollisionExit2DAsync(); + } + } +#endregion + +#region CollisionStay + + public interface IAsyncOnCollisionStayHandler + { + UniTask OnCollisionStayAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnCollisionStayHandler + { + UniTask IAsyncOnCollisionStayHandler.OnCollisionStayAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncCollisionStayTrigger GetAsyncCollisionStayTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncCollisionStayTrigger GetAsyncCollisionStayTrigger(this Component component) + { + return component.gameObject.GetAsyncCollisionStayTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncCollisionStayTrigger : AsyncTriggerBase + { + TriggerEvent onCollisionStayTriggerEvent; + + void OnCollisionStay(Collision coll) + { + onCollisionStayTriggerEvent?.TrySetResult((coll)); + } + + public IAsyncOnCollisionStayHandler GetOnCollisionStayAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionStayTriggerEvent), false); + } + + public IAsyncOnCollisionStayHandler GetOnCollisionStayAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionStayTriggerEvent), cancellationToken, false); + } + + public UniTask OnCollisionStayAsync() + { + return ((IAsyncOnCollisionStayHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionStayTriggerEvent), true)).OnCollisionStayAsync(); + } + + public UniTask OnCollisionStayAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnCollisionStayHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionStayTriggerEvent), cancellationToken, true)).OnCollisionStayAsync(); + } + } +#endregion + +#region CollisionStay2D + + public interface IAsyncOnCollisionStay2DHandler + { + UniTask OnCollisionStay2DAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnCollisionStay2DHandler + { + UniTask IAsyncOnCollisionStay2DHandler.OnCollisionStay2DAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncCollisionStay2DTrigger GetAsyncCollisionStay2DTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncCollisionStay2DTrigger GetAsyncCollisionStay2DTrigger(this Component component) + { + return component.gameObject.GetAsyncCollisionStay2DTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncCollisionStay2DTrigger : AsyncTriggerBase + { + TriggerEvent onCollisionStay2DTriggerEvent; + + void OnCollisionStay2D(Collision2D coll) + { + onCollisionStay2DTriggerEvent?.TrySetResult((coll)); + } + + public IAsyncOnCollisionStay2DHandler GetOnCollisionStay2DAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionStay2DTriggerEvent), false); + } + + public IAsyncOnCollisionStay2DHandler GetOnCollisionStay2DAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionStay2DTriggerEvent), cancellationToken, false); + } + + public UniTask OnCollisionStay2DAsync() + { + return ((IAsyncOnCollisionStay2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionStay2DTriggerEvent), true)).OnCollisionStay2DAsync(); + } + + public UniTask OnCollisionStay2DAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnCollisionStay2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCollisionStay2DTriggerEvent), cancellationToken, true)).OnCollisionStay2DAsync(); + } + } +#endregion + +#region ControllerColliderHit + + public interface IAsyncOnControllerColliderHitHandler + { + UniTask OnControllerColliderHitAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnControllerColliderHitHandler + { + UniTask IAsyncOnControllerColliderHitHandler.OnControllerColliderHitAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncControllerColliderHitTrigger GetAsyncControllerColliderHitTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncControllerColliderHitTrigger GetAsyncControllerColliderHitTrigger(this Component component) + { + return component.gameObject.GetAsyncControllerColliderHitTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncControllerColliderHitTrigger : AsyncTriggerBase + { + TriggerEvent onControllerColliderHitTriggerEvent; + + void OnControllerColliderHit(ControllerColliderHit hit) + { + onControllerColliderHitTriggerEvent?.TrySetResult((hit)); + } + + public IAsyncOnControllerColliderHitHandler GetOnControllerColliderHitAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onControllerColliderHitTriggerEvent), false); + } + + public IAsyncOnControllerColliderHitHandler GetOnControllerColliderHitAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onControllerColliderHitTriggerEvent), cancellationToken, false); + } + + public UniTask OnControllerColliderHitAsync() + { + return ((IAsyncOnControllerColliderHitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onControllerColliderHitTriggerEvent), true)).OnControllerColliderHitAsync(); + } + + public UniTask OnControllerColliderHitAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnControllerColliderHitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onControllerColliderHitTriggerEvent), cancellationToken, true)).OnControllerColliderHitAsync(); + } + } +#endregion + +#region Disable + + public interface IAsyncOnDisableHandler + { + UniTask OnDisableAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnDisableHandler + { + UniTask IAsyncOnDisableHandler.OnDisableAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncDisableTrigger GetAsyncDisableTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncDisableTrigger GetAsyncDisableTrigger(this Component component) + { + return component.gameObject.GetAsyncDisableTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncDisableTrigger : AsyncTriggerBase + { + TriggerEvent onDisableTriggerEvent; + + void OnDisable() + { + onDisableTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnDisableHandler GetOnDisableAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onDisableTriggerEvent), false); + } + + public IAsyncOnDisableHandler GetOnDisableAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onDisableTriggerEvent), cancellationToken, false); + } + + public UniTask OnDisableAsync() + { + return ((IAsyncOnDisableHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDisableTriggerEvent), true)).OnDisableAsync(); + } + + public UniTask OnDisableAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnDisableHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDisableTriggerEvent), cancellationToken, true)).OnDisableAsync(); + } + } +#endregion + +#region DrawGizmos + + public interface IAsyncOnDrawGizmosHandler + { + UniTask OnDrawGizmosAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnDrawGizmosHandler + { + UniTask IAsyncOnDrawGizmosHandler.OnDrawGizmosAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncDrawGizmosTrigger GetAsyncDrawGizmosTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncDrawGizmosTrigger GetAsyncDrawGizmosTrigger(this Component component) + { + return component.gameObject.GetAsyncDrawGizmosTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncDrawGizmosTrigger : AsyncTriggerBase + { + TriggerEvent onDrawGizmosTriggerEvent; + + void OnDrawGizmos() + { + onDrawGizmosTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnDrawGizmosHandler GetOnDrawGizmosAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onDrawGizmosTriggerEvent), false); + } + + public IAsyncOnDrawGizmosHandler GetOnDrawGizmosAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onDrawGizmosTriggerEvent), cancellationToken, false); + } + + public UniTask OnDrawGizmosAsync() + { + return ((IAsyncOnDrawGizmosHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDrawGizmosTriggerEvent), true)).OnDrawGizmosAsync(); + } + + public UniTask OnDrawGizmosAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnDrawGizmosHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDrawGizmosTriggerEvent), cancellationToken, true)).OnDrawGizmosAsync(); + } + } +#endregion + +#region DrawGizmosSelected + + public interface IAsyncOnDrawGizmosSelectedHandler + { + UniTask OnDrawGizmosSelectedAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnDrawGizmosSelectedHandler + { + UniTask IAsyncOnDrawGizmosSelectedHandler.OnDrawGizmosSelectedAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncDrawGizmosSelectedTrigger GetAsyncDrawGizmosSelectedTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncDrawGizmosSelectedTrigger GetAsyncDrawGizmosSelectedTrigger(this Component component) + { + return component.gameObject.GetAsyncDrawGizmosSelectedTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncDrawGizmosSelectedTrigger : AsyncTriggerBase + { + TriggerEvent onDrawGizmosSelectedTriggerEvent; + + void OnDrawGizmosSelected() + { + onDrawGizmosSelectedTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnDrawGizmosSelectedHandler GetOnDrawGizmosSelectedAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onDrawGizmosSelectedTriggerEvent), false); + } + + public IAsyncOnDrawGizmosSelectedHandler GetOnDrawGizmosSelectedAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onDrawGizmosSelectedTriggerEvent), cancellationToken, false); + } + + public UniTask OnDrawGizmosSelectedAsync() + { + return ((IAsyncOnDrawGizmosSelectedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDrawGizmosSelectedTriggerEvent), true)).OnDrawGizmosSelectedAsync(); + } + + public UniTask OnDrawGizmosSelectedAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnDrawGizmosSelectedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDrawGizmosSelectedTriggerEvent), cancellationToken, true)).OnDrawGizmosSelectedAsync(); + } + } +#endregion + +#region Enable + + public interface IAsyncOnEnableHandler + { + UniTask OnEnableAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnEnableHandler + { + UniTask IAsyncOnEnableHandler.OnEnableAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncEnableTrigger GetAsyncEnableTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncEnableTrigger GetAsyncEnableTrigger(this Component component) + { + return component.gameObject.GetAsyncEnableTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncEnableTrigger : AsyncTriggerBase + { + TriggerEvent onEnableTriggerEvent; + + void OnEnable() + { + onEnableTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnEnableHandler GetOnEnableAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onEnableTriggerEvent), false); + } + + public IAsyncOnEnableHandler GetOnEnableAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onEnableTriggerEvent), cancellationToken, false); + } + + public UniTask OnEnableAsync() + { + return ((IAsyncOnEnableHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onEnableTriggerEvent), true)).OnEnableAsync(); + } + + public UniTask OnEnableAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnEnableHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onEnableTriggerEvent), cancellationToken, true)).OnEnableAsync(); + } + } +#endregion + +#region GUI + + public interface IAsyncOnGUIHandler + { + UniTask OnGUIAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnGUIHandler + { + UniTask IAsyncOnGUIHandler.OnGUIAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncGUITrigger GetAsyncGUITrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncGUITrigger GetAsyncGUITrigger(this Component component) + { + return component.gameObject.GetAsyncGUITrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncGUITrigger : AsyncTriggerBase + { + TriggerEvent onGUITriggerEvent; + + void OnGUI() + { + onGUITriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnGUIHandler GetOnGUIAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onGUITriggerEvent), false); + } + + public IAsyncOnGUIHandler GetOnGUIAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onGUITriggerEvent), cancellationToken, false); + } + + public UniTask OnGUIAsync() + { + return ((IAsyncOnGUIHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onGUITriggerEvent), true)).OnGUIAsync(); + } + + public UniTask OnGUIAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnGUIHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onGUITriggerEvent), cancellationToken, true)).OnGUIAsync(); + } + } +#endregion + +#region JointBreak + + public interface IAsyncOnJointBreakHandler + { + UniTask OnJointBreakAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnJointBreakHandler + { + UniTask IAsyncOnJointBreakHandler.OnJointBreakAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncJointBreakTrigger GetAsyncJointBreakTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncJointBreakTrigger GetAsyncJointBreakTrigger(this Component component) + { + return component.gameObject.GetAsyncJointBreakTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncJointBreakTrigger : AsyncTriggerBase + { + TriggerEvent onJointBreakTriggerEvent; + + void OnJointBreak(float breakForce) + { + onJointBreakTriggerEvent?.TrySetResult((breakForce)); + } + + public IAsyncOnJointBreakHandler GetOnJointBreakAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onJointBreakTriggerEvent), false); + } + + public IAsyncOnJointBreakHandler GetOnJointBreakAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onJointBreakTriggerEvent), cancellationToken, false); + } + + public UniTask OnJointBreakAsync() + { + return ((IAsyncOnJointBreakHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onJointBreakTriggerEvent), true)).OnJointBreakAsync(); + } + + public UniTask OnJointBreakAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnJointBreakHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onJointBreakTriggerEvent), cancellationToken, true)).OnJointBreakAsync(); + } + } +#endregion + +#region JointBreak2D + + public interface IAsyncOnJointBreak2DHandler + { + UniTask OnJointBreak2DAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnJointBreak2DHandler + { + UniTask IAsyncOnJointBreak2DHandler.OnJointBreak2DAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncJointBreak2DTrigger GetAsyncJointBreak2DTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncJointBreak2DTrigger GetAsyncJointBreak2DTrigger(this Component component) + { + return component.gameObject.GetAsyncJointBreak2DTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncJointBreak2DTrigger : AsyncTriggerBase + { + TriggerEvent onJointBreak2DTriggerEvent; + + void OnJointBreak2D(Joint2D brokenJoint) + { + onJointBreak2DTriggerEvent?.TrySetResult((brokenJoint)); + } + + public IAsyncOnJointBreak2DHandler GetOnJointBreak2DAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onJointBreak2DTriggerEvent), false); + } + + public IAsyncOnJointBreak2DHandler GetOnJointBreak2DAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onJointBreak2DTriggerEvent), cancellationToken, false); + } + + public UniTask OnJointBreak2DAsync() + { + return ((IAsyncOnJointBreak2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onJointBreak2DTriggerEvent), true)).OnJointBreak2DAsync(); + } + + public UniTask OnJointBreak2DAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnJointBreak2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onJointBreak2DTriggerEvent), cancellationToken, true)).OnJointBreak2DAsync(); + } + } +#endregion + +#region MouseDown + + public interface IAsyncOnMouseDownHandler + { + UniTask OnMouseDownAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnMouseDownHandler + { + UniTask IAsyncOnMouseDownHandler.OnMouseDownAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncMouseDownTrigger GetAsyncMouseDownTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncMouseDownTrigger GetAsyncMouseDownTrigger(this Component component) + { + return component.gameObject.GetAsyncMouseDownTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncMouseDownTrigger : AsyncTriggerBase + { + TriggerEvent onMouseDownTriggerEvent; + + void OnMouseDown() + { + onMouseDownTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnMouseDownHandler GetOnMouseDownAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseDownTriggerEvent), false); + } + + public IAsyncOnMouseDownHandler GetOnMouseDownAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseDownTriggerEvent), cancellationToken, false); + } + + public UniTask OnMouseDownAsync() + { + return ((IAsyncOnMouseDownHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseDownTriggerEvent), true)).OnMouseDownAsync(); + } + + public UniTask OnMouseDownAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnMouseDownHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseDownTriggerEvent), cancellationToken, true)).OnMouseDownAsync(); + } + } +#endregion + +#region MouseDrag + + public interface IAsyncOnMouseDragHandler + { + UniTask OnMouseDragAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnMouseDragHandler + { + UniTask IAsyncOnMouseDragHandler.OnMouseDragAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncMouseDragTrigger GetAsyncMouseDragTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncMouseDragTrigger GetAsyncMouseDragTrigger(this Component component) + { + return component.gameObject.GetAsyncMouseDragTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncMouseDragTrigger : AsyncTriggerBase + { + TriggerEvent onMouseDragTriggerEvent; + + void OnMouseDrag() + { + onMouseDragTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnMouseDragHandler GetOnMouseDragAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseDragTriggerEvent), false); + } + + public IAsyncOnMouseDragHandler GetOnMouseDragAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseDragTriggerEvent), cancellationToken, false); + } + + public UniTask OnMouseDragAsync() + { + return ((IAsyncOnMouseDragHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseDragTriggerEvent), true)).OnMouseDragAsync(); + } + + public UniTask OnMouseDragAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnMouseDragHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseDragTriggerEvent), cancellationToken, true)).OnMouseDragAsync(); + } + } +#endregion + +#region MouseEnter + + public interface IAsyncOnMouseEnterHandler + { + UniTask OnMouseEnterAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnMouseEnterHandler + { + UniTask IAsyncOnMouseEnterHandler.OnMouseEnterAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncMouseEnterTrigger GetAsyncMouseEnterTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncMouseEnterTrigger GetAsyncMouseEnterTrigger(this Component component) + { + return component.gameObject.GetAsyncMouseEnterTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncMouseEnterTrigger : AsyncTriggerBase + { + TriggerEvent onMouseEnterTriggerEvent; + + void OnMouseEnter() + { + onMouseEnterTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnMouseEnterHandler GetOnMouseEnterAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseEnterTriggerEvent), false); + } + + public IAsyncOnMouseEnterHandler GetOnMouseEnterAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseEnterTriggerEvent), cancellationToken, false); + } + + public UniTask OnMouseEnterAsync() + { + return ((IAsyncOnMouseEnterHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseEnterTriggerEvent), true)).OnMouseEnterAsync(); + } + + public UniTask OnMouseEnterAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnMouseEnterHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseEnterTriggerEvent), cancellationToken, true)).OnMouseEnterAsync(); + } + } +#endregion + +#region MouseExit + + public interface IAsyncOnMouseExitHandler + { + UniTask OnMouseExitAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnMouseExitHandler + { + UniTask IAsyncOnMouseExitHandler.OnMouseExitAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncMouseExitTrigger GetAsyncMouseExitTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncMouseExitTrigger GetAsyncMouseExitTrigger(this Component component) + { + return component.gameObject.GetAsyncMouseExitTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncMouseExitTrigger : AsyncTriggerBase + { + TriggerEvent onMouseExitTriggerEvent; + + void OnMouseExit() + { + onMouseExitTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnMouseExitHandler GetOnMouseExitAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseExitTriggerEvent), false); + } + + public IAsyncOnMouseExitHandler GetOnMouseExitAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseExitTriggerEvent), cancellationToken, false); + } + + public UniTask OnMouseExitAsync() + { + return ((IAsyncOnMouseExitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseExitTriggerEvent), true)).OnMouseExitAsync(); + } + + public UniTask OnMouseExitAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnMouseExitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseExitTriggerEvent), cancellationToken, true)).OnMouseExitAsync(); + } + } +#endregion + +#region MouseOver + + public interface IAsyncOnMouseOverHandler + { + UniTask OnMouseOverAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnMouseOverHandler + { + UniTask IAsyncOnMouseOverHandler.OnMouseOverAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncMouseOverTrigger GetAsyncMouseOverTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncMouseOverTrigger GetAsyncMouseOverTrigger(this Component component) + { + return component.gameObject.GetAsyncMouseOverTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncMouseOverTrigger : AsyncTriggerBase + { + TriggerEvent onMouseOverTriggerEvent; + + void OnMouseOver() + { + onMouseOverTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnMouseOverHandler GetOnMouseOverAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseOverTriggerEvent), false); + } + + public IAsyncOnMouseOverHandler GetOnMouseOverAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseOverTriggerEvent), cancellationToken, false); + } + + public UniTask OnMouseOverAsync() + { + return ((IAsyncOnMouseOverHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseOverTriggerEvent), true)).OnMouseOverAsync(); + } + + public UniTask OnMouseOverAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnMouseOverHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseOverTriggerEvent), cancellationToken, true)).OnMouseOverAsync(); + } + } +#endregion + +#region MouseUp + + public interface IAsyncOnMouseUpHandler + { + UniTask OnMouseUpAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnMouseUpHandler + { + UniTask IAsyncOnMouseUpHandler.OnMouseUpAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncMouseUpTrigger GetAsyncMouseUpTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncMouseUpTrigger GetAsyncMouseUpTrigger(this Component component) + { + return component.gameObject.GetAsyncMouseUpTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncMouseUpTrigger : AsyncTriggerBase + { + TriggerEvent onMouseUpTriggerEvent; + + void OnMouseUp() + { + onMouseUpTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnMouseUpHandler GetOnMouseUpAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseUpTriggerEvent), false); + } + + public IAsyncOnMouseUpHandler GetOnMouseUpAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseUpTriggerEvent), cancellationToken, false); + } + + public UniTask OnMouseUpAsync() + { + return ((IAsyncOnMouseUpHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseUpTriggerEvent), true)).OnMouseUpAsync(); + } + + public UniTask OnMouseUpAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnMouseUpHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseUpTriggerEvent), cancellationToken, true)).OnMouseUpAsync(); + } + } +#endregion + +#region MouseUpAsButton + + public interface IAsyncOnMouseUpAsButtonHandler + { + UniTask OnMouseUpAsButtonAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnMouseUpAsButtonHandler + { + UniTask IAsyncOnMouseUpAsButtonHandler.OnMouseUpAsButtonAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncMouseUpAsButtonTrigger GetAsyncMouseUpAsButtonTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncMouseUpAsButtonTrigger GetAsyncMouseUpAsButtonTrigger(this Component component) + { + return component.gameObject.GetAsyncMouseUpAsButtonTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncMouseUpAsButtonTrigger : AsyncTriggerBase + { + TriggerEvent onMouseUpAsButtonTriggerEvent; + + void OnMouseUpAsButton() + { + onMouseUpAsButtonTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnMouseUpAsButtonHandler GetOnMouseUpAsButtonAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseUpAsButtonTriggerEvent), false); + } + + public IAsyncOnMouseUpAsButtonHandler GetOnMouseUpAsButtonAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMouseUpAsButtonTriggerEvent), cancellationToken, false); + } + + public UniTask OnMouseUpAsButtonAsync() + { + return ((IAsyncOnMouseUpAsButtonHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseUpAsButtonTriggerEvent), true)).OnMouseUpAsButtonAsync(); + } + + public UniTask OnMouseUpAsButtonAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnMouseUpAsButtonHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMouseUpAsButtonTriggerEvent), cancellationToken, true)).OnMouseUpAsButtonAsync(); + } + } +#endregion + +#region ParticleCollision + + public interface IAsyncOnParticleCollisionHandler + { + UniTask OnParticleCollisionAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnParticleCollisionHandler + { + UniTask IAsyncOnParticleCollisionHandler.OnParticleCollisionAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncParticleCollisionTrigger GetAsyncParticleCollisionTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncParticleCollisionTrigger GetAsyncParticleCollisionTrigger(this Component component) + { + return component.gameObject.GetAsyncParticleCollisionTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncParticleCollisionTrigger : AsyncTriggerBase + { + TriggerEvent onParticleCollisionTriggerEvent; + + void OnParticleCollision(GameObject other) + { + onParticleCollisionTriggerEvent?.TrySetResult((other)); + } + + public IAsyncOnParticleCollisionHandler GetOnParticleCollisionAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onParticleCollisionTriggerEvent), false); + } + + public IAsyncOnParticleCollisionHandler GetOnParticleCollisionAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onParticleCollisionTriggerEvent), cancellationToken, false); + } + + public UniTask OnParticleCollisionAsync() + { + return ((IAsyncOnParticleCollisionHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onParticleCollisionTriggerEvent), true)).OnParticleCollisionAsync(); + } + + public UniTask OnParticleCollisionAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnParticleCollisionHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onParticleCollisionTriggerEvent), cancellationToken, true)).OnParticleCollisionAsync(); + } + } +#endregion + +#region ParticleSystemStopped + + public interface IAsyncOnParticleSystemStoppedHandler + { + UniTask OnParticleSystemStoppedAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnParticleSystemStoppedHandler + { + UniTask IAsyncOnParticleSystemStoppedHandler.OnParticleSystemStoppedAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncParticleSystemStoppedTrigger GetAsyncParticleSystemStoppedTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncParticleSystemStoppedTrigger GetAsyncParticleSystemStoppedTrigger(this Component component) + { + return component.gameObject.GetAsyncParticleSystemStoppedTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncParticleSystemStoppedTrigger : AsyncTriggerBase + { + TriggerEvent onParticleSystemStoppedTriggerEvent; + + void OnParticleSystemStopped() + { + onParticleSystemStoppedTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnParticleSystemStoppedHandler GetOnParticleSystemStoppedAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onParticleSystemStoppedTriggerEvent), false); + } + + public IAsyncOnParticleSystemStoppedHandler GetOnParticleSystemStoppedAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onParticleSystemStoppedTriggerEvent), cancellationToken, false); + } + + public UniTask OnParticleSystemStoppedAsync() + { + return ((IAsyncOnParticleSystemStoppedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onParticleSystemStoppedTriggerEvent), true)).OnParticleSystemStoppedAsync(); + } + + public UniTask OnParticleSystemStoppedAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnParticleSystemStoppedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onParticleSystemStoppedTriggerEvent), cancellationToken, true)).OnParticleSystemStoppedAsync(); + } + } +#endregion + +#region ParticleTrigger + + public interface IAsyncOnParticleTriggerHandler + { + UniTask OnParticleTriggerAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnParticleTriggerHandler + { + UniTask IAsyncOnParticleTriggerHandler.OnParticleTriggerAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncParticleTriggerTrigger GetAsyncParticleTriggerTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncParticleTriggerTrigger GetAsyncParticleTriggerTrigger(this Component component) + { + return component.gameObject.GetAsyncParticleTriggerTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncParticleTriggerTrigger : AsyncTriggerBase + { + TriggerEvent onParticleTriggerTriggerEvent; + + void OnParticleTrigger() + { + onParticleTriggerTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnParticleTriggerHandler GetOnParticleTriggerAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onParticleTriggerTriggerEvent), false); + } + + public IAsyncOnParticleTriggerHandler GetOnParticleTriggerAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onParticleTriggerTriggerEvent), cancellationToken, false); + } + + public UniTask OnParticleTriggerAsync() + { + return ((IAsyncOnParticleTriggerHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onParticleTriggerTriggerEvent), true)).OnParticleTriggerAsync(); + } + + public UniTask OnParticleTriggerAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnParticleTriggerHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onParticleTriggerTriggerEvent), cancellationToken, true)).OnParticleTriggerAsync(); + } + } +#endregion + +#region ParticleUpdateJobScheduled +#if UNITY_2019_3_OR_NEWER + + public interface IAsyncOnParticleUpdateJobScheduledHandler + { + UniTask OnParticleUpdateJobScheduledAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnParticleUpdateJobScheduledHandler + { + UniTask IAsyncOnParticleUpdateJobScheduledHandler.OnParticleUpdateJobScheduledAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncParticleUpdateJobScheduledTrigger GetAsyncParticleUpdateJobScheduledTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncParticleUpdateJobScheduledTrigger GetAsyncParticleUpdateJobScheduledTrigger(this Component component) + { + return component.gameObject.GetAsyncParticleUpdateJobScheduledTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncParticleUpdateJobScheduledTrigger : AsyncTriggerBase + { + TriggerEvent onParticleUpdateJobScheduledTriggerEvent; + + void OnParticleUpdateJobScheduled(UnityEngine.ParticleSystemJobs.ParticleSystemJobData particles) + { + onParticleUpdateJobScheduledTriggerEvent?.TrySetResult((particles)); + } + + public IAsyncOnParticleUpdateJobScheduledHandler GetOnParticleUpdateJobScheduledAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onParticleUpdateJobScheduledTriggerEvent), false); + } + + public IAsyncOnParticleUpdateJobScheduledHandler GetOnParticleUpdateJobScheduledAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onParticleUpdateJobScheduledTriggerEvent), cancellationToken, false); + } + + public UniTask OnParticleUpdateJobScheduledAsync() + { + return ((IAsyncOnParticleUpdateJobScheduledHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onParticleUpdateJobScheduledTriggerEvent), true)).OnParticleUpdateJobScheduledAsync(); + } + + public UniTask OnParticleUpdateJobScheduledAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnParticleUpdateJobScheduledHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onParticleUpdateJobScheduledTriggerEvent), cancellationToken, true)).OnParticleUpdateJobScheduledAsync(); + } + } +#endif +#endregion + +#region PostRender + + public interface IAsyncOnPostRenderHandler + { + UniTask OnPostRenderAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnPostRenderHandler + { + UniTask IAsyncOnPostRenderHandler.OnPostRenderAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncPostRenderTrigger GetAsyncPostRenderTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncPostRenderTrigger GetAsyncPostRenderTrigger(this Component component) + { + return component.gameObject.GetAsyncPostRenderTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncPostRenderTrigger : AsyncTriggerBase + { + TriggerEvent onPostRenderTriggerEvent; + + void OnPostRender() + { + onPostRenderTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnPostRenderHandler GetOnPostRenderAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPostRenderTriggerEvent), false); + } + + public IAsyncOnPostRenderHandler GetOnPostRenderAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPostRenderTriggerEvent), cancellationToken, false); + } + + public UniTask OnPostRenderAsync() + { + return ((IAsyncOnPostRenderHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPostRenderTriggerEvent), true)).OnPostRenderAsync(); + } + + public UniTask OnPostRenderAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnPostRenderHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPostRenderTriggerEvent), cancellationToken, true)).OnPostRenderAsync(); + } + } +#endregion + +#region PreCull + + public interface IAsyncOnPreCullHandler + { + UniTask OnPreCullAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnPreCullHandler + { + UniTask IAsyncOnPreCullHandler.OnPreCullAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncPreCullTrigger GetAsyncPreCullTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncPreCullTrigger GetAsyncPreCullTrigger(this Component component) + { + return component.gameObject.GetAsyncPreCullTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncPreCullTrigger : AsyncTriggerBase + { + TriggerEvent onPreCullTriggerEvent; + + void OnPreCull() + { + onPreCullTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnPreCullHandler GetOnPreCullAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPreCullTriggerEvent), false); + } + + public IAsyncOnPreCullHandler GetOnPreCullAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPreCullTriggerEvent), cancellationToken, false); + } + + public UniTask OnPreCullAsync() + { + return ((IAsyncOnPreCullHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPreCullTriggerEvent), true)).OnPreCullAsync(); + } + + public UniTask OnPreCullAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnPreCullHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPreCullTriggerEvent), cancellationToken, true)).OnPreCullAsync(); + } + } +#endregion + +#region PreRender + + public interface IAsyncOnPreRenderHandler + { + UniTask OnPreRenderAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnPreRenderHandler + { + UniTask IAsyncOnPreRenderHandler.OnPreRenderAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncPreRenderTrigger GetAsyncPreRenderTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncPreRenderTrigger GetAsyncPreRenderTrigger(this Component component) + { + return component.gameObject.GetAsyncPreRenderTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncPreRenderTrigger : AsyncTriggerBase + { + TriggerEvent onPreRenderTriggerEvent; + + void OnPreRender() + { + onPreRenderTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnPreRenderHandler GetOnPreRenderAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPreRenderTriggerEvent), false); + } + + public IAsyncOnPreRenderHandler GetOnPreRenderAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPreRenderTriggerEvent), cancellationToken, false); + } + + public UniTask OnPreRenderAsync() + { + return ((IAsyncOnPreRenderHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPreRenderTriggerEvent), true)).OnPreRenderAsync(); + } + + public UniTask OnPreRenderAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnPreRenderHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPreRenderTriggerEvent), cancellationToken, true)).OnPreRenderAsync(); + } + } +#endregion + +#region RectTransformDimensionsChange + + public interface IAsyncOnRectTransformDimensionsChangeHandler + { + UniTask OnRectTransformDimensionsChangeAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnRectTransformDimensionsChangeHandler + { + UniTask IAsyncOnRectTransformDimensionsChangeHandler.OnRectTransformDimensionsChangeAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncRectTransformDimensionsChangeTrigger GetAsyncRectTransformDimensionsChangeTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncRectTransformDimensionsChangeTrigger GetAsyncRectTransformDimensionsChangeTrigger(this Component component) + { + return component.gameObject.GetAsyncRectTransformDimensionsChangeTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncRectTransformDimensionsChangeTrigger : AsyncTriggerBase + { + TriggerEvent onRectTransformDimensionsChangeTriggerEvent; + + void OnRectTransformDimensionsChange() + { + onRectTransformDimensionsChangeTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnRectTransformDimensionsChangeHandler GetOnRectTransformDimensionsChangeAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onRectTransformDimensionsChangeTriggerEvent), false); + } + + public IAsyncOnRectTransformDimensionsChangeHandler GetOnRectTransformDimensionsChangeAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onRectTransformDimensionsChangeTriggerEvent), cancellationToken, false); + } + + public UniTask OnRectTransformDimensionsChangeAsync() + { + return ((IAsyncOnRectTransformDimensionsChangeHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onRectTransformDimensionsChangeTriggerEvent), true)).OnRectTransformDimensionsChangeAsync(); + } + + public UniTask OnRectTransformDimensionsChangeAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnRectTransformDimensionsChangeHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onRectTransformDimensionsChangeTriggerEvent), cancellationToken, true)).OnRectTransformDimensionsChangeAsync(); + } + } +#endregion + +#region RectTransformRemoved + + public interface IAsyncOnRectTransformRemovedHandler + { + UniTask OnRectTransformRemovedAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnRectTransformRemovedHandler + { + UniTask IAsyncOnRectTransformRemovedHandler.OnRectTransformRemovedAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncRectTransformRemovedTrigger GetAsyncRectTransformRemovedTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncRectTransformRemovedTrigger GetAsyncRectTransformRemovedTrigger(this Component component) + { + return component.gameObject.GetAsyncRectTransformRemovedTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncRectTransformRemovedTrigger : AsyncTriggerBase + { + TriggerEvent onRectTransformRemovedTriggerEvent; + + void OnRectTransformRemoved() + { + onRectTransformRemovedTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnRectTransformRemovedHandler GetOnRectTransformRemovedAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onRectTransformRemovedTriggerEvent), false); + } + + public IAsyncOnRectTransformRemovedHandler GetOnRectTransformRemovedAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onRectTransformRemovedTriggerEvent), cancellationToken, false); + } + + public UniTask OnRectTransformRemovedAsync() + { + return ((IAsyncOnRectTransformRemovedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onRectTransformRemovedTriggerEvent), true)).OnRectTransformRemovedAsync(); + } + + public UniTask OnRectTransformRemovedAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnRectTransformRemovedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onRectTransformRemovedTriggerEvent), cancellationToken, true)).OnRectTransformRemovedAsync(); + } + } +#endregion + +#region RenderImage + + public interface IAsyncOnRenderImageHandler + { + UniTask<(RenderTexture source, RenderTexture destination)> OnRenderImageAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnRenderImageHandler + { + UniTask<(RenderTexture source, RenderTexture destination)> IAsyncOnRenderImageHandler.OnRenderImageAsync() + { + core.Reset(); + return new UniTask<(RenderTexture source, RenderTexture destination)>((IUniTaskSource<(RenderTexture source, RenderTexture destination)>)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncRenderImageTrigger GetAsyncRenderImageTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncRenderImageTrigger GetAsyncRenderImageTrigger(this Component component) + { + return component.gameObject.GetAsyncRenderImageTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncRenderImageTrigger : AsyncTriggerBase + { + TriggerEvent<(RenderTexture source, RenderTexture destination)> onRenderImageTriggerEvent; + + void OnRenderImage(RenderTexture source, RenderTexture destination) + { + onRenderImageTriggerEvent?.TrySetResult((source, destination)); + } + + public IAsyncOnRenderImageHandler GetOnRenderImageAsyncHandler() + { + return new AsyncTriggerHandler<(RenderTexture source, RenderTexture destination)>(SetTriggerEvent(ref onRenderImageTriggerEvent), false); + } + + public IAsyncOnRenderImageHandler GetOnRenderImageAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler<(RenderTexture source, RenderTexture destination)>(SetTriggerEvent(ref onRenderImageTriggerEvent), cancellationToken, false); + } + + public UniTask<(RenderTexture source, RenderTexture destination)> OnRenderImageAsync() + { + return ((IAsyncOnRenderImageHandler)new AsyncTriggerHandler<(RenderTexture source, RenderTexture destination)>(SetTriggerEvent(ref onRenderImageTriggerEvent), true)).OnRenderImageAsync(); + } + + public UniTask<(RenderTexture source, RenderTexture destination)> OnRenderImageAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnRenderImageHandler)new AsyncTriggerHandler<(RenderTexture source, RenderTexture destination)>(SetTriggerEvent(ref onRenderImageTriggerEvent), cancellationToken, true)).OnRenderImageAsync(); + } + } +#endregion + +#region RenderObject + + public interface IAsyncOnRenderObjectHandler + { + UniTask OnRenderObjectAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnRenderObjectHandler + { + UniTask IAsyncOnRenderObjectHandler.OnRenderObjectAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncRenderObjectTrigger GetAsyncRenderObjectTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncRenderObjectTrigger GetAsyncRenderObjectTrigger(this Component component) + { + return component.gameObject.GetAsyncRenderObjectTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncRenderObjectTrigger : AsyncTriggerBase + { + TriggerEvent onRenderObjectTriggerEvent; + + void OnRenderObject() + { + onRenderObjectTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnRenderObjectHandler GetOnRenderObjectAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onRenderObjectTriggerEvent), false); + } + + public IAsyncOnRenderObjectHandler GetOnRenderObjectAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onRenderObjectTriggerEvent), cancellationToken, false); + } + + public UniTask OnRenderObjectAsync() + { + return ((IAsyncOnRenderObjectHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onRenderObjectTriggerEvent), true)).OnRenderObjectAsync(); + } + + public UniTask OnRenderObjectAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnRenderObjectHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onRenderObjectTriggerEvent), cancellationToken, true)).OnRenderObjectAsync(); + } + } +#endregion + +#region ServerInitialized + + public interface IAsyncOnServerInitializedHandler + { + UniTask OnServerInitializedAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnServerInitializedHandler + { + UniTask IAsyncOnServerInitializedHandler.OnServerInitializedAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncServerInitializedTrigger GetAsyncServerInitializedTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncServerInitializedTrigger GetAsyncServerInitializedTrigger(this Component component) + { + return component.gameObject.GetAsyncServerInitializedTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncServerInitializedTrigger : AsyncTriggerBase + { + TriggerEvent onServerInitializedTriggerEvent; + + void OnServerInitialized() + { + onServerInitializedTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnServerInitializedHandler GetOnServerInitializedAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onServerInitializedTriggerEvent), false); + } + + public IAsyncOnServerInitializedHandler GetOnServerInitializedAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onServerInitializedTriggerEvent), cancellationToken, false); + } + + public UniTask OnServerInitializedAsync() + { + return ((IAsyncOnServerInitializedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onServerInitializedTriggerEvent), true)).OnServerInitializedAsync(); + } + + public UniTask OnServerInitializedAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnServerInitializedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onServerInitializedTriggerEvent), cancellationToken, true)).OnServerInitializedAsync(); + } + } +#endregion + +#region TransformChildrenChanged + + public interface IAsyncOnTransformChildrenChangedHandler + { + UniTask OnTransformChildrenChangedAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnTransformChildrenChangedHandler + { + UniTask IAsyncOnTransformChildrenChangedHandler.OnTransformChildrenChangedAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncTransformChildrenChangedTrigger GetAsyncTransformChildrenChangedTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncTransformChildrenChangedTrigger GetAsyncTransformChildrenChangedTrigger(this Component component) + { + return component.gameObject.GetAsyncTransformChildrenChangedTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncTransformChildrenChangedTrigger : AsyncTriggerBase + { + TriggerEvent onTransformChildrenChangedTriggerEvent; + + void OnTransformChildrenChanged() + { + onTransformChildrenChangedTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnTransformChildrenChangedHandler GetOnTransformChildrenChangedAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTransformChildrenChangedTriggerEvent), false); + } + + public IAsyncOnTransformChildrenChangedHandler GetOnTransformChildrenChangedAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTransformChildrenChangedTriggerEvent), cancellationToken, false); + } + + public UniTask OnTransformChildrenChangedAsync() + { + return ((IAsyncOnTransformChildrenChangedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTransformChildrenChangedTriggerEvent), true)).OnTransformChildrenChangedAsync(); + } + + public UniTask OnTransformChildrenChangedAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnTransformChildrenChangedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTransformChildrenChangedTriggerEvent), cancellationToken, true)).OnTransformChildrenChangedAsync(); + } + } +#endregion + +#region TransformParentChanged + + public interface IAsyncOnTransformParentChangedHandler + { + UniTask OnTransformParentChangedAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnTransformParentChangedHandler + { + UniTask IAsyncOnTransformParentChangedHandler.OnTransformParentChangedAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncTransformParentChangedTrigger GetAsyncTransformParentChangedTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncTransformParentChangedTrigger GetAsyncTransformParentChangedTrigger(this Component component) + { + return component.gameObject.GetAsyncTransformParentChangedTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncTransformParentChangedTrigger : AsyncTriggerBase + { + TriggerEvent onTransformParentChangedTriggerEvent; + + void OnTransformParentChanged() + { + onTransformParentChangedTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnTransformParentChangedHandler GetOnTransformParentChangedAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTransformParentChangedTriggerEvent), false); + } + + public IAsyncOnTransformParentChangedHandler GetOnTransformParentChangedAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTransformParentChangedTriggerEvent), cancellationToken, false); + } + + public UniTask OnTransformParentChangedAsync() + { + return ((IAsyncOnTransformParentChangedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTransformParentChangedTriggerEvent), true)).OnTransformParentChangedAsync(); + } + + public UniTask OnTransformParentChangedAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnTransformParentChangedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTransformParentChangedTriggerEvent), cancellationToken, true)).OnTransformParentChangedAsync(); + } + } +#endregion + +#region TriggerEnter + + public interface IAsyncOnTriggerEnterHandler + { + UniTask OnTriggerEnterAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnTriggerEnterHandler + { + UniTask IAsyncOnTriggerEnterHandler.OnTriggerEnterAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncTriggerEnterTrigger GetAsyncTriggerEnterTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncTriggerEnterTrigger GetAsyncTriggerEnterTrigger(this Component component) + { + return component.gameObject.GetAsyncTriggerEnterTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncTriggerEnterTrigger : AsyncTriggerBase + { + TriggerEvent onTriggerEnterTriggerEvent; + + void OnTriggerEnter(Collider other) + { + onTriggerEnterTriggerEvent?.TrySetResult((other)); + } + + public IAsyncOnTriggerEnterHandler GetOnTriggerEnterAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerEnterTriggerEvent), false); + } + + public IAsyncOnTriggerEnterHandler GetOnTriggerEnterAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerEnterTriggerEvent), cancellationToken, false); + } + + public UniTask OnTriggerEnterAsync() + { + return ((IAsyncOnTriggerEnterHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerEnterTriggerEvent), true)).OnTriggerEnterAsync(); + } + + public UniTask OnTriggerEnterAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnTriggerEnterHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerEnterTriggerEvent), cancellationToken, true)).OnTriggerEnterAsync(); + } + } +#endregion + +#region TriggerEnter2D + + public interface IAsyncOnTriggerEnter2DHandler + { + UniTask OnTriggerEnter2DAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnTriggerEnter2DHandler + { + UniTask IAsyncOnTriggerEnter2DHandler.OnTriggerEnter2DAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncTriggerEnter2DTrigger GetAsyncTriggerEnter2DTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncTriggerEnter2DTrigger GetAsyncTriggerEnter2DTrigger(this Component component) + { + return component.gameObject.GetAsyncTriggerEnter2DTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncTriggerEnter2DTrigger : AsyncTriggerBase + { + TriggerEvent onTriggerEnter2DTriggerEvent; + + void OnTriggerEnter2D(Collider2D other) + { + onTriggerEnter2DTriggerEvent?.TrySetResult((other)); + } + + public IAsyncOnTriggerEnter2DHandler GetOnTriggerEnter2DAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerEnter2DTriggerEvent), false); + } + + public IAsyncOnTriggerEnter2DHandler GetOnTriggerEnter2DAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerEnter2DTriggerEvent), cancellationToken, false); + } + + public UniTask OnTriggerEnter2DAsync() + { + return ((IAsyncOnTriggerEnter2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerEnter2DTriggerEvent), true)).OnTriggerEnter2DAsync(); + } + + public UniTask OnTriggerEnter2DAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnTriggerEnter2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerEnter2DTriggerEvent), cancellationToken, true)).OnTriggerEnter2DAsync(); + } + } +#endregion + +#region TriggerExit + + public interface IAsyncOnTriggerExitHandler + { + UniTask OnTriggerExitAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnTriggerExitHandler + { + UniTask IAsyncOnTriggerExitHandler.OnTriggerExitAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncTriggerExitTrigger GetAsyncTriggerExitTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncTriggerExitTrigger GetAsyncTriggerExitTrigger(this Component component) + { + return component.gameObject.GetAsyncTriggerExitTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncTriggerExitTrigger : AsyncTriggerBase + { + TriggerEvent onTriggerExitTriggerEvent; + + void OnTriggerExit(Collider other) + { + onTriggerExitTriggerEvent?.TrySetResult((other)); + } + + public IAsyncOnTriggerExitHandler GetOnTriggerExitAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerExitTriggerEvent), false); + } + + public IAsyncOnTriggerExitHandler GetOnTriggerExitAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerExitTriggerEvent), cancellationToken, false); + } + + public UniTask OnTriggerExitAsync() + { + return ((IAsyncOnTriggerExitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerExitTriggerEvent), true)).OnTriggerExitAsync(); + } + + public UniTask OnTriggerExitAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnTriggerExitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerExitTriggerEvent), cancellationToken, true)).OnTriggerExitAsync(); + } + } +#endregion + +#region TriggerExit2D + + public interface IAsyncOnTriggerExit2DHandler + { + UniTask OnTriggerExit2DAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnTriggerExit2DHandler + { + UniTask IAsyncOnTriggerExit2DHandler.OnTriggerExit2DAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncTriggerExit2DTrigger GetAsyncTriggerExit2DTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncTriggerExit2DTrigger GetAsyncTriggerExit2DTrigger(this Component component) + { + return component.gameObject.GetAsyncTriggerExit2DTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncTriggerExit2DTrigger : AsyncTriggerBase + { + TriggerEvent onTriggerExit2DTriggerEvent; + + void OnTriggerExit2D(Collider2D other) + { + onTriggerExit2DTriggerEvent?.TrySetResult((other)); + } + + public IAsyncOnTriggerExit2DHandler GetOnTriggerExit2DAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerExit2DTriggerEvent), false); + } + + public IAsyncOnTriggerExit2DHandler GetOnTriggerExit2DAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerExit2DTriggerEvent), cancellationToken, false); + } + + public UniTask OnTriggerExit2DAsync() + { + return ((IAsyncOnTriggerExit2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerExit2DTriggerEvent), true)).OnTriggerExit2DAsync(); + } + + public UniTask OnTriggerExit2DAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnTriggerExit2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerExit2DTriggerEvent), cancellationToken, true)).OnTriggerExit2DAsync(); + } + } +#endregion + +#region TriggerStay + + public interface IAsyncOnTriggerStayHandler + { + UniTask OnTriggerStayAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnTriggerStayHandler + { + UniTask IAsyncOnTriggerStayHandler.OnTriggerStayAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncTriggerStayTrigger GetAsyncTriggerStayTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncTriggerStayTrigger GetAsyncTriggerStayTrigger(this Component component) + { + return component.gameObject.GetAsyncTriggerStayTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncTriggerStayTrigger : AsyncTriggerBase + { + TriggerEvent onTriggerStayTriggerEvent; + + void OnTriggerStay(Collider other) + { + onTriggerStayTriggerEvent?.TrySetResult((other)); + } + + public IAsyncOnTriggerStayHandler GetOnTriggerStayAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerStayTriggerEvent), false); + } + + public IAsyncOnTriggerStayHandler GetOnTriggerStayAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerStayTriggerEvent), cancellationToken, false); + } + + public UniTask OnTriggerStayAsync() + { + return ((IAsyncOnTriggerStayHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerStayTriggerEvent), true)).OnTriggerStayAsync(); + } + + public UniTask OnTriggerStayAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnTriggerStayHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerStayTriggerEvent), cancellationToken, true)).OnTriggerStayAsync(); + } + } +#endregion + +#region TriggerStay2D + + public interface IAsyncOnTriggerStay2DHandler + { + UniTask OnTriggerStay2DAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnTriggerStay2DHandler + { + UniTask IAsyncOnTriggerStay2DHandler.OnTriggerStay2DAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncTriggerStay2DTrigger GetAsyncTriggerStay2DTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncTriggerStay2DTrigger GetAsyncTriggerStay2DTrigger(this Component component) + { + return component.gameObject.GetAsyncTriggerStay2DTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncTriggerStay2DTrigger : AsyncTriggerBase + { + TriggerEvent onTriggerStay2DTriggerEvent; + + void OnTriggerStay2D(Collider2D other) + { + onTriggerStay2DTriggerEvent?.TrySetResult((other)); + } + + public IAsyncOnTriggerStay2DHandler GetOnTriggerStay2DAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerStay2DTriggerEvent), false); + } + + public IAsyncOnTriggerStay2DHandler GetOnTriggerStay2DAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerStay2DTriggerEvent), cancellationToken, false); + } + + public UniTask OnTriggerStay2DAsync() + { + return ((IAsyncOnTriggerStay2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerStay2DTriggerEvent), true)).OnTriggerStay2DAsync(); + } + + public UniTask OnTriggerStay2DAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnTriggerStay2DHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onTriggerStay2DTriggerEvent), cancellationToken, true)).OnTriggerStay2DAsync(); + } + } +#endregion + +#region Validate + + public interface IAsyncOnValidateHandler + { + UniTask OnValidateAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnValidateHandler + { + UniTask IAsyncOnValidateHandler.OnValidateAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncValidateTrigger GetAsyncValidateTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncValidateTrigger GetAsyncValidateTrigger(this Component component) + { + return component.gameObject.GetAsyncValidateTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncValidateTrigger : AsyncTriggerBase + { + TriggerEvent onValidateTriggerEvent; + + void OnValidate() + { + onValidateTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnValidateHandler GetOnValidateAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onValidateTriggerEvent), false); + } + + public IAsyncOnValidateHandler GetOnValidateAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onValidateTriggerEvent), cancellationToken, false); + } + + public UniTask OnValidateAsync() + { + return ((IAsyncOnValidateHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onValidateTriggerEvent), true)).OnValidateAsync(); + } + + public UniTask OnValidateAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnValidateHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onValidateTriggerEvent), cancellationToken, true)).OnValidateAsync(); + } + } +#endregion + +#region WillRenderObject + + public interface IAsyncOnWillRenderObjectHandler + { + UniTask OnWillRenderObjectAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnWillRenderObjectHandler + { + UniTask IAsyncOnWillRenderObjectHandler.OnWillRenderObjectAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncWillRenderObjectTrigger GetAsyncWillRenderObjectTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncWillRenderObjectTrigger GetAsyncWillRenderObjectTrigger(this Component component) + { + return component.gameObject.GetAsyncWillRenderObjectTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncWillRenderObjectTrigger : AsyncTriggerBase + { + TriggerEvent onWillRenderObjectTriggerEvent; + + void OnWillRenderObject() + { + onWillRenderObjectTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncOnWillRenderObjectHandler GetOnWillRenderObjectAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onWillRenderObjectTriggerEvent), false); + } + + public IAsyncOnWillRenderObjectHandler GetOnWillRenderObjectAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onWillRenderObjectTriggerEvent), cancellationToken, false); + } + + public UniTask OnWillRenderObjectAsync() + { + return ((IAsyncOnWillRenderObjectHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onWillRenderObjectTriggerEvent), true)).OnWillRenderObjectAsync(); + } + + public UniTask OnWillRenderObjectAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnWillRenderObjectHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onWillRenderObjectTriggerEvent), cancellationToken, true)).OnWillRenderObjectAsync(); + } + } +#endregion + +#region Reset + + public interface IAsyncResetHandler + { + UniTask ResetAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncResetHandler + { + UniTask IAsyncResetHandler.ResetAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncResetTrigger GetAsyncResetTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncResetTrigger GetAsyncResetTrigger(this Component component) + { + return component.gameObject.GetAsyncResetTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncResetTrigger : AsyncTriggerBase + { + TriggerEvent resetTriggerEvent; + + void Reset() + { + resetTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncResetHandler GetResetAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref resetTriggerEvent), false); + } + + public IAsyncResetHandler GetResetAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref resetTriggerEvent), cancellationToken, false); + } + + public UniTask ResetAsync() + { + return ((IAsyncResetHandler)new AsyncTriggerHandler(SetTriggerEvent(ref resetTriggerEvent), true)).ResetAsync(); + } + + public UniTask ResetAsync(CancellationToken cancellationToken) + { + return ((IAsyncResetHandler)new AsyncTriggerHandler(SetTriggerEvent(ref resetTriggerEvent), cancellationToken, true)).ResetAsync(); + } + } +#endregion + +#region Update + + public interface IAsyncUpdateHandler + { + UniTask UpdateAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncUpdateHandler + { + UniTask IAsyncUpdateHandler.UpdateAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncUpdateTrigger GetAsyncUpdateTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncUpdateTrigger GetAsyncUpdateTrigger(this Component component) + { + return component.gameObject.GetAsyncUpdateTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncUpdateTrigger : AsyncTriggerBase + { + TriggerEvent updateTriggerEvent; + + void Update() + { + updateTriggerEvent?.TrySetResult(AsyncUnit.Default); + } + + public IAsyncUpdateHandler GetUpdateAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref updateTriggerEvent), false); + } + + public IAsyncUpdateHandler GetUpdateAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref updateTriggerEvent), cancellationToken, false); + } + + public UniTask UpdateAsync() + { + return ((IAsyncUpdateHandler)new AsyncTriggerHandler(SetTriggerEvent(ref updateTriggerEvent), true)).UpdateAsync(); + } + + public UniTask UpdateAsync(CancellationToken cancellationToken) + { + return ((IAsyncUpdateHandler)new AsyncTriggerHandler(SetTriggerEvent(ref updateTriggerEvent), cancellationToken, true)).UpdateAsync(); + } + } +#endregion + +#region BeginDrag + + public interface IAsyncOnBeginDragHandler + { + UniTask OnBeginDragAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnBeginDragHandler + { + UniTask IAsyncOnBeginDragHandler.OnBeginDragAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncBeginDragTrigger GetAsyncBeginDragTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncBeginDragTrigger GetAsyncBeginDragTrigger(this Component component) + { + return component.gameObject.GetAsyncBeginDragTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncBeginDragTrigger : AsyncTriggerBase, IBeginDragHandler + { + TriggerEvent onBeginDragTriggerEvent; + + void IBeginDragHandler.OnBeginDrag(PointerEventData eventData) + { + onBeginDragTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnBeginDragHandler GetOnBeginDragAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onBeginDragTriggerEvent), false); + } + + public IAsyncOnBeginDragHandler GetOnBeginDragAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onBeginDragTriggerEvent), cancellationToken, false); + } + + public UniTask OnBeginDragAsync() + { + return ((IAsyncOnBeginDragHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onBeginDragTriggerEvent), true)).OnBeginDragAsync(); + } + + public UniTask OnBeginDragAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnBeginDragHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onBeginDragTriggerEvent), cancellationToken, true)).OnBeginDragAsync(); + } + } +#endregion + +#region Cancel + + public interface IAsyncOnCancelHandler + { + UniTask OnCancelAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnCancelHandler + { + UniTask IAsyncOnCancelHandler.OnCancelAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncCancelTrigger GetAsyncCancelTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncCancelTrigger GetAsyncCancelTrigger(this Component component) + { + return component.gameObject.GetAsyncCancelTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncCancelTrigger : AsyncTriggerBase, ICancelHandler + { + TriggerEvent onCancelTriggerEvent; + + void ICancelHandler.OnCancel(BaseEventData eventData) + { + onCancelTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnCancelHandler GetOnCancelAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCancelTriggerEvent), false); + } + + public IAsyncOnCancelHandler GetOnCancelAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onCancelTriggerEvent), cancellationToken, false); + } + + public UniTask OnCancelAsync() + { + return ((IAsyncOnCancelHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCancelTriggerEvent), true)).OnCancelAsync(); + } + + public UniTask OnCancelAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnCancelHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onCancelTriggerEvent), cancellationToken, true)).OnCancelAsync(); + } + } +#endregion + +#region Deselect + + public interface IAsyncOnDeselectHandler + { + UniTask OnDeselectAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnDeselectHandler + { + UniTask IAsyncOnDeselectHandler.OnDeselectAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncDeselectTrigger GetAsyncDeselectTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncDeselectTrigger GetAsyncDeselectTrigger(this Component component) + { + return component.gameObject.GetAsyncDeselectTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncDeselectTrigger : AsyncTriggerBase, IDeselectHandler + { + TriggerEvent onDeselectTriggerEvent; + + void IDeselectHandler.OnDeselect(BaseEventData eventData) + { + onDeselectTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnDeselectHandler GetOnDeselectAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onDeselectTriggerEvent), false); + } + + public IAsyncOnDeselectHandler GetOnDeselectAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onDeselectTriggerEvent), cancellationToken, false); + } + + public UniTask OnDeselectAsync() + { + return ((IAsyncOnDeselectHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDeselectTriggerEvent), true)).OnDeselectAsync(); + } + + public UniTask OnDeselectAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnDeselectHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDeselectTriggerEvent), cancellationToken, true)).OnDeselectAsync(); + } + } +#endregion + +#region Drag + + public interface IAsyncOnDragHandler + { + UniTask OnDragAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnDragHandler + { + UniTask IAsyncOnDragHandler.OnDragAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncDragTrigger GetAsyncDragTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncDragTrigger GetAsyncDragTrigger(this Component component) + { + return component.gameObject.GetAsyncDragTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncDragTrigger : AsyncTriggerBase, IDragHandler + { + TriggerEvent onDragTriggerEvent; + + void IDragHandler.OnDrag(PointerEventData eventData) + { + onDragTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnDragHandler GetOnDragAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onDragTriggerEvent), false); + } + + public IAsyncOnDragHandler GetOnDragAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onDragTriggerEvent), cancellationToken, false); + } + + public UniTask OnDragAsync() + { + return ((IAsyncOnDragHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDragTriggerEvent), true)).OnDragAsync(); + } + + public UniTask OnDragAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnDragHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDragTriggerEvent), cancellationToken, true)).OnDragAsync(); + } + } +#endregion + +#region Drop + + public interface IAsyncOnDropHandler + { + UniTask OnDropAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnDropHandler + { + UniTask IAsyncOnDropHandler.OnDropAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncDropTrigger GetAsyncDropTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncDropTrigger GetAsyncDropTrigger(this Component component) + { + return component.gameObject.GetAsyncDropTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncDropTrigger : AsyncTriggerBase, IDropHandler + { + TriggerEvent onDropTriggerEvent; + + void IDropHandler.OnDrop(PointerEventData eventData) + { + onDropTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnDropHandler GetOnDropAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onDropTriggerEvent), false); + } + + public IAsyncOnDropHandler GetOnDropAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onDropTriggerEvent), cancellationToken, false); + } + + public UniTask OnDropAsync() + { + return ((IAsyncOnDropHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDropTriggerEvent), true)).OnDropAsync(); + } + + public UniTask OnDropAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnDropHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onDropTriggerEvent), cancellationToken, true)).OnDropAsync(); + } + } +#endregion + +#region EndDrag + + public interface IAsyncOnEndDragHandler + { + UniTask OnEndDragAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnEndDragHandler + { + UniTask IAsyncOnEndDragHandler.OnEndDragAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncEndDragTrigger GetAsyncEndDragTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncEndDragTrigger GetAsyncEndDragTrigger(this Component component) + { + return component.gameObject.GetAsyncEndDragTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncEndDragTrigger : AsyncTriggerBase, IEndDragHandler + { + TriggerEvent onEndDragTriggerEvent; + + void IEndDragHandler.OnEndDrag(PointerEventData eventData) + { + onEndDragTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnEndDragHandler GetOnEndDragAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onEndDragTriggerEvent), false); + } + + public IAsyncOnEndDragHandler GetOnEndDragAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onEndDragTriggerEvent), cancellationToken, false); + } + + public UniTask OnEndDragAsync() + { + return ((IAsyncOnEndDragHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onEndDragTriggerEvent), true)).OnEndDragAsync(); + } + + public UniTask OnEndDragAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnEndDragHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onEndDragTriggerEvent), cancellationToken, true)).OnEndDragAsync(); + } + } +#endregion + +#region InitializePotentialDrag + + public interface IAsyncOnInitializePotentialDragHandler + { + UniTask OnInitializePotentialDragAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnInitializePotentialDragHandler + { + UniTask IAsyncOnInitializePotentialDragHandler.OnInitializePotentialDragAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncInitializePotentialDragTrigger GetAsyncInitializePotentialDragTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncInitializePotentialDragTrigger GetAsyncInitializePotentialDragTrigger(this Component component) + { + return component.gameObject.GetAsyncInitializePotentialDragTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncInitializePotentialDragTrigger : AsyncTriggerBase, IInitializePotentialDragHandler + { + TriggerEvent onInitializePotentialDragTriggerEvent; + + void IInitializePotentialDragHandler.OnInitializePotentialDrag(PointerEventData eventData) + { + onInitializePotentialDragTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnInitializePotentialDragHandler GetOnInitializePotentialDragAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onInitializePotentialDragTriggerEvent), false); + } + + public IAsyncOnInitializePotentialDragHandler GetOnInitializePotentialDragAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onInitializePotentialDragTriggerEvent), cancellationToken, false); + } + + public UniTask OnInitializePotentialDragAsync() + { + return ((IAsyncOnInitializePotentialDragHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onInitializePotentialDragTriggerEvent), true)).OnInitializePotentialDragAsync(); + } + + public UniTask OnInitializePotentialDragAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnInitializePotentialDragHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onInitializePotentialDragTriggerEvent), cancellationToken, true)).OnInitializePotentialDragAsync(); + } + } +#endregion + +#region Move + + public interface IAsyncOnMoveHandler + { + UniTask OnMoveAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnMoveHandler + { + UniTask IAsyncOnMoveHandler.OnMoveAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncMoveTrigger GetAsyncMoveTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncMoveTrigger GetAsyncMoveTrigger(this Component component) + { + return component.gameObject.GetAsyncMoveTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncMoveTrigger : AsyncTriggerBase, IMoveHandler + { + TriggerEvent onMoveTriggerEvent; + + void IMoveHandler.OnMove(AxisEventData eventData) + { + onMoveTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnMoveHandler GetOnMoveAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMoveTriggerEvent), false); + } + + public IAsyncOnMoveHandler GetOnMoveAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onMoveTriggerEvent), cancellationToken, false); + } + + public UniTask OnMoveAsync() + { + return ((IAsyncOnMoveHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMoveTriggerEvent), true)).OnMoveAsync(); + } + + public UniTask OnMoveAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnMoveHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onMoveTriggerEvent), cancellationToken, true)).OnMoveAsync(); + } + } +#endregion + +#region PointerClick + + public interface IAsyncOnPointerClickHandler + { + UniTask OnPointerClickAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnPointerClickHandler + { + UniTask IAsyncOnPointerClickHandler.OnPointerClickAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncPointerClickTrigger GetAsyncPointerClickTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncPointerClickTrigger GetAsyncPointerClickTrigger(this Component component) + { + return component.gameObject.GetAsyncPointerClickTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncPointerClickTrigger : AsyncTriggerBase, IPointerClickHandler + { + TriggerEvent onPointerClickTriggerEvent; + + void IPointerClickHandler.OnPointerClick(PointerEventData eventData) + { + onPointerClickTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnPointerClickHandler GetOnPointerClickAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPointerClickTriggerEvent), false); + } + + public IAsyncOnPointerClickHandler GetOnPointerClickAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPointerClickTriggerEvent), cancellationToken, false); + } + + public UniTask OnPointerClickAsync() + { + return ((IAsyncOnPointerClickHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPointerClickTriggerEvent), true)).OnPointerClickAsync(); + } + + public UniTask OnPointerClickAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnPointerClickHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPointerClickTriggerEvent), cancellationToken, true)).OnPointerClickAsync(); + } + } +#endregion + +#region PointerDown + + public interface IAsyncOnPointerDownHandler + { + UniTask OnPointerDownAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnPointerDownHandler + { + UniTask IAsyncOnPointerDownHandler.OnPointerDownAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncPointerDownTrigger GetAsyncPointerDownTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncPointerDownTrigger GetAsyncPointerDownTrigger(this Component component) + { + return component.gameObject.GetAsyncPointerDownTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncPointerDownTrigger : AsyncTriggerBase, IPointerDownHandler + { + TriggerEvent onPointerDownTriggerEvent; + + void IPointerDownHandler.OnPointerDown(PointerEventData eventData) + { + onPointerDownTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnPointerDownHandler GetOnPointerDownAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPointerDownTriggerEvent), false); + } + + public IAsyncOnPointerDownHandler GetOnPointerDownAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPointerDownTriggerEvent), cancellationToken, false); + } + + public UniTask OnPointerDownAsync() + { + return ((IAsyncOnPointerDownHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPointerDownTriggerEvent), true)).OnPointerDownAsync(); + } + + public UniTask OnPointerDownAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnPointerDownHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPointerDownTriggerEvent), cancellationToken, true)).OnPointerDownAsync(); + } + } +#endregion + +#region PointerEnter + + public interface IAsyncOnPointerEnterHandler + { + UniTask OnPointerEnterAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnPointerEnterHandler + { + UniTask IAsyncOnPointerEnterHandler.OnPointerEnterAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncPointerEnterTrigger GetAsyncPointerEnterTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncPointerEnterTrigger GetAsyncPointerEnterTrigger(this Component component) + { + return component.gameObject.GetAsyncPointerEnterTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncPointerEnterTrigger : AsyncTriggerBase, IPointerEnterHandler + { + TriggerEvent onPointerEnterTriggerEvent; + + void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData) + { + onPointerEnterTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnPointerEnterHandler GetOnPointerEnterAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPointerEnterTriggerEvent), false); + } + + public IAsyncOnPointerEnterHandler GetOnPointerEnterAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPointerEnterTriggerEvent), cancellationToken, false); + } + + public UniTask OnPointerEnterAsync() + { + return ((IAsyncOnPointerEnterHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPointerEnterTriggerEvent), true)).OnPointerEnterAsync(); + } + + public UniTask OnPointerEnterAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnPointerEnterHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPointerEnterTriggerEvent), cancellationToken, true)).OnPointerEnterAsync(); + } + } +#endregion + +#region PointerExit + + public interface IAsyncOnPointerExitHandler + { + UniTask OnPointerExitAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnPointerExitHandler + { + UniTask IAsyncOnPointerExitHandler.OnPointerExitAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncPointerExitTrigger GetAsyncPointerExitTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncPointerExitTrigger GetAsyncPointerExitTrigger(this Component component) + { + return component.gameObject.GetAsyncPointerExitTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncPointerExitTrigger : AsyncTriggerBase, IPointerExitHandler + { + TriggerEvent onPointerExitTriggerEvent; + + void IPointerExitHandler.OnPointerExit(PointerEventData eventData) + { + onPointerExitTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnPointerExitHandler GetOnPointerExitAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPointerExitTriggerEvent), false); + } + + public IAsyncOnPointerExitHandler GetOnPointerExitAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPointerExitTriggerEvent), cancellationToken, false); + } + + public UniTask OnPointerExitAsync() + { + return ((IAsyncOnPointerExitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPointerExitTriggerEvent), true)).OnPointerExitAsync(); + } + + public UniTask OnPointerExitAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnPointerExitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPointerExitTriggerEvent), cancellationToken, true)).OnPointerExitAsync(); + } + } +#endregion + +#region PointerUp + + public interface IAsyncOnPointerUpHandler + { + UniTask OnPointerUpAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnPointerUpHandler + { + UniTask IAsyncOnPointerUpHandler.OnPointerUpAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncPointerUpTrigger GetAsyncPointerUpTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncPointerUpTrigger GetAsyncPointerUpTrigger(this Component component) + { + return component.gameObject.GetAsyncPointerUpTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncPointerUpTrigger : AsyncTriggerBase, IPointerUpHandler + { + TriggerEvent onPointerUpTriggerEvent; + + void IPointerUpHandler.OnPointerUp(PointerEventData eventData) + { + onPointerUpTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnPointerUpHandler GetOnPointerUpAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPointerUpTriggerEvent), false); + } + + public IAsyncOnPointerUpHandler GetOnPointerUpAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onPointerUpTriggerEvent), cancellationToken, false); + } + + public UniTask OnPointerUpAsync() + { + return ((IAsyncOnPointerUpHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPointerUpTriggerEvent), true)).OnPointerUpAsync(); + } + + public UniTask OnPointerUpAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnPointerUpHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onPointerUpTriggerEvent), cancellationToken, true)).OnPointerUpAsync(); + } + } +#endregion + +#region Scroll + + public interface IAsyncOnScrollHandler + { + UniTask OnScrollAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnScrollHandler + { + UniTask IAsyncOnScrollHandler.OnScrollAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncScrollTrigger GetAsyncScrollTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncScrollTrigger GetAsyncScrollTrigger(this Component component) + { + return component.gameObject.GetAsyncScrollTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncScrollTrigger : AsyncTriggerBase, IScrollHandler + { + TriggerEvent onScrollTriggerEvent; + + void IScrollHandler.OnScroll(PointerEventData eventData) + { + onScrollTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnScrollHandler GetOnScrollAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onScrollTriggerEvent), false); + } + + public IAsyncOnScrollHandler GetOnScrollAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onScrollTriggerEvent), cancellationToken, false); + } + + public UniTask OnScrollAsync() + { + return ((IAsyncOnScrollHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onScrollTriggerEvent), true)).OnScrollAsync(); + } + + public UniTask OnScrollAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnScrollHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onScrollTriggerEvent), cancellationToken, true)).OnScrollAsync(); + } + } +#endregion + +#region Select + + public interface IAsyncOnSelectHandler + { + UniTask OnSelectAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnSelectHandler + { + UniTask IAsyncOnSelectHandler.OnSelectAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncSelectTrigger GetAsyncSelectTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncSelectTrigger GetAsyncSelectTrigger(this Component component) + { + return component.gameObject.GetAsyncSelectTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncSelectTrigger : AsyncTriggerBase, ISelectHandler + { + TriggerEvent onSelectTriggerEvent; + + void ISelectHandler.OnSelect(BaseEventData eventData) + { + onSelectTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnSelectHandler GetOnSelectAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onSelectTriggerEvent), false); + } + + public IAsyncOnSelectHandler GetOnSelectAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onSelectTriggerEvent), cancellationToken, false); + } + + public UniTask OnSelectAsync() + { + return ((IAsyncOnSelectHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onSelectTriggerEvent), true)).OnSelectAsync(); + } + + public UniTask OnSelectAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnSelectHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onSelectTriggerEvent), cancellationToken, true)).OnSelectAsync(); + } + } +#endregion + +#region Submit + + public interface IAsyncOnSubmitHandler + { + UniTask OnSubmitAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnSubmitHandler + { + UniTask IAsyncOnSubmitHandler.OnSubmitAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncSubmitTrigger GetAsyncSubmitTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncSubmitTrigger GetAsyncSubmitTrigger(this Component component) + { + return component.gameObject.GetAsyncSubmitTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncSubmitTrigger : AsyncTriggerBase, ISubmitHandler + { + TriggerEvent onSubmitTriggerEvent; + + void ISubmitHandler.OnSubmit(BaseEventData eventData) + { + onSubmitTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnSubmitHandler GetOnSubmitAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onSubmitTriggerEvent), false); + } + + public IAsyncOnSubmitHandler GetOnSubmitAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onSubmitTriggerEvent), cancellationToken, false); + } + + public UniTask OnSubmitAsync() + { + return ((IAsyncOnSubmitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onSubmitTriggerEvent), true)).OnSubmitAsync(); + } + + public UniTask OnSubmitAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnSubmitHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onSubmitTriggerEvent), cancellationToken, true)).OnSubmitAsync(); + } + } +#endregion + +#region UpdateSelected + + public interface IAsyncOnUpdateSelectedHandler + { + UniTask OnUpdateSelectedAsync(); + } + + public partial class AsyncTriggerHandler : IAsyncOnUpdateSelectedHandler + { + UniTask IAsyncOnUpdateSelectedHandler.OnUpdateSelectedAsync() + { + core.Reset(); + return new UniTask((IUniTaskSource)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static AsyncUpdateSelectedTrigger GetAsyncUpdateSelectedTrigger(this GameObject gameObject) + { + return GetOrAddComponent(gameObject); + } + + public static AsyncUpdateSelectedTrigger GetAsyncUpdateSelectedTrigger(this Component component) + { + return component.gameObject.GetAsyncUpdateSelectedTrigger(); + } + } + + [DisallowMultipleComponent] + public sealed class AsyncUpdateSelectedTrigger : AsyncTriggerBase, IUpdateSelectedHandler + { + TriggerEvent onUpdateSelectedTriggerEvent; + + void IUpdateSelectedHandler.OnUpdateSelected(BaseEventData eventData) + { + onUpdateSelectedTriggerEvent?.TrySetResult((eventData)); + } + + public IAsyncOnUpdateSelectedHandler GetOnUpdateSelectedAsyncHandler() + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onUpdateSelectedTriggerEvent), false); + } + + public IAsyncOnUpdateSelectedHandler GetOnUpdateSelectedAsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler(SetTriggerEvent(ref onUpdateSelectedTriggerEvent), cancellationToken, false); + } + + public UniTask OnUpdateSelectedAsync() + { + return ((IAsyncOnUpdateSelectedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onUpdateSelectedTriggerEvent), true)).OnUpdateSelectedAsync(); + } + + public UniTask OnUpdateSelectedAsync(CancellationToken cancellationToken) + { + return ((IAsyncOnUpdateSelectedHandler)new AsyncTriggerHandler(SetTriggerEvent(ref onUpdateSelectedTriggerEvent), cancellationToken, true)).OnUpdateSelectedAsync(); + } + } +#endregion + +} \ No newline at end of file diff --git a/Assets/UniRx.Async/Triggers/MonoBehaviourMessagesTriggers.tt b/Assets/UniRx.Async/Triggers/MonoBehaviourMessagesTriggers.tt new file mode 100644 index 0000000..b2b56d7 --- /dev/null +++ b/Assets/UniRx.Async/Triggers/MonoBehaviourMessagesTriggers.tt @@ -0,0 +1,186 @@ +<#@ template debug="false" hostspecific="false" language="C#" #> +<#@ assembly name="System.Core" #> +<#@ import namespace="System.Linq" #> +<#@ import namespace="System.Text" #> +<#@ import namespace="System.Collections.Generic" #> +<#@ output extension=".cs" #> +<# + var empty = new (string, string)[0]; + + var triggers = new (string triggerName, string methodName, string returnType, string handlerInterface, (string argType, string argName)[] arguments)[] + { + ("AnimatorIK", "OnAnimatorIK", "int", null, new []{ ("int", "layerIndex") }), + ("AnimatorMove", "OnAnimatorMove", "AsyncUnit", null, empty), + ("OnCanvasGroupChanged", "OnCanvasGroupChanged", "AsyncUnit", null, empty ), + ("CollisionEnter2D", "OnCollisionEnter2D", "Collision2D", null, new []{ ("Collision2D", "coll") }), + ("CollisionExit2D", "OnCollisionExit2D", "Collision2D", null, new []{ ("Collision2D", "coll") }), + ("CollisionStay2D", "OnCollisionStay2D", "Collision2D", null, new []{ ("Collision2D", "coll") }), + ("CollisionEnter", "OnCollisionEnter", "Collision", null, new []{ ("Collision", "coll") }), + ("CollisionExit", "OnCollisionExit", "Collision", null, new []{ ("Collision", "coll") }), + ("CollisionStay", "OnCollisionStay", "Collision", null, new []{ ("Collision", "coll") }), + ("Enable", "OnEnable", "AsyncUnit", null, empty), + ("Disable", "OnDisable", "AsyncUnit", null, empty), + ("JointBreak", "OnJointBreak", "float", null, new []{ ("float", "breakForce") }), + ("JointBreak2D", "OnJointBreak2D", "Joint2D", null, new []{ ("Joint2D", "brokenJoint") }), + ("Update", "Update", "AsyncUnit", null, empty), + ("FixedUpdate", "FixedUpdate", "AsyncUnit", null, empty), + ("LateUpdate", "LateUpdate", "AsyncUnit", null, empty), + ("MouseDown", "OnMouseDown", "AsyncUnit", null, empty), + ("MouseDrag", "OnMouseDrag", "AsyncUnit", null, empty), + ("MouseEnter", "OnMouseEnter", "AsyncUnit", null, empty), + ("MouseExit", "OnMouseExit", "AsyncUnit", null, empty), + ("MouseOver", "OnMouseOver", "AsyncUnit", null, empty), + ("MouseUp", "OnMouseUp", "AsyncUnit", null, empty), + ("MouseUpAsButton", "OnMouseUpAsButton", "AsyncUnit", null, empty), + ("ParticleCollision", "OnParticleCollision", "GameObject", null, new []{ ("GameObject", "other") }), + ("RectTransformDimensionsChange", "OnRectTransformDimensionsChange", "AsyncUnit", null, empty), + ("RectTransformRemoved", "OnRectTransformRemoved", "AsyncUnit", null, empty), + ("BeforeTransformParentChanged", "OnBeforeTransformParentChanged", "AsyncUnit", null, empty), + ("TransformParentChanged", "OnTransformParentChanged", "AsyncUnit", null, empty), + ("TransformChildrenChanged", "OnTransformChildrenChanged", "AsyncUnit", null, empty), + ("TriggerEnter2D", "OnTriggerEnter2D", "Collider2D", null, new []{ ("Collider2D", "other") }), + ("TriggerExit2D", "OnTriggerExit2D", "Collider2D", null, new []{ ("Collider2D", "other") }), + ("TriggerStay2D", "OnTriggerStay2D", "Collider2D", null, new []{ ("Collider2D", "other") }), + ("TriggerEnter", "OnTriggerEnter", "Collider", null, new []{ ("Collider", "other") }), + ("TriggerExit", "OnTriggerExit", "Collider", null, new []{ ("Collider", "other") }), + ("TriggerStay", "OnTriggerStay", "Collider", null, new []{ ("Collider", "other") }), + ("BecameInvisible", "OnBecameInvisible", "AsyncUnit", null, empty), + ("BecameVisible", "OnBecameVisible", "AsyncUnit", null, empty), + + // new in v2 + ("ApplicationFocus", "OnApplicationFocus", "bool", null, new []{("bool", "hasFocus") }), + ("ApplicationPause", "OnApplicationPause", "bool", null, new []{("bool", "pauseStatus") }), + ("ApplicationQuit", "OnApplicationQuit", "AsyncUnit", null, empty), + ("AudioFilterRead", "OnAudioFilterRead", "(float[] data, int channels)", null, new[]{("float[]", "data"), ("int", "channels")}), + ("ControllerColliderHit", "OnControllerColliderHit", "ControllerColliderHit", null, new[]{("ControllerColliderHit", "hit")}), + ("DrawGizmos", "OnDrawGizmos", "AsyncUnit", null, empty), + ("DrawGizmosSelected", "OnDrawGizmosSelected", "AsyncUnit", null, empty), + ("GUI", "OnGUI", "AsyncUnit", null, empty), + ("ParticleSystemStopped", "OnParticleSystemStopped", "AsyncUnit", null, empty), + ("ParticleTrigger", "OnParticleTrigger", "AsyncUnit", null, empty), + ("PostRender", "OnPostRender", "AsyncUnit", null, empty), + ("PreCull", "OnPreCull", "AsyncUnit", null, empty), + ("PreRender", "OnPreRender", "AsyncUnit", null, empty), + ("RenderImage", "OnRenderImage", "(RenderTexture source, RenderTexture destination)", null, new[]{("RenderTexture", "source"), ("RenderTexture", "destination")}), + ("RenderObject", "OnRenderObject", "AsyncUnit", null, empty), + ("ServerInitialized", "OnServerInitialized", "AsyncUnit", null, empty), + ("Validate", "OnValidate", "AsyncUnit", null, empty), + ("WillRenderObject", "OnWillRenderObject", "AsyncUnit", null, empty), + ("Reset", "Reset", "AsyncUnit", null, empty), + + // uGUI + ("BeginDrag", "OnBeginDrag", "PointerEventData", "IBeginDragHandler", new []{ ("PointerEventData", "eventData") }), + ("Cancel", "OnCancel", "BaseEventData", "ICancelHandler", new []{ ("BaseEventData", "eventData") }), + ("Deselect", "OnDeselect", "BaseEventData", "IDeselectHandler", new []{ ("BaseEventData", "eventData") }), + ("Drag", "OnDrag", "PointerEventData", "IDragHandler", new []{ ("PointerEventData", "eventData") }), + ("Drop", "OnDrop", "PointerEventData", "IDropHandler", new []{ ("PointerEventData", "eventData") }), + ("EndDrag", "OnEndDrag", "PointerEventData", "IEndDragHandler", new []{ ("PointerEventData", "eventData") }), + ("InitializePotentialDrag", "OnInitializePotentialDrag", "PointerEventData", "IInitializePotentialDragHandler", new []{ ("PointerEventData", "eventData") }), + ("Move", "OnMove", "AxisEventData", "IMoveHandler", new []{ ("AxisEventData", "eventData") }), + ("PointerClick", "OnPointerClick", "PointerEventData", "IPointerClickHandler", new []{ ("PointerEventData", "eventData") }), + ("PointerDown", "OnPointerDown", "PointerEventData", "IPointerDownHandler", new []{ ("PointerEventData", "eventData") }), + ("PointerEnter", "OnPointerEnter", "PointerEventData", "IPointerEnterHandler", new []{ ("PointerEventData", "eventData") }), + ("PointerExit", "OnPointerExit", "PointerEventData", "IPointerExitHandler", new []{ ("PointerEventData", "eventData") }), + ("PointerUp", "OnPointerUp", "PointerEventData", "IPointerUpHandler", new []{ ("PointerEventData", "eventData") }), + ("Scroll", "OnScroll", "PointerEventData", "IScrollHandler", new []{ ("PointerEventData", "eventData") }), + ("Select", "OnSelect", "BaseEventData", "ISelectHandler", new []{ ("BaseEventData", "eventData") }), + ("Submit", "OnSubmit", "BaseEventData", "ISubmitHandler", new []{ ("BaseEventData", "eventData") }), + ("UpdateSelected", "OnUpdateSelected", "BaseEventData", "IUpdateSelectedHandler", new []{ ("BaseEventData", "eventData") }), + + // 2019.3 + ("ParticleUpdateJobScheduled", "OnParticleUpdateJobScheduled", "UnityEngine.ParticleSystemJobs.ParticleSystemJobData", null, new[]{("UnityEngine.ParticleSystemJobs.ParticleSystemJobData", "particles")}), + + // Oneshot + // Awake, Start, Destroy + }; + + triggers = triggers.OrderBy(x => x.handlerInterface != null).ThenBy(x => x.handlerInterface != null ? x.handlerInterface : x.methodName).ToArray(); + + Func ToInterfaceName = x => $"IAsync{x}Handler"; + Func ToUniTaskName = x => x == "AsyncUnit" ? "UniTask" : $"UniTask<{x}>"; + Func ToCastUniTasSourceType = x => x == "AsyncUnit" ? "IUniTaskSource" : $"IUniTaskSource<{x}>"; + Func TriggerFieldName = x => char.ToLowerInvariant(x[0]) + x.Substring(1, x.Length - 1) + "TriggerEvent"; + Func OnInvokeSuffix = x => x == "AsyncUnit" ? ".AsUniTask()" : $""; + Func<(string argType, string argName)[], string> BuildMethodArgument = x => string.Join(", ", x.Select(y => y.argType + " " + y.argName)); + Func<(string argType, string argName)[], string> BuildResultParameter = x => x.Length == 0 ? "AsyncUnit.Default" : "(" + string.Join(", ", x.Select(y => y.argName)) + ")"; + + Func Is2019_3 = x => x == "ParticleUpdateJobScheduled"; +#> +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member + +using System.Threading; +using UnityEngine; +using UnityEngine.EventSystems; + +namespace UniRx.Async.Triggers +{ +<# foreach(var t in triggers) { #> +#region <#= t.triggerName #> +<# if(Is2019_3(t.triggerName)) { #> +#if UNITY_2019_3_OR_NEWER +<# } #> + + public interface <#= ToInterfaceName(t.methodName) #> + { + <#= ToUniTaskName(t.returnType) #> <#= t.methodName #>Async(); + } + + public partial class AsyncTriggerHandler : <#= ToInterfaceName(t.methodName) #> + { + <#= ToUniTaskName(t.returnType) #> <#= ToInterfaceName(t.methodName) #>.<#= t.methodName #>Async() + { + core.Reset(); + return new <#= ToUniTaskName(t.returnType) #>((<#= ToCastUniTasSourceType(t.returnType) #>)(object)this, core.Version); + } + } + + public static partial class AsyncTriggerExtensions + { + public static Async<#= t.triggerName #>Trigger GetAsync<#= t.triggerName #>Trigger(this GameObject gameObject) + { + return GetOrAddComponentTrigger>(gameObject); + } + + public static Async<#= t.triggerName #>Trigger GetAsync<#= t.triggerName #>Trigger(this Component component) + { + return component.gameObject.GetAsync<#= t.triggerName #>Trigger(); + } + } + + [DisallowMultipleComponent] + public sealed class Async<#= t.triggerName #>Trigger : AsyncTriggerBase<#= (t.handlerInterface == null) ? "" : $", {t.handlerInterface}" #> + { + TriggerEvent<<#= t.returnType #>> <#= TriggerFieldName(t.methodName) #>; + + void <#= (t.handlerInterface == null) ? "" : $"{t.handlerInterface}." #><#= t.methodName #>(<#= BuildMethodArgument(t.arguments) #>) + { + <#= TriggerFieldName(t.methodName) #>?.TrySetResult(<#= BuildResultParameter(t.arguments) #>); + } + + public <#= ToInterfaceName(t.methodName) #> Get<#= t.methodName #>AsyncHandler() + { + return new AsyncTriggerHandler<<#= t.returnType #>>(SetTriggerEvent(ref <#= TriggerFieldName(t.methodName) #>), false); + } + + public <#= ToInterfaceName(t.methodName) #> Get<#= t.methodName #>AsyncHandler(CancellationToken cancellationToken) + { + return new AsyncTriggerHandler<<#= t.returnType #>>(SetTriggerEvent(ref <#= TriggerFieldName(t.methodName) #>), cancellationToken, false); + } + + public <#= ToUniTaskName(t.returnType) #> <#= t.methodName #>Async() + { + return ((<#= ToInterfaceName(t.methodName) #>)new AsyncTriggerHandler<<#= t.returnType #>>(SetTriggerEvent(ref <#= TriggerFieldName(t.methodName) #>), true)).<#= t.methodName #>Async(); + } + + public <#= ToUniTaskName(t.returnType) #> <#= t.methodName #>Async(CancellationToken cancellationToken) + { + return ((<#= ToInterfaceName(t.methodName) #>)new AsyncTriggerHandler<<#= t.returnType #>>(SetTriggerEvent(ref <#= TriggerFieldName(t.methodName) #>), cancellationToken, true)).<#= t.methodName #>Async(); + } + } +<# if(Is2019_3(t.triggerName)) { #> +#endif +<# } #> +#endregion + +<# } #> +} \ No newline at end of file diff --git a/Assets/UniRx.Async/UniTask.Delay.cs b/Assets/UniRx.Async/UniTask.Delay.cs index df3f4ef..05048d4 100644 --- a/Assets/UniRx.Async/UniTask.Delay.cs +++ b/Assets/UniRx.Async/UniTask.Delay.cs @@ -79,7 +79,7 @@ namespace UniRx.Async result.cancellationToken = cancellationToken; - TaskTracker2.TrackActiveTask(result, 3); + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -91,7 +91,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); core.GetResult(token); } finally @@ -168,7 +168,7 @@ namespace UniRx.Async result.delayFrameCount = delayFrameCount; result.cancellationToken = cancellationToken; - TaskTracker2.TrackActiveTask(result, 3); + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -180,7 +180,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); core.GetResult(token); } finally @@ -266,7 +266,7 @@ namespace UniRx.Async result.delayFrameTimeSpan = (float)delayFrameTimeSpan.TotalSeconds; result.cancellationToken = cancellationToken; - TaskTracker2.TrackActiveTask(result, 3); + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -278,7 +278,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); core.GetResult(token); } finally @@ -364,7 +364,7 @@ namespace UniRx.Async result.delayFrameTimeSpan = (float)delayFrameTimeSpan.TotalSeconds; result.cancellationToken = cancellationToken; - TaskTracker2.TrackActiveTask(result, 3); + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -376,7 +376,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); core.GetResult(token); } finally diff --git a/Assets/UniRx.Async/UniTask.WaitUntil.cs b/Assets/UniRx.Async/UniTask.WaitUntil.cs index 554dc59..877fe2f 100644 --- a/Assets/UniRx.Async/UniTask.WaitUntil.cs +++ b/Assets/UniRx.Async/UniTask.WaitUntil.cs @@ -56,7 +56,7 @@ namespace UniRx.Async result.predicate = predicate; result.cancellationToken = cancellationToken; - TaskTracker2.TrackActiveTask(result, 3); + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -68,7 +68,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); core.GetResult(token); } finally @@ -158,7 +158,7 @@ namespace UniRx.Async result.predicate = predicate; result.cancellationToken = cancellationToken; - TaskTracker2.TrackActiveTask(result, 3); + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -170,7 +170,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); core.GetResult(token); } finally @@ -267,7 +267,7 @@ namespace UniRx.Async result.equalityComparer = equalityComparer ?? UnityEqualityComparer.GetDefault(); result.cancellationToken = cancellationToken; - TaskTracker2.TrackActiveTask(result, 3); + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -279,7 +279,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); return core.GetResult(token); } finally @@ -387,7 +387,7 @@ namespace UniRx.Async result.equalityComparer = equalityComparer ?? UnityEqualityComparer.GetDefault(); result.cancellationToken = cancellationToken; - TaskTracker2.TrackActiveTask(result, 3); + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -399,7 +399,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); return core.GetResult(token); } finally diff --git a/Assets/UniRx.Async/UniTask.WhenAll.Generated.cs b/Assets/UniRx.Async/UniTask.WhenAll.Generated.cs index 8652192..95c6a4c 100644 --- a/Assets/UniRx.Async/UniTask.WhenAll.Generated.cs +++ b/Assets/UniRx.Async/UniTask.WhenAll.Generated.cs @@ -29,7 +29,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask task1, UniTask task2) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -107,7 +107,7 @@ namespace UniRx.Async public (T1, T2) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -158,7 +158,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -271,7 +271,7 @@ namespace UniRx.Async public (T1, T2, T3) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -323,7 +323,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -471,7 +471,7 @@ namespace UniRx.Async public (T1, T2, T3, T4) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -524,7 +524,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -707,7 +707,7 @@ namespace UniRx.Async public (T1, T2, T3, T4, T5) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -761,7 +761,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -979,7 +979,7 @@ namespace UniRx.Async public (T1, T2, T3, T4, T5, T6) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -1034,7 +1034,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -1287,7 +1287,7 @@ namespace UniRx.Async public (T1, T2, T3, T4, T5, T6, T7) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -1343,7 +1343,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -1631,7 +1631,7 @@ namespace UniRx.Async public (T1, T2, T3, T4, T5, T6, T7, T8) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -1688,7 +1688,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -2011,7 +2011,7 @@ namespace UniRx.Async public (T1, T2, T3, T4, T5, T6, T7, T8, T9) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -2069,7 +2069,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -2427,7 +2427,7 @@ namespace UniRx.Async public (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -2486,7 +2486,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -2879,7 +2879,7 @@ namespace UniRx.Async public (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -2939,7 +2939,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -3367,7 +3367,7 @@ namespace UniRx.Async public (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -3428,7 +3428,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -3891,7 +3891,7 @@ namespace UniRx.Async public (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -3953,7 +3953,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -4451,7 +4451,7 @@ namespace UniRx.Async public (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -4514,7 +4514,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14, UniTask task15) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -5047,7 +5047,7 @@ namespace UniRx.Async public (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } diff --git a/Assets/UniRx.Async/UniTask.WhenAll.cs b/Assets/UniRx.Async/UniTask.WhenAll.cs index e9a83d7..ed6f2dc 100644 --- a/Assets/UniRx.Async/UniTask.WhenAll.cs +++ b/Assets/UniRx.Async/UniTask.WhenAll.cs @@ -17,7 +17,7 @@ namespace UniRx.Async public static UniTask WhenAll(IEnumerable> tasks) { - using (var span = ArrayPoolUtil.Materialize(tasks)) + using (var span = ArrayPoolUtil.CopyToRentArray(tasks)) { var promise = new WhenAllPromise(span.Array, span.Length); // consumed array in constructor. return new UniTask(promise, 0); @@ -31,7 +31,7 @@ namespace UniRx.Async public static UniTask WhenAll(IEnumerable tasks) { - using (var span = ArrayPoolUtil.Materialize(tasks)) + using (var span = ArrayPoolUtil.CopyToRentArray(tasks)) { var promise = new WhenAllPromise(span.Array, span.Length); // consumed array in constructor. return new UniTask(promise, 0); @@ -46,7 +46,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask[] tasks, int tasksLength) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completeCount = 0; this.result = new T[tasksLength]; @@ -101,7 +101,7 @@ namespace UniRx.Async public T[] GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -140,7 +140,7 @@ namespace UniRx.Async public WhenAllPromise(UniTask[] tasks, int tasksLength) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.tasksLength = tasksLength; this.completeCount = 0; @@ -195,7 +195,7 @@ namespace UniRx.Async public void GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); core.GetResult(token); } diff --git a/Assets/UniRx.Async/UniTask.WhenAny.Generated.cs b/Assets/UniRx.Async/UniTask.WhenAny.Generated.cs index 14a29b6..9178472 100644 --- a/Assets/UniRx.Async/UniTask.WhenAny.Generated.cs +++ b/Assets/UniRx.Async/UniTask.WhenAny.Generated.cs @@ -21,7 +21,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask task1, UniTask task2) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -103,7 +103,7 @@ namespace UniRx.Async public (int, T1 result1, T2 result2) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -146,7 +146,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -265,7 +265,7 @@ namespace UniRx.Async public (int, T1 result1, T2 result2, T3 result3) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -308,7 +308,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -464,7 +464,7 @@ namespace UniRx.Async public (int, T1 result1, T2 result2, T3 result3, T4 result4) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -507,7 +507,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -700,7 +700,7 @@ namespace UniRx.Async public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -743,7 +743,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -973,7 +973,7 @@ namespace UniRx.Async public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -1016,7 +1016,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -1283,7 +1283,7 @@ namespace UniRx.Async public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -1326,7 +1326,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -1630,7 +1630,7 @@ namespace UniRx.Async public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -1673,7 +1673,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -2014,7 +2014,7 @@ namespace UniRx.Async public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -2057,7 +2057,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -2435,7 +2435,7 @@ namespace UniRx.Async public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -2478,7 +2478,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -2893,7 +2893,7 @@ namespace UniRx.Async public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -2936,7 +2936,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -3388,7 +3388,7 @@ namespace UniRx.Async public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -3431,7 +3431,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -3920,7 +3920,7 @@ namespace UniRx.Async public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12, T13 result13) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -3963,7 +3963,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -4489,7 +4489,7 @@ namespace UniRx.Async public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12, T13 result13, T14 result14) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -4532,7 +4532,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask task1, UniTask task2, UniTask task3, UniTask task4, UniTask task5, UniTask task6, UniTask task7, UniTask task8, UniTask task9, UniTask task10, UniTask task11, UniTask task12, UniTask task13, UniTask task14, UniTask task15) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); this.completedCount = 0; { @@ -5095,7 +5095,7 @@ namespace UniRx.Async public (int, T1 result1, T2 result2, T3 result3, T4 result4, T5 result5, T6 result6, T7 result7, T8 result8, T9 result9, T10 result10, T11 result11, T12 result12, T13 result13, T14 result14, T15 result15) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } diff --git a/Assets/UniRx.Async/UniTask.WhenAny.cs b/Assets/UniRx.Async/UniTask.WhenAny.cs index 3bfe25c..c025f1b 100644 --- a/Assets/UniRx.Async/UniTask.WhenAny.cs +++ b/Assets/UniRx.Async/UniTask.WhenAny.cs @@ -22,7 +22,7 @@ namespace UniRx.Async public static UniTask<(int winArgumentIndex, T result)> WhenAny(IEnumerable> tasks) { - using (var span = ArrayPoolUtil.Materialize(tasks)) + using (var span = ArrayPoolUtil.CopyToRentArray(tasks)) { return new UniTask<(int, T)>(new WhenAnyPromise(span.Array, span.Length), 0); } @@ -37,7 +37,7 @@ namespace UniRx.Async /// Return value is winArgumentIndex public static UniTask WhenAny(IEnumerable tasks) { - using (var span = ArrayPoolUtil.Materialize(tasks)) + using (var span = ArrayPoolUtil.CopyToRentArray(tasks)) { return new UniTask(new WhenAnyPromise(span.Array, span.Length), 0); } @@ -51,7 +51,7 @@ namespace UniRx.Async public WhenAnyLRPromise(UniTask leftTask, UniTask rightTask) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); { UniTask.Awaiter awaiter; @@ -149,7 +149,7 @@ namespace UniRx.Async public (bool, T) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -189,7 +189,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask[] tasks, int tasksLength) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); for (int i = 0; i < tasksLength; i++) { @@ -242,7 +242,7 @@ namespace UniRx.Async public (int, T) GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } @@ -281,7 +281,7 @@ namespace UniRx.Async public WhenAnyPromise(UniTask[] tasks, int tasksLength) { - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); for (int i = 0; i < tasksLength; i++) { @@ -333,7 +333,7 @@ namespace UniRx.Async public int GetResult(short token) { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); GC.SuppressFinalize(this); return core.GetResult(token); } diff --git a/Assets/UniRx.Async/UniTaskCompletionSource.cs b/Assets/UniRx.Async/UniTaskCompletionSource.cs index ccc4f4a..de72a47 100644 --- a/Assets/UniRx.Async/UniTaskCompletionSource.cs +++ b/Assets/UniRx.Async/UniTaskCompletionSource.cs @@ -272,7 +272,7 @@ namespace UniRx.Async public UniTaskCompletionSource() { - TaskTracker2.TrackActiveTask(this, 2); + TaskTracker.TrackActiveTask(this, 2); } [Conditional("UNITY_EDITOR")] @@ -281,7 +281,7 @@ namespace UniRx.Async if (!handled) { handled = true; - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); } } @@ -297,7 +297,7 @@ namespace UniRx.Async { // Reset, re-active tracker handled = false; - TaskTracker2.TrackActiveTask(this, 2); + TaskTracker.TrackActiveTask(this, 2); core.Reset(); } @@ -357,7 +357,7 @@ namespace UniRx.Async public static AutoResetUniTaskCompletionSource Create() { var value = pool.TryRent() ?? new AutoResetUniTaskCompletionSource(); - TaskTracker2.TrackActiveTask(value, 2); + TaskTracker.TrackActiveTask(value, 2); return value; } @@ -412,7 +412,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); core.GetResult(token); } finally @@ -459,7 +459,7 @@ namespace UniRx.Async public UniTaskCompletionSource() { - TaskTracker2.TrackActiveTask(this, 2); + TaskTracker.TrackActiveTask(this, 2); } [Conditional("UNITY_EDITOR")] @@ -468,7 +468,7 @@ namespace UniRx.Async if (!handled) { handled = true; - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); } } @@ -484,7 +484,7 @@ namespace UniRx.Async { handled = false; core.Reset(); - TaskTracker2.TrackActiveTask(this, 2); + TaskTracker.TrackActiveTask(this, 2); } public bool TrySetResult(T result) @@ -548,7 +548,7 @@ namespace UniRx.Async public static AutoResetUniTaskCompletionSource Create() { var result = pool.TryRent() ?? new AutoResetUniTaskCompletionSource(); - TaskTracker2.TrackActiveTask(result, 2); + TaskTracker.TrackActiveTask(result, 2); return result; } @@ -603,7 +603,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); return core.GetResult(token); } finally diff --git a/Assets/UniRx.Async/UnityAsyncExtensions.Jobs.cs b/Assets/UniRx.Async/UnityAsyncExtensions.Jobs.cs index 2e958d6..4c76539 100644 --- a/Assets/UniRx.Async/UnityAsyncExtensions.Jobs.cs +++ b/Assets/UniRx.Async/UnityAsyncExtensions.Jobs.cs @@ -3,136 +3,117 @@ using System; using System.Threading; -using UniRx.Async.Internal; using Unity.Jobs; namespace UniRx.Async { public static partial class UnityAsyncExtensions { - public static IAwaiter GetAwaiter(this JobHandle jobHandle) + public static UniTask.Awaiter GetAwaiter(this JobHandle jobHandle) { - var awaiter = new JobHandleAwaiter(jobHandle, CancellationToken.None); - if (!awaiter.IsCompleted) + var handler = JobHandlePromise.Create(jobHandle, CancellationToken.None, out var token); + if (handler.GetStatus(token).IsCompleted() && handler is JobHandlePromise loopItem) { - PlayerLoopHelper.AddAction(PlayerLoopTiming.EarlyUpdate, awaiter); - PlayerLoopHelper.AddAction(PlayerLoopTiming.PreUpdate, awaiter); - PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, awaiter); - PlayerLoopHelper.AddAction(PlayerLoopTiming.PreLateUpdate, awaiter); - PlayerLoopHelper.AddAction(PlayerLoopTiming.PostLateUpdate, awaiter); + PlayerLoopHelper.AddAction(PlayerLoopTiming.EarlyUpdate, loopItem); + PlayerLoopHelper.AddAction(PlayerLoopTiming.PreUpdate, loopItem); + PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, loopItem); + PlayerLoopHelper.AddAction(PlayerLoopTiming.PreLateUpdate, loopItem); + PlayerLoopHelper.AddAction(PlayerLoopTiming.PostLateUpdate, loopItem); } - return awaiter; + + return new UniTask(handler, token).GetAwaiter(); } public static UniTask ToUniTask(this JobHandle jobHandle, CancellationToken cancellation = default(CancellationToken)) { - var awaiter = new JobHandleAwaiter(jobHandle, cancellation); - if (!awaiter.IsCompleted) + var handler = JobHandlePromise.Create(jobHandle, cancellation, out var token); + if (handler.GetStatus(token).IsCompleted() && handler is JobHandlePromise loopItem) { - PlayerLoopHelper.AddAction(PlayerLoopTiming.EarlyUpdate, awaiter); - PlayerLoopHelper.AddAction(PlayerLoopTiming.PreUpdate, awaiter); - PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, awaiter); - PlayerLoopHelper.AddAction(PlayerLoopTiming.PreLateUpdate, awaiter); - PlayerLoopHelper.AddAction(PlayerLoopTiming.PostLateUpdate, awaiter); + PlayerLoopHelper.AddAction(PlayerLoopTiming.EarlyUpdate, loopItem); + PlayerLoopHelper.AddAction(PlayerLoopTiming.PreUpdate, loopItem); + PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, loopItem); + PlayerLoopHelper.AddAction(PlayerLoopTiming.PreLateUpdate, loopItem); + PlayerLoopHelper.AddAction(PlayerLoopTiming.PostLateUpdate, loopItem); } - return new UniTask(awaiter); + + return new UniTask(handler, token); } public static UniTask ConfigureAwait(this JobHandle jobHandle, PlayerLoopTiming waitTiming, CancellationToken cancellation = default(CancellationToken)) { - var awaiter = new JobHandleAwaiter(jobHandle, cancellation); - if (!awaiter.IsCompleted) + var handler = JobHandlePromise.Create(jobHandle, cancellation, out var token); + if (handler.GetStatus(token).IsCompleted() && handler is JobHandlePromise loopItem) { - PlayerLoopHelper.AddAction(waitTiming, awaiter); + PlayerLoopHelper.AddAction(waitTiming, loopItem); } - return new UniTask(awaiter); + + return new UniTask(handler, token); } - class JobHandleAwaiter : IAwaiter, IPlayerLoopItem + sealed class JobHandlePromise : IUniTaskSource, IPlayerLoopItem { JobHandle jobHandle; CancellationToken cancellationToken; - UniTaskStatus status; - Action continuation; - public JobHandleAwaiter(JobHandle jobHandle, CancellationToken cancellationToken, int skipFrame = 2) + UniTaskCompletionSourceCore core; + + public static IUniTaskSource Create(JobHandle jobHandle, CancellationToken cancellationToken, out short token) { - this.status = cancellationToken.IsCancellationRequested ? UniTaskStatus.Canceled - : jobHandle.IsCompleted ? UniTaskStatus.Succeeded - : UniTaskStatus.Pending; + if (cancellationToken.IsCancellationRequested) + { + return AutoResetUniTaskCompletionSource.CreateFromCanceled(cancellationToken, out token); + } - if (this.status.IsCompleted()) return; + // not use pool. + var result = new JobHandlePromise(); - this.jobHandle = jobHandle; - this.cancellationToken = cancellationToken; - this.status = UniTaskStatus.Pending; - this.continuation = null; + result.jobHandle = jobHandle; + result.cancellationToken = cancellationToken; - TaskTracker.TrackActiveTask(this, skipFrame); + TaskTracker.TrackActiveTask(result, 3); + + token = result.core.Version; + return result; } - public bool IsCompleted => status.IsCompleted(); - - public UniTaskStatus Status => status; - - public void GetResult() + public void GetResult(short token) { - if (status == UniTaskStatus.Succeeded) - { - return; - } - else if (status == UniTaskStatus.Canceled) - { - Error.ThrowOperationCanceledException(); - } + TaskTracker.RemoveTracking(this); + core.GetResult(token); + } - Error.ThrowNotYetCompleted(); + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); } public bool MoveNext() { if (cancellationToken.IsCancellationRequested) { - // Call jobHandle.Complete after finished. - PlayerLoopHelper.AddAction(PlayerLoopTiming.EarlyUpdate, new JobHandleAwaiter(jobHandle, CancellationToken.None, 1)); - InvokeContinuation(UniTaskStatus.Canceled); + core.TrySetCanceled(cancellationToken); return false; } if (jobHandle.IsCompleted) { jobHandle.Complete(); - InvokeContinuation(UniTaskStatus.Succeeded); + core.TrySetResult(AsyncUnit.Default); return false; } return true; } - - void InvokeContinuation(UniTaskStatus status) - { - this.status = status; - var cont = this.continuation; - - // cleanup - TaskTracker.RemoveTracking(this); - this.continuation = null; - this.cancellationToken = CancellationToken.None; - this.jobHandle = default(JobHandle); - - if (cont != null) cont.Invoke(); - } - - public void OnCompleted(Action continuation) - { - UnsafeOnCompleted(continuation); - } - - public void UnsafeOnCompleted(Action continuation) - { - Error.ThrowWhenContinuationIsAlreadyRegistered(this.continuation); - this.continuation = continuation; - } } } } diff --git a/Assets/UniRx.Async/UnityAsyncExtensions.cs b/Assets/UniRx.Async/UnityAsyncExtensions.cs index 385581f..d8d00be 100644 --- a/Assets/UniRx.Async/UnityAsyncExtensions.cs +++ b/Assets/UniRx.Async/UnityAsyncExtensions.cs @@ -104,7 +104,7 @@ namespace UniRx.Async result.progress = progress; result.cancellationToken = cancellationToken; - TaskTracker2.TrackActiveTask(result, 3); + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -116,7 +116,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); core.GetResult(token); } @@ -277,7 +277,7 @@ namespace UniRx.Async result.progress = progress; result.cancellationToken = cancellationToken; - TaskTracker2.TrackActiveTask(result, 3); + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -289,7 +289,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); return core.GetResult(token); } @@ -454,7 +454,7 @@ namespace UniRx.Async result.progress = progress; result.cancellationToken = cancellationToken; - TaskTracker2.TrackActiveTask(result, 3); + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -466,7 +466,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); return core.GetResult(token); } @@ -631,7 +631,7 @@ namespace UniRx.Async result.progress = progress; result.cancellationToken = cancellationToken; - TaskTracker2.TrackActiveTask(result, 3); + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -643,7 +643,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); return core.GetResult(token); } @@ -809,7 +809,7 @@ namespace UniRx.Async result.progress = progress; result.cancellationToken = cancellationToken; - TaskTracker2.TrackActiveTask(result, 3); + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -821,7 +821,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); return core.GetResult(token); } diff --git a/Assets/UniRx.Async/UnityAsyncExtensions.tt b/Assets/UniRx.Async/UnityAsyncExtensions.tt index e4d6e27..1b2b8ac 100644 --- a/Assets/UniRx.Async/UnityAsyncExtensions.tt +++ b/Assets/UniRx.Async/UnityAsyncExtensions.tt @@ -137,7 +137,7 @@ namespace UniRx.Async result.progress = progress; result.cancellationToken = cancellationToken; - TaskTracker2.TrackActiveTask(result, 3); + TaskTracker.TrackActiveTask(result, 3); PlayerLoopHelper.AddAction(timing, result); @@ -149,7 +149,7 @@ namespace UniRx.Async { try { - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); <# if (!IsVoid(t)) { #> return core.GetResult(token); diff --git a/Assets/UniRx.Async/UnityAsyncExtensions.uGUI.cs b/Assets/UniRx.Async/UnityAsyncExtensions.uGUI.cs index 09658f7..24a119c 100644 --- a/Assets/UniRx.Async/UnityAsyncExtensions.uGUI.cs +++ b/Assets/UniRx.Async/UnityAsyncExtensions.uGUI.cs @@ -211,7 +211,7 @@ namespace UniRx.Async registration = cancellationToken.RegisterWithoutCaptureExecutionContext(cancellationCallback, this); } - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); } public UniTask OnInvokeAsync() @@ -238,7 +238,7 @@ namespace UniRx.Async if (!isDisposed) { isDisposed = true; - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); registration.Dispose(); if (unityEvent != null) { @@ -317,7 +317,7 @@ namespace UniRx.Async registration = cancellationToken.RegisterWithoutCaptureExecutionContext(cancellationCallback, this); } - TaskTracker2.TrackActiveTask(this, 3); + TaskTracker.TrackActiveTask(this, 3); } public UniTask OnInvokeAsync() @@ -344,7 +344,7 @@ namespace UniRx.Async if (!isDisposed) { isDisposed = true; - TaskTracker2.RemoveTracking(this); + TaskTracker.RemoveTracking(this); registration.Dispose(); if (unityEvent != null) {