Exemplo n.º 1
0
        private void Start()
        {
            _moveUseCase
            .WhereMoveCount(0)
            .Subscribe(_ => SetInteractableMementoButton(false))
            .AddTo(this);

            _moveUseCase
            .WhereMoveCount(1)
            .Subscribe(_ => SetInteractableMementoButton(true))
            .AddTo(this);

            var token = this.GetCancellationTokenOnDestroy();

            _goal.Initialize(() =>
            {
                undoButton.HideAsync(token).Forget();
                resetButton.HideAsync(token).Forget();
                homeButton.HideAsync(token).Forget();
                foreach (var moveButton in moveButtons)
                {
                    moveButton.HideAsync(token).Forget();
                }
            });

            // 全移動ボタン
            isStop = true;
            foreach (var moveButton in moveButtons)
            {
                moveButton.onPush
                .Where(_ => _moveUseCase.IsMove())
                .Subscribe(moveDirection =>
                {
                    isStop = false;
                    _moveUseCase.CountUp();
                    _playerMover.Move(moveDirection);
                    SetEnableButton(false);
                })
                .AddTo(moveButton);
            }

            // 一手戻るボタン
            undoButton.onPush
            .Where(_ => _moveUseCase.IsMove())
            .Subscribe(_ => _moveUseCase.CountDown())
            .AddTo(undoButton);

            // 移動リセットボタン
            resetButton.onPush
            .Where(_ => _moveUseCase.IsMove())
            .Subscribe(_ => _moveUseCase.ResetCount())
            .AddTo(resetButton);

            this.OnCollisionEnter2DAsObservable()
            .Select(other => other.gameObject.GetComponent <IHittable>())
            .Where(hittable => hittable != null)
            .Subscribe(hittable =>
            {
                _playerMover.HitBlock(hittable);
                var roundPosition = transform.RoundPosition();
                _goal.SetPlayerPosition(roundPosition, _moveUseCase.currentCount);
                CorrectPosition(roundPosition);
            })
            .AddTo(this);
        }