Пример #1
0
	public void Turn(){
		float rotationDir = joystick.GetAxis();
		if (rotationDir == 0) {
			return; // 조이스틱 입력값이 없을 때 현재 방향 바라보도록 설정
		}
		_transform.rotation = Quaternion.Euler (0f, 0f, rotationDir);
	}
Пример #2
0
        private void OnTimerCallback2(object state)
        {
            JoystickAPI.JOYINFOEX infoEx_PR = new JoystickAPI.JOYINFOEX();
            JoystickAPI.JOYINFOEX infoEx_Y  = new JoystickAPI.JOYINFOEX();
            JoystickAPI.JOYINFOEX infoEx_T  = new JoystickAPI.JOYINFOEX();
            Axis axis_now = PreviousAxis2;

            if (joystick_PR2.getinfo(ref infoEx_PR) == JoystickAPI.JOYERR_NOERROR)
            {
                JoystickButtons buttons = joystick_PR2.GetButtons(infoEx_PR.dwButtons);
                JoystickAxis    axis    = joystick_PR2.GetAxis(ref infoEx_PR);

                if (PreviousButtons2 != buttons)
                {
                    //按钮状态有更改,则发出ButtonUp事件

                    //取得前一次按下的按钮与本次按下的按钮的差(即不再处于按下状态的按钮)
                    JoystickButtons b = (JoystickButtons)(PreviousButtons2 - (PreviousButtons2 & buttons));
                    JoystickButtons n = (JoystickButtons)(buttons - (PreviousButtons2 & buttons));//新按下的按钮;
                    if (b != JoystickButtons.None)
                    {
                        this.Dispatcher.Invoke(new ButtonsUpCallBack(buttonUp2), b);
                    }
                    if (n != JoystickButtons.None)
                    {
                        this.Dispatcher.Invoke(new ButtonsDownCallBack(buttonDown2), n);
                    }
                    PreviousButtons2 = buttons;
                }
                axis_now.Pitch = Convert.ToDouble(axis.Ypos - joystick_PR2.JoystickCAPS.wYmin) * 100 / (joystick_PR2.JoystickCAPS.wYmax - joystick_PR2.JoystickCAPS.wYmin);
                axis_now.Roll  = Convert.ToDouble(axis.Xpos - joystick_PR2.JoystickCAPS.wXmin) * 100 / (joystick_PR2.JoystickCAPS.wXmax - joystick_PR2.JoystickCAPS.wXmin);
            }
            if (joystick_Y2.getinfo(ref infoEx_Y) == JoystickAPI.JOYERR_NOERROR)
            {
                JoystickAxis axis = joystick_Y2.GetAxis(ref infoEx_Y);
                axis_now.Yaw = Convert.ToDouble(axis.Zpos - joystick_Y2.JoystickCAPS.wRmin) * 100 / (joystick_Y2.JoystickCAPS.wRmax - joystick_Y2.JoystickCAPS.wRmin);
            }
            if (joystick_T2.getinfo(ref infoEx_T) == JoystickAPI.JOYERR_NOERROR)
            {
                JoystickAxis axis = joystick_T2.GetAxis(ref infoEx_T);
                //axis_now.Throttle = 100 - Convert.ToDouble(axis.Rpos - joystick_T.JoystickCAPS.wRmin) * 100 / (joystick_T.JoystickCAPS.wRmax - joystick_T.JoystickCAPS.wRmin);
                axis_now.Throttle = 100 - Convert.ToDouble(axis.Zpos - joystick_T2.JoystickCAPS.wZmin) * 100 / (joystick_T2.JoystickCAPS.wZmax - joystick_T2.JoystickCAPS.wZmin);
            }
            if (axis_now.Equals(PreviousAxis2))
            {
            }
            else
            {
                this.Dispatcher.Invoke(new AxisChangeCallBack(axisChange2), axis_now);
                PreviousAxis2 = axis_now;
            }
        }
Пример #3
0
        /// <summary>
        ///   Gets the current value of the given axis on the given device.
        /// </summary>
        /// <param name="dev">
        ///   The input device.
        /// </param>
        /// <param name="axis">
        ///   The axis to check.
        /// </param>
        /// <returns>
        ///   The current value of the given axis on the given device if it is valid, otherwise 0.0f.
        /// </returns>
        public float GetAxis(InputDevice dev, string axis)
        {
            if (dev is InputDevice.Mouse)
            {
                return(Mouse.GetAxis(axis));
            }
            else if (dev is InputDevice.Joystick)
            {
                return(Joystick.GetAxis(axis));
            }

            return(0.0f);
        }
Пример #4
0
        private void RedrawValueMarkers()
        {
            if (!axisSelected)
            {
                calibratedValueMarker.anchoredPosition = new Vector2(0, calibratedValueMarker.anchoredPosition.y);
                rawValueMarker.anchoredPosition        = new Vector2(0, rawValueMarker.anchoredPosition.y);
                return;
            }

            float value    = joystick.GetAxis(selectedAxis);
            float rawValue = Mathf.Clamp(joystick.GetAxisRaw(selectedAxis), -1.0f, 1.0f);

            calibratedValueMarker.anchoredPosition = new Vector2(displayAreaWidth * 0.5f * value, calibratedValueMarker.anchoredPosition.y);
            rawValueMarker.anchoredPosition        = new Vector2(displayAreaWidth * 0.5f * rawValue, rawValueMarker.anchoredPosition.y);
        }
Пример #5
0
    void Update()
    {
        if (!gameManager.gamePaused)
        {
            for (int touchIndex = 0; touchIndex < Input.touchCount; ++touchIndex)
            {
                Touch currentTouch = Input.GetTouch(touchIndex);

                //ignores touch if it's position is over a ui element
                bool touchPositionOnUIElement = false;
                foreach (Vector3[] corners in cornersOfUIElements)
                {
                    if (currentTouch.position.x > corners[0].x &&
                        currentTouch.position.x <corners[3].x &&
                                                 currentTouch.position.y> corners[0].y &&
                        currentTouch.position.y < corners[1].y)
                    {
                        touchPositionOnUIElement = true;
                    }
                }

                bool touchPositionInDeadZone = currentTouch.position.x < deadZone.x && currentTouch.position.y < deadZone.y;

                if (currentTouch.phase == TouchPhase.Moved && !touchPositionOnUIElement && !touchPositionInDeadZone && joystick.GetAxis("Vertical") == 0 && joystick.GetAxis("Horizontal") == 0)
                {
                    float dX = currentTouch.deltaPosition.x / mainCamera.pixelWidth * 360;
                    transform.Rotate(Vector3.up * dX);
                    mainCamera.transform.RotateAround(transform.position, Vector3.up, dX);
                }
            }
        }
    }
        // 以下、メイン処理.リジッドボディと絡めるので、FixedUpdate内で処理を行う.
        void FixedUpdate()
        {
            float h = (Input.GetAxis("Horizontal") > 0 ? Input.GetAxis("Horizontal") : -Input.GetAxis("Horizontal")) > (joystick.GetAxis("Horizontal") > 0 ? joystick.GetAxis("Horizontal") : -joystick.GetAxis("Horizontal")) ? Input.GetAxis("Horizontal") : joystick.GetAxis("Horizontal"); // 入力デバイスの水平軸をhで定義
            float v = (Input.GetAxis("Vertical") > 0 ? Input.GetAxis("Vertical") : -Input.GetAxis("Vertical")) > (joystick.GetAxis("Vertical") > 0 ? joystick.GetAxis("Vertical") : -joystick.GetAxis("Vertical")) ? Input.GetAxis("Vertical") : joystick.GetAxis("Vertical");                 // 入力デバイスの垂直軸をvで定義

            anim.SetFloat("Speed", v);                                                                                                                                                                                                                                                         // Animator側で設定している"Speed"パラメタにvを渡す
            anim.SetFloat("Direction", h);                                                                                                                                                                                                                                                     // Animator側で設定している"Direction"パラメタにhを渡す
            anim.speed       = animSpeed;                                                                                                                                                                                                                                                      // Animatorのモーション再生速度に animSpeedを設定する
            currentBaseState = anim.GetCurrentAnimatorStateInfo(0);                                                                                                                                                                                                                            // 参照用のステート変数にBase Layer (0)の現在のステートを設定する
            rb.useGravity    = true;                                                                                                                                                                                                                                                           //ジャンプ中に重力を切るので、それ以外は重力の影響を受けるようにする



            // 以下、キャラクターの移動処理
            velocity = Vector3.forward * v;        // 上下のキー入力からZ軸方向の移動量を取得
                                                   // キャラクターのローカル空間での方向に変換
            velocity = transform.TransformDirection(velocity);
            //以下のvの閾値は、Mecanim側のトランジションと一緒に調整する
            if (v > 0.1)
            {
                velocity *= forwardSpeed;       // 移動速度を掛ける
            }
            else if (v < -0.1)
            {
                velocity *= backwardSpeed;  // 移動速度を掛ける
            }

            if (transform.parent.parent != null && (Input.GetButtonDown("Jump") || jumpButton.GetButtonDown()))    // スペースキーを入力したら

            //アニメーションのステートがLocomotionの最中のみジャンプできる
            {
                if (currentBaseState.fullPathHash == locoState)
                {
                    //ステート遷移中でなかったらジャンプできる
                    if (!anim.IsInTransition(0))
                    {
                        rb.velocity = Vector3.zero;
                        rb.AddForce(Vector3.up * jumpPower, ForceMode.VelocityChange);
                        anim.SetBool("Jump", true);     // Animatorにジャンプに切り替えるフラグを送る
                    }
                }
            }


            // 上下のキー入力でキャラクターを移動させる
            transform.localPosition += velocity * Time.fixedDeltaTime;

            // 左右のキー入力でキャラクタをY軸で旋回させる
            transform.Rotate(0, h * rotateSpeed, 0);


            // 以下、Animatorの各ステート中での処理
            // Locomotion中
            // 現在のベースレイヤーがlocoStateの時
            if (currentBaseState.fullPathHash == locoState)
            {
                //カーブでコライダ調整をしている時は、念のためにリセットする
                if (useCurves)
                {
                    resetCollider();
                }
            }
            // JUMP中の処理
            // 現在のベースレイヤーがjumpStateの時
            else if (currentBaseState.fullPathHash == jumpState)
            {
                cameraObject.SendMessage("setCameraPositionJumpView");  // ジャンプ中のカメラに変更
                                                                        // ステートがトランジション中でない場合
                if (!anim.IsInTransition(0))
                {
                    // 以下、カーブ調整をする場合の処理
                    if (useCurves)
                    {
                        // 以下JUMP00アニメーションについているカーブJumpHeightとGravityControl
                        // JumpHeight:JUMP00でのジャンプの高さ(0〜1)
                        // GravityControl:1⇒ジャンプ中(重力無効)、0⇒重力有効
                        float jumpHeight     = anim.GetFloat("JumpHeight");
                        float gravityControl = anim.GetFloat("GravityControl");
                        if (gravityControl > 0)
                        {
                            rb.useGravity = false;  //ジャンプ中の重力の影響を切る
                        }
                        // レイキャストをキャラクターのセンターから落とす
                        Ray        ray     = new Ray(transform.position + Vector3.up, -Vector3.up);
                        RaycastHit hitInfo = new RaycastHit();
                        // 高さが useCurvesHeight 以上ある時のみ、コライダーの高さと中心をJUMP00アニメーションについているカーブで調整する
                        if (Physics.Raycast(ray, out hitInfo))
                        {
                            if (hitInfo.distance > useCurvesHeight)
                            {
                                col.height = orgColHight - jumpHeight;      // 調整されたコライダーの高さ
                                float adjCenterY = orgVectColCenter.y + jumpHeight;
                                col.center = new Vector3(0, adjCenterY, 0); // 調整されたコライダーのセンター
                            }
                            else
                            {
                                // 閾値よりも低い時には初期値に戻す(念のため)
                                resetCollider();
                            }
                        }
                    }
                    // Jump bool値をリセットする(ループしないようにする)
                    anim.SetBool("Jump", false);
                }
            }
            // IDLE中の処理
            // 現在のベースレイヤーがidleStateの時
            else if (currentBaseState.fullPathHash == idleState)
            {
                //カーブでコライダ調整をしている時は、念のためにリセットする

                if (transform.parent.parent != null && (Input.GetButtonDown("Jump") || jumpButton.GetButtonDown()))
                {
                    if (!anim.IsInTransition(0))
                    {
                        rb.velocity = Vector3.zero;
                        rb.AddForce(Vector3.up * jumpPower, ForceMode.VelocityChange);
                        anim.SetBool("Rest", true);     // Animatorにジャンプに切り替えるフラグを送る
                    }
                }

                if (useCurves)
                {
                    resetCollider();
                }

                /*// スペースキーを入力したらRest状態になる
                 * if (Input.GetButtonDown("Jump")) {
                 *  anim.SetBool("Rest", true);
                 * }*/
            }
            // REST中の処理
            // 現在のベースレイヤーがrestStateの時
            else if (currentBaseState.fullPathHash == restState)
            {
                //cameraObject.SendMessage("setCameraPositionFrontView");		// カメラを正面に切り替える
                // ステートが遷移中でない場合、Rest bool値をリセットする(ループしないようにする)
                if (!anim.IsInTransition(0))
                {
                    anim.SetBool("Rest", false);
                }
            }
        }