Exemple #1
0
        /// <summary>
        /// 入力更新
        /// GameManagerがFixedUpdate()内でこのメソッドをStartCoroutine()で呼び出す
        /// </summary>
        public static IEnumerator LateFixedUpdate()
        {
            yield return new WaitForFixedUpdate();
            // 同時押し判定後のタイミングでリセット
            if (jumpTrampledInputCount >= jumpTrampledInputSeconds)
            {
                buttonState[ButtonName.Attack] = false;
                buttonState[ButtonName.Jump] = false;
                jumpTrampledInputCount = 0.0f;
                jumpTrampledInput = JumpTrampledInput.None;
                buttonState[ButtonName.JumpTrampled] = false;
            }

            // Attackと Jumpについては同時押しに使用するためfalseに戻すタイミングを遅延させる
            //buttonState[ButtonName.Attack] = false;
            buttonState[ButtonName.Barrier] = false;
            buttonState[ButtonName.ItemGet] = false;
            //buttonState[ButtonName.Jump] = false;
            buttonState[ButtonName.LockOn] = false;
            buttonState[ButtonName.CameraToFront] = false;
            if (lockOnChangedInputFrameCount >= 1)
            {
                buttonState[ButtonName.RightLockOnChanged] = false;
                buttonState[ButtonName.LeftLockOnChanged] = false;
            }
        }
Exemple #2
0
        /// <summary>
        /// プレイヤー入力情報更新
        /// GameManagerが毎フレーム呼ぶこと
        /// </summary>
        public static void Update(float elapsedTime)
        {
            // プレイヤーの移動入力
            horizontal = Input.GetAxisRaw(InputName.Horizontal);
            vertical = Input.GetAxisRaw(InputName.Vertical);

            // カメラ回転入力(-1 ~ 1)
            cameraHorizontal = Input.GetAxisRaw(InputName.CameraX);
            cameraVertical = Input.GetAxisRaw(InputName.CameraY);

            // 微小な値を無視
            if (Mathf.Abs(cameraHorizontal) < 0.2f)
                cameraHorizontal = 0.0f;
            if (Mathf.Abs(cameraVertical) < 0.2f)
                cameraVertical = 0.0f;

            // 画面クリック時のカメラ回転
            if (Input.GetMouseButton(1))
            {
                Vector3 rotationInput = Camera.main.ScreenToViewportPoint(Input.mousePosition);
                // 中央を(0, 0)にする
                rotationInput.x -= 0.5f;
                rotationInput.y -= 0.5f;
                rotationInput *= 2.0f;
                if (Mathf.Abs(rotationInput.y) < 0.5f)
                {
                    rotationInput.y = 0.0f;
                }

                cameraHorizontal = rotationInput.x;
                cameraVertical = rotationInput.y;
            }

            // コントローラでは同時押しだがキーボードでは辛いのでキーボード用の設定
            buttonState[ButtonName.JumpTrampled] = Input.GetButtonDown(InputName.JumpAndAttack) ? true : buttonState[ButtonName.JumpTrampled];

            buttonState[ButtonName.CameraToFront] = Input.GetButtonDown(InputName.CameraToFront) ? true : buttonState[ButtonName.CameraToFront];
            buttonState[ButtonName.ItemGet] = Input.GetButtonDown(InputName.ItemGet) ? true : buttonState[ButtonName.ItemGet];
            buttonState[ButtonName.Barrier] = Input.GetButtonDown(InputName.Barrier) ? true : buttonState[ButtonName.Barrier];

            if (Input.GetAxis(InputName.RightStickHorizontal) < -lockOnChangeThreshold)
            {
                if (!buttonState[ButtonName.LeftLockOnChanged] &&
                    lockOnChangedInputFrameCount == 0)
                {
                    buttonState[ButtonName.LeftLockOnChanged] = true;
                }
                ++lockOnChangedInputFrameCount;
            }
            else if (Input.GetAxis(InputName.RightStickHorizontal) > lockOnChangeThreshold)
            {
                if (!buttonState[ButtonName.RightLockOnChanged] &&
                    lockOnChangedInputFrameCount == 0)
                {
                    buttonState[ButtonName.RightLockOnChanged] = true;
                }
                ++lockOnChangedInputFrameCount;
            }
            else
            {
                lockOnChangedInputFrameCount = 0;
            }

            buttonState[ButtonName.Jump] = Input.GetButtonDown(InputName.Jump) ? true : buttonState[ButtonName.Jump];
            buttonState[ButtonName.Attack] = Input.GetButtonDown(InputName.Attack) ? true : buttonState[ButtonName.Attack];
            if (buttonState[ButtonName.Jump])
            {
                jumpTrampledInput |= JumpTrampledInput.Jump;
            }

            if (buttonState[ButtonName.Attack])
            {
                jumpTrampledInput |= JumpTrampledInput.Attack;
            }
            Debug.Log(jumpTrampledInput);
            // 時間内に同時押しが成立
            if (jumpTrampledInput == JumpTrampledInput.All &&
                jumpTrampledInputCount <= jumpTrampledInputSeconds)
            {
                // 同時押し判定が複数回発生しないように入力フレームをカウント
                ++jumpTrampledInputFrame;
            }
            else
            {
                jumpTrampledInputFrame = 0;
            }

            if (jumpTrampledInput != JumpTrampledInput.None)
            {
                // 何らかのボタンが押されていたので同時押し判定用のカウンタを増加させる
                jumpTrampledInputCount += elapsedTime;
            }
            else
            {
                jumpTrampledInputCount = 0.0f;
            }

            // 同時押しの瞬間にtrue
            if (jumpTrampledInputFrame == 1)
            {
                jumpTrampled = true;
                buttonState[ButtonName.JumpTrampled] = true;
            }
            else
            {
                jumpTrampled = false;
            }

            buttonState[ButtonName.LockOn] = Input.GetButtonDown(InputName.LockOn) ? true : buttonState[ButtonName.LockOn];
        }
Exemple #3
0
    /// <summary>
    /// プレイヤー入力情報更新
    /// GameManagerが毎フレーム呼ぶこと
    /// </summary>
    public void Update(float elapsedTime)
    {
        // プレイヤーの移動入力
        horizontal = Input.GetAxisRaw(InputName.Horizontal);
        vertical = Input.GetAxisRaw(InputName.Vertical);

        // カメラ回転入力(-1 ~ 1)
        cameraHorizontal = Input.GetAxisRaw(InputName.CameraX);
        cameraVertical = Input.GetAxisRaw(InputName.CameraY);

        // 微小な値を無視
        if (Mathf.Abs(cameraHorizontal) < 0.2f)
            cameraHorizontal = 0.0f;
        if (Mathf.Abs(cameraVertical) < 0.2f)
            cameraVertical = 0.0f;

        // 画面クリック時のカメラ回転
        if (Input.GetMouseButton(1))
        {
            Vector3 rotationInput = Camera.main.ScreenToViewportPoint(Input.mousePosition);
            // 中央を(0, 0)にする
            rotationInput.x -= 0.5f;
            rotationInput.y -= 0.5f;
            rotationInput *= 2.0f;
            if (Mathf.Abs(rotationInput.y) < 0.5f)
            {
                rotationInput.y = 0.0f;
            }

            cameraHorizontal = rotationInput.x;
            cameraVertical = rotationInput.y;
        }

        cameraToFront = Input.GetButtonDown(InputName.CameraToFront) ? true : cameraToFront;
        itemGet = Input.GetButtonDown(InputName.ItemGet) ? true : itemGet;
        barrier = Input.GetButtonDown(InputName.Barrier) ? true : barrier;

        jump = Input.GetButtonDown(InputName.Jump) ? true : jump;
        attack = Input.GetButtonDown(InputName.Attack) ? true : attack;
        if (Input.GetButton(InputName.Jump))
        {
            jumpTrampledInput |= JumpTrampledInput.Jump;
        }

        if (Input.GetButton(InputName.Attack))
        {
            jumpTrampledInput |= JumpTrampledInput.Attack;
        }

        if (jumpTrampledInput == JumpTrampledInput.None)
        {
            jumpTrampledInputCount = 0.0f;
        }
        else
        {
            // 何らかのボタンが押されていたので同時押し判定用のカウンタを増加させる
            jumpTrampledInputCount += Time.deltaTime;
        }

        // 時間内に同時押しが成立
        if (jumpTrampledInput == JumpTrampledInput.All &&
            jumpTrampledInputCount < jumpTrampledInputSeconds)
        {
            jumpTrampled = true;
            // 同時押し判定が複数回発生しないようにカウンタを猶予時間外に設定
            jumpTrampledInputCount = jumpTrampledInputSeconds;
        }

        // 同時入力猶予時間を超えた
        if (jumpTrampledInputCount >= jumpTrampledInputSeconds)
        {
            jumpTrampled = false;
        }

        lockOn = Input.GetButtonDown(InputName.LockOn) ? true : lockOn;

        if (updateCount > 2)
        {
            //Debug.Log("入力情報が正しく検知できません。入力更新メソッドを適切に呼び出してください");
        }
        ++updateCount;
    }