Example #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 AsyncReactiveCommand <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));
        }
Example #2
0
        public void Awake()
        {
            MainThreadDispatcher.Initialize();

            //LogHelper.LogCallbackAsObservable()
            //    .ObserveOnMainThread()
            //    .Where(x => x.LogType == LogType.Exception)
            //    .Subscribe(x => logtext.AppendLine(x.ToString()));

            //ObservableLogger.Listener.LogToUnityDebug();
            //ObservableLogger.Listener.ObserveOnMainThread().Subscribe(x =>
            //{
            //    logtext.AppendLine(x.Message);
            //});

#if UNITY_5_3
            button.OnClickAsObservable().Subscribe(_ =>
            {
                UnityEngine.Debug.Log("---");
                Observable.EveryGameObjectUpdate().Subscribe(x => Debug.Log("EveryGameObjectUpdate" + x));
                Observable.EveryUpdate().Subscribe(x => Debug.Log("EveryUpdate:" + x));
                Observable.EveryAfterUpdate().Subscribe(x => Debug.Log("EveryAfterUpdate:" + x));
                Observable.EveryLateUpdate().Subscribe(x => Debug.Log("EveryLateUpdate:" + x));
                Observable.EveryEndOfFrame().Subscribe(x => Debug.Log("EveryEndOfFrame:" + x));
                UnityEngine.Debug.Log("---");
            });
#endif
        }
Example #3
0
 public static IObservable <Unit> OnClickAsOptional(this UnityEngine.UI.Button btn)
 {
     return(btn
            .OnClickAsObservable()
            .ThrottleFirst(TimeSpan.FromSeconds(Config.ignore_btn_continuity))
            .First());
 }
Example #4
0
        /// <summary>
        /// Bind AsyncRaectiveCommand to button's interactable and onClick and register async action to command.
        /// </summary>
        public static IDisposable BindToOnClick(this AsyncReactiveCommand <Unit> command, UnityEngine.UI.Button button, Func <Unit, IObservable <Unit> > asyncOnClick)
        {
            IDisposable d1 = command.CanExecute.SubscribeToInteractable(button);
            IDisposable d2 = button.OnClickAsObservable().SubscribeWithState(command, (x, c) => c.Execute(x));
            IDisposable d3 = command.Subscribe(asyncOnClick);

            return(StableCompositeDisposable.Create(d1, d2, d3));
        }
Example #5
0
        /// <summary>
        /// Bind ReactiveCommand to button's interactable and onClick and register onClick action to command.
        /// </summary>
        public static IDisposable BindToOnClick(this IReactiveCommand<Unit> command, UnityEngine.UI.Button button, Action<Unit> onClick)
        {
            var d1 = command.CanExecute.SubscribeToInteractable(button);
            var d2 = button.OnClickAsObservable().SubscribeWithState(command, (x, c) => c.Execute(x));
            var d3 = command.Subscribe(onClick);

            return StableCompositeDisposable.Create(d1, d2, d3);
        }
Example #6
0
        public override void Init(Room _model)
        {
            base.Init(_model);

            _img.InitUrl(AppContext.Get <Data>().Settings.First(p => p.Name == Constants.PlayerIcon).Value);
            _players.text  = Model.Players.ToString();
            _roomName.text = Model.Name;

            _joinRoom.OnClickAsObservable().Subscribe(p =>
            {
                AppContext.Get <GameState>().SelectedRoom = _model.Name;
                AppContext.Get <ShowPopupSignal>().Dispatch(Popups.JoinRoomPopup);
            });

            SetRoomState(_model.Players == _model.MaxPlayers ? RoomViewState.Full : RoomViewState.Join);
        }
 public static IDisposable BindValueToButtonOnClick <T>(this IReactiveProperty <T> toUpdateSource, UnityEngine.UI.Button fromButton, Func <T> onClickValue)
 {
     return(GenericBindings.Bind(fromButton.OnClickAsObservable(), _ => toUpdateSource.Value = onClickValue()).AddTo(fromButton));
 }