diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs index 2f6a6a9..bd66aba 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs @@ -81,6 +81,16 @@ namespace Cysharp.Threading.Tasks return factory(); } + public static UniTask Create(Func factory, CancellationToken cancellationToken) + { + return factory(cancellationToken); + } + + public static UniTask Create(T state, Func factory) + { + return factory(state); + } + public static UniTask Create(Func> factory) { return factory(); @@ -137,11 +147,19 @@ namespace Cysharp.Threading.Tasks return () => asyncAction(cancellationToken).Forget(); } + /// + /// helper of create add UniTaskVoid to delegate. + /// + public static Action Action(T state, Func asyncAction) + { + return () => asyncAction(state).Forget(); + } + #if UNITY_2018_3_OR_NEWER /// /// Create async void(UniTaskVoid) UnityAction. - /// For exampe: onClick.AddListener(UniTask.UnityAction(async () => { /* */ } )) + /// For example: onClick.AddListener(UniTask.UnityAction(async () => { /* */ } )) /// public static UnityEngine.Events.UnityAction UnityAction(Func asyncAction) { @@ -150,13 +168,22 @@ namespace Cysharp.Threading.Tasks /// /// Create async void(UniTaskVoid) UnityAction. - /// For exampe: onClick.AddListener(UniTask.UnityAction(FooAsync, this.GetCancellationTokenOnDestroy())) + /// For example: onClick.AddListener(UniTask.UnityAction(FooAsync, this.GetCancellationTokenOnDestroy())) /// public static UnityEngine.Events.UnityAction UnityAction(Func asyncAction, CancellationToken cancellationToken) { return () => asyncAction(cancellationToken).Forget(); } + /// + /// Create async void(UniTaskVoid) UnityAction. + /// For example: onClick.AddListener(UniTask.UnityAction(FooAsync, Argument)) + /// + public static UnityEngine.Events.UnityAction UnityAction(T state, Func asyncAction) + { + return () => asyncAction(state).Forget(); + } + #endif ///