コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        controllerInput.Update();
        float rotation_z = this.transform.eulerAngles.z;
        float rotation_y = this.transform.eulerAngles.y;
        float rotation_x = this.transform.eulerAngles.x;

        if (Input.GetAxis("rotate_v") < 0 || controllerInput.GetAxisRightThumbstickY() < 0)
        {
            rotation_x = rotation_x + 1;
            if (rotation_x >= 358)
            {
                rotation_x = 358;
            }
            this.transform.rotation = Quaternion.Euler(rotation_x, rotation_y, rotation_z);
        }
        if (Input.GetAxis("rotate_v") > 0 || controllerInput.GetAxisRightThumbstickY() > 0)
        {
            rotation_x = rotation_x - 1;
            if (rotation_x < 270)
            {
                rotation_x = 270;
            }
            this.transform.rotation = Quaternion.Euler(rotation_x, rotation_y, rotation_z);
        }
        if (Input.GetKeyDown(KeyCode.JoystickButton9) || (controllerInput.GetButton(ControllerButton.RightThumbstick)))
        {
            // this.transform.rotation = Quaternion.Euler(0, 0, 0);
            GameObject mesh = GameObject.Find("cloudMeshMap");
            mesh.transform.localRotation = Quaternion.Euler(0, 90, 0);
        }
    }
コード例 #2
0
        /// <summary>
        /// 获得右侧摇杆的纵向位移
        /// </summary>
        /// <returns></returns>
        public float GetAxisRightThumbstickY()
        {
#if UNITY_METRO && !UNITY_EDITOR
            return(controllerInput.GetAxisRightThumbstickY());
#else
            return(Input.GetAxis("RightVertical"));
#endif
        }
コード例 #3
0
    void updateRotation()
    {
        //float v= Input.GetAxis("Right Stick X");
        //float h =Input.GetAxis("Right Stick Y");
        float h = controllerInput.GetAxisRightThumbstickY() * movementSpeed;// For bluetooth Xbox controller input Input.GetAxis("Right Stick X")
        float v = controllerInput.GetAxisRightThumbstickX() * movementSpeed;

        transform.Rotate(v, h, 0);
    }
コード例 #4
0
    /* private void translateRotateScale()
     * {
     *   float moveHorizontal = MoveHorizontalSpeed * controllerInput.GetAxisLeftThumbstickX();
     *   float moveVertical = MoveVerticalSpeed * controllerInput.GetAxisLeftThumbstickY();
     *   this.transform.Translate(moveHorizontal, moveVertical, 0.0f);
     *
     *   float rotateAroundY = RotateAroundYSpeed * controllerInput.GetAxisRightThumbstickX();
     *   float rotateAroundX = RotateAroundXSpeed * controllerInput.GetAxisRightThumbstickY();
     *   float rotateAroundZ = RotateAroundZSpeed * (controllerInput.GetAxisRightTrigger() - controllerInput.GetAxisLeftTrigger());
     *   this.transform.Rotate(rotateAroundX, -rotateAroundY, rotateAroundZ);
     *
     *   if (controllerInput.GetButton(ControllerButton.DPadUp))
     *       this.transform.localScale = this.transform.localScale + (this.transform.localScale * ScaleSpeed * Time.deltaTime);
     *
     *   if (controllerInput.GetButton(ControllerButton.DPadDown))
     *       this.transform.localScale = this.transform.localScale - (this.transform.localScale * ScaleSpeed * Time.deltaTime);
     * }*/

    private void setAxisInputText()
    {
        AxisInputText.text =
            "LeftThumbstickX: " + controllerInput.GetAxisLeftThumbstickX().ToString() + System.Environment.NewLine +
            "LeftThumbstickY: " + controllerInput.GetAxisLeftThumbstickY().ToString() + System.Environment.NewLine +
            "RightThumbstickX: " + controllerInput.GetAxisRightThumbstickX().ToString() + System.Environment.NewLine +
            "RightThumbstickY: " + controllerInput.GetAxisRightThumbstickY().ToString() + System.Environment.NewLine +
            "LeftTrigger: " + controllerInput.GetAxisLeftTrigger().ToString() + System.Environment.NewLine +
            "RightTrigger: " + controllerInput.GetAxisRightTrigger().ToString();
    }
コード例 #5
0
    private void translateRotateScale()
    {
        float moveHorizontal = MoveHorizontalSpeed * controllerInput.GetAxisLeftThumbstickX();
        float moveVertical   = MoveVerticalSpeed * controllerInput.GetAxisLeftThumbstickY();

        this.transform.Translate(moveHorizontal, moveVertical, 0.0f);

        float rotateAroundY = RotateAroundYSpeed * controllerInput.GetAxisRightThumbstickX();
        float rotateAroundX = RotateAroundXSpeed * controllerInput.GetAxisRightThumbstickY();
        float rotateAroundZ = RotateAroundZSpeed * (controllerInput.GetAxisRightTrigger() - controllerInput.GetAxisLeftTrigger());

        this.transform.Rotate(rotateAroundX, -rotateAroundY, rotateAroundZ);

        if (controllerInput.GetButton(ControllerButton.DPadUp))
        {
            this.transform.localScale = this.transform.localScale + (this.transform.localScale * ScaleSpeed * Time.deltaTime);
        }

        if (controllerInput.GetButton(ControllerButton.DPadDown))
        {
            this.transform.localScale = this.transform.localScale - (this.transform.localScale * ScaleSpeed * Time.deltaTime);
        }
    }
コード例 #6
0
    void Update()
    {
        controllerInput.Update();

        float mouseX = controllerInput.GetAxisRightThumbstickX(); //
        float mouseY = controllerInput.GetAxisRightThumbstickY(); //

        //mouseX= Input.GetAxis("Mouse X");
        //mouseY= -Input.GetAxis("Mouse Y");
        rotY += mouseX * mouseSensitivity * Time.deltaTime;
        rotX += mouseY * mouseSensitivity * Time.deltaTime;

        rotX = Mathf.Clamp(rotX, -clampAngle, clampAngle);

        Quaternion localRotation = Quaternion.Euler(rotX, rotY, 0.0f);

        transform.rotation = localRotation;
    }
コード例 #7
0
    // Update is called once per frame
    void Update()
    {
        bool  updateNeeded = false;
        float cutoff       = 0.5f;
        float input;

        _controllerInput.Update();

        if (_controllerInput.GetButton(ControllerButton.DPadUp))
        {
            updateNeeded = _dataManager.SizeWindow(4);
        }
        else if (_controllerInput.GetButton(ControllerButton.DPadDown))
        {
            updateNeeded = _dataManager.SizeWindow(-4);
        }
        else if (_controllerInput.GetButton(ControllerButton.DPadRight))
        {
            updateNeeded = _dataManager.MoveWindow(4);
        }
        else if (_controllerInput.GetButton(ControllerButton.DPadLeft))
        {
            updateNeeded = _dataManager.MoveWindow(-4);
        }

        if (updateNeeded)
        {
            foreach (SliceManagerScript slice in slices)
            {
                slice.RefreshSlices();
            }
        }

        if (_controllerInput.GetButton(ControllerButton.View))
        {
            foreach (SliceManagerScript slice in slices)
            {
                slice.CenterSlice();
            }
        }

        input = _controllerInput.GetAxisLeftThumbstickY();
        if (Mathf.Abs(input) > cutoff)
        {
            if (input > 0f)
            {
                slices[0].MoveSlice(1);
            }
            else
            {
                slices[0].MoveSlice(-1);
            }
        }

        input = _controllerInput.GetAxisRightThumbstickY();
        if (Mathf.Abs(input) > cutoff)
        {
            if (input > 0f)
            {
                slices[1].MoveSlice(1);
            }
            else
            {
                slices[1].MoveSlice(-1);
            }
        }

        input = _controllerInput.GetAxisLeftThumbstickX();
        if (Mathf.Abs(input) > cutoff)
        {
            if (input > 0f)
            {
                slices[2].MoveSlice(1);
            }
            else
            {
                slices[2].MoveSlice(-1);
            }
        }
    }
コード例 #8
0
ファイル: Helicopter.cs プロジェクト: ly774508966/hololens
    private void UpdateControls(Vector3 aim)
    {
        // Determine angle between user gaze vector and helicopter forward, in xz
        // plane
        Vector3 view    = new Vector3(Camera.main.transform.forward.x, 0, Camera.main.transform.forward.z);
        Vector3 forward = new Vector3(transform.forward.x, 0, transform.forward.z);
        float   angle   = Vector3.Angle(view, forward);

        // Get current joypad axis values
#if UNITY_EDITOR
        float hor     = Input.GetAxis("Horizontal");
        float ver     = Input.GetAxis("Vertical");
        float hor2    = Input.GetAxis("Horizontal2");
        float ver2    = -Input.GetAxis("Vertical2");
        float lt      = Input.GetAxis("Axis9");
        float rt      = Input.GetAxis("Axis10");
        bool  buttonA = Input.GetKey(KeyCode.Joystick1Button0);
        bool  buttonB = Input.GetKey(KeyCode.Joystick1Button1);
        bool  fire    = rt > 0.5f || buttonA;
#else
        m_xboxController.Update();
        float hor     = m_xboxController.GetAxisLeftThumbstickX();
        float ver     = m_xboxController.GetAxisLeftThumbstickY();
        float hor2    = m_xboxController.GetAxisRightThumbstickX();
        float ver2    = m_xboxController.GetAxisRightThumbstickY();
        float lt      = m_xboxController.GetAxisLeftTrigger();
        float rt      = m_xboxController.GetAxisRightTrigger();
        bool  fire    = rt > 0.5f;
        bool  buttonA = m_xboxController.GetButton(ControllerButton.A);
        bool  buttonB = m_xboxController.GetButton(ControllerButton.B);

        /*
         * float hor = Input.GetAxis("Horizontal");
         * float ver = Input.GetAxis("Vertical");
         * float axis3 = Input.GetAxis("Axis3");
         * float lt = Mathf.Max(axis3, 0);
         * float rt = -Mathf.Min(axis3, 0);
         */
#endif

        // Any of the main axes (which are relative to orientation) pressed?
        bool movingThisFrame = (hor != 0) || (ver != 0);
        if (movingThisFrame && !m_movingLastFrame)
        {
            // Joypad was not pressed last frame, reorient based on current view position
            m_joypadLateralAxis      = Vector3.Normalize(Camera.main.transform.right);
            m_joypadLongitudinalAxis = Vector3.Normalize(Camera.main.transform.forward);
        }
        m_movingLastFrame = movingThisFrame;

        // Apply longitudinal and lateral controls. Compute projection of joypad
        // lateral/longitudinal axes onto helicopter's.
        float joypadLongitudinalToHeliLongitudinal = Vector3.Dot(m_joypadLongitudinalAxis, transform.forward);
        float joypadLongitudinalToHeliLateral      = Vector3.Dot(m_joypadLongitudinalAxis, transform.right);
        float joypadLateralToHeliLongitudinal      = Vector3.Dot(m_joypadLateralAxis, transform.forward);
        float joypadLateralToHeliLateral           = Vector3.Dot(m_joypadLateralAxis, transform.right);
        m_playerControls.longitudinal = joypadLongitudinalToHeliLongitudinal * ver + joypadLateralToHeliLongitudinal * hor;
        m_playerControls.lateral      = joypadLongitudinalToHeliLateral * ver + joypadLateralToHeliLateral * hor;

        // Helicopter rotation
        m_playerControls.rotational = hor2;

        // Altitude control (trigger axes each range from 0 to 1)
        m_playerControls.altitude = ver2;

        // Gun
        if (fire && (Time.time - m_gunLastFired >= GUN_FIRE_PERIOD))
        {
            FireGun(aim);
        }
    }