Ejemplo n.º 1
0
    IEnumerator Start()
    {
        // 入力を受け付けるコントローラー情報をまとめて取得
        var joysticks = _joysticks.Select(i => JoystickManager.GetJoystick(i));

        // 最初のボタンのサイズを大きくしておく
        buttonIndex = 0;
        ChangeButtonState(buttonIndex, _buttonScale, _selected);

        // 直前フレームの入力を記憶
        int previousInput = 0;

        while (isActiveAndEnabled)
        {
            yield return(null);

            // 決定ボタンの状態を取得
            isPushApplyButton = IsPushApplyButton(joysticks);

            // 待機状態ならコントローラー入力を受け付けない
            if (isStop)
            {
                continue;
            }

            // 決定ボタンが押されたとき、イベント登録されたボタンなら実行
            if (isPushApplyButton && ExistCallBackEvents())
            {
                _buttons[buttonIndex].onClick.Invoke();
            }

            // いずれかのコントローラーからの入力を受け付けたら実行
            var currentInput = GetAxisToInt(joysticks);
            if (currentInput != 0 && previousInput == 0)
            {
                // 移動前のインデックスにあるボタンの状態を戻す
                ChangeButtonState(buttonIndex, 1f, _normal);

                // インデックスを移動、ボタンの状態を更新する
                buttonIndex = MoveIndex(currentInput);
                ChangeButtonState(buttonIndex, _buttonScale, _selected);
            }

            previousInput = currentInput;
        }
    }
Ejemplo n.º 2
0
    IEnumerator Start()
    {
        var joystick = JoystickManager.GetJoystick(_joystickIndex);
        var audio    = GetComponent <AudioClipPlayer>();

        isApply  = false;
        isCancel = false;

        // UI を初期化する
        var state = _joystickIndex.GetState();

        _ui.ChangePlayerState(state.isPlayer);
        _ui.SwitchState(isApply);

        while (isActiveAndEnabled)
        {
            yield return(null);

            if (isStop)
            {
                continue;
            }

            // キャンセルボタンの判定を取得
            isCancel = joystick.IsPush(Joystick.AxisType.Cancel);

            // 決定ボタンが押されていれば、状態切り替えをスキップ
            if (isApply)
            {
                // キャンセルボタンが押されたら、切り替え判定を再開
                if (isCancel)
                {
                    isApply  = false;
                    isCancel = false;
                    audio.Play(_seCancel);
                    _ui.SwitchState(isApply);
                }
                continue;
            }

            // 決定ボタンが押されていない状態でキャンセルボタンが押されたらスキップ
            if (isCancel)
            {
                audio.Play(_seCancel); continue;
            }

            // 決定ボタン
            if (joystick.IsPush(Joystick.AxisType.Attack))
            {
                isApply = true;
                audio.Play(_seApply);
                _ui.SwitchState(isApply);
                continue;
            }

            // X ボタンが押されたらプレイヤーの状態を切り替える
            if (joystick.IsPush(Joystick.AxisType.Super))
            {
                state.isPlayer = !state.isPlayer;
                _ui.ChangePlayerState(state.isPlayer);

                audio.Play(_seSelect);
            }
        }
    }