コード例 #1
0
        // for uGUI(from 4.6)
#if !(UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5)
        /// <summary>
        /// Bind AsyncRaectiveCommand to button's interactable and onClick.
        /// </summary>
        public static IDisposable BindTo(this IAsyncReactiveCommand <Unit> command, UnityEngine.UI.Button button)
        {
            var d1 = command.CanExecute.SubscribeToInteractable(button);
            var d2 = button.OnClickAsObservable().SubscribeWithState(command, (x, c) => c.Execute(x));

            return(StableCompositeDisposable.Create(d1, d2));
        }
コード例 #2
0
        public static Task <T> WaitUntilExecuteAsync <T>(this IAsyncReactiveCommand <T> source, CancellationToken cancellationToken = default(CancellationToken))
        {
            var tcs = new CancellableTaskCompletionSource <T>();

            var subscription = source.Subscribe(x => { tcs.TrySetResult(x); return(Observable.ReturnUnit()); });

            cancellationToken.Register(Callback, Tuple.Create(tcs, subscription), false);

            return(tcs.Task);
        }
    private async UniTaskVoid WaitCommandAsync(IAsyncReactiveCommand <string> command)
    {
        // Execute() が実行されたときのパラメータを待ち受ける
        var value = await command;

        // "Work!" が表示される
        Debug.Log(value);

        // ↑はこれと同義
        // command.Take(1).Subscribe(x => Debug.Log(x));
    }
コード例 #4
0
 public static System.Runtime.CompilerServices.TaskAwaiter <T> GetAwaiter <T>(this IAsyncReactiveCommand <T> command)
 {
     return(command.WaitUntilExecuteAsync(CancellationToken.None).GetAwaiter());
 }
コード例 #5
0
 public static UniTask <T> .Awaiter GetAwaiter <T>(this IAsyncReactiveCommand <T> command)
 {
     return(command.WaitUntilExecuteAsync().GetAwaiter());
 }
コード例 #6
0
 public static UniTask<T>.Awaiter GetAwaiter<T>(this IAsyncReactiveCommand<T> command)
 {
     return command.WaitUntilExecuteAsync(CancellationToken.None).GetAwaiter();
 }