コード例 #1
0
    // FixedUpdate is called just before performing any physics calculations
    void FixedUpdate()
    {
        float moveHorizontal;
        float moveVertical;

#if (UNITY_EDITOR)
        {
            // This code lets us use either keyboard arrow or WASD keys, as well
            // as a controller (left thumbstick) which is ideal for VR/MR
            moveHorizontal = Input.GetAxis("Horizontal");
            moveVertical   = Input.GetAxis("Vertical");
        }
#else
        {
            controllerInput.Update();

            moveHorizontal = controllerInput.GetAxisLeftThumbstickX();
            moveVertical   = controllerInput.GetAxisLeftThumbstickY();
        }
#endif

        Vector3 movement = new Vector3(moveHorizontal, 0, moveVertical);

        rb.AddForce(movement * speed);
    }
コード例 #2
0
    private Vector3 GetMotionInput()
    {
#if UNITY_EDITOR
        float hor = Input.GetAxis("Horizontal");
        float ver = Input.GetAxis("Vertical");
        //bool buttonA = Input.GetKeyDown(KeyCode.Joystick1Button0);
        bool jump = Input.GetKey(KeyCode.LeftControl);
#else
        m_xboxController.Update();
        float hor     = m_xboxController.GetAxisLeftThumbstickX();
        float ver     = m_xboxController.GetAxisLeftThumbstickY();
        bool  buttonA = m_xboxController.GetButtonDown(ControllerButton.A);
        bool  buttonB = m_xboxController.GetButtonDown(ControllerButton.B);
        bool  jump    = m_xboxController.GetButton(ControllerButton.A);
#endif
        hor = Mathf.Abs(hor) > 0.25f ? hor : 0;
        ver = Mathf.Abs(ver) > 0.25f ? ver : 0;
        bool pressed = hor != 0 || ver != 0;
        if (!pressed)
        {
            m_horAxis = Vector3.zero;
            m_verAxis = Vector3.zero;
            return(Vector3.zero);
        }
        if (m_horAxis == Vector3.zero)
        {
            // Compute new motion axes
            m_verAxis = Vector3.Normalize(ProjectXZ(Camera.main.transform.forward));
            m_horAxis = Vector3.Normalize(Quaternion.Euler(0, 90, 0) * m_verAxis);
        }
        return(hor * m_horAxis + ver * m_verAxis);
    }
コード例 #3
0
        /// <summary>
        /// 获得左侧摇杆的纵向位移
        /// </summary>
        /// <returns></returns>
        public float GetAxisLeftThumbstickY()
        {
#if UNITY_METRO && !UNITY_EDITOR
            return(controllerInput.GetAxisLeftThumbstickY());
#else
            return(Input.GetAxis("Vertical"));
#endif
        }
コード例 #4
0
    void changeTransform()
    {
        float moveHorizontal = 0.0f, moveVertical = 0.0f, moveDepth = 0.0f;

        if (controllerInput.GetButton(ControllerButton.RightShoulder))
        {
            moveDepth = MoveSpeed * controllerInput.GetAxisLeftThumbstickY();
        }
        else
        {
            moveHorizontal = MoveSpeed * controllerInput.GetAxisLeftThumbstickX();
            moveVertical   = MoveSpeed * controllerInput.GetAxisLeftThumbstickY();
        }
        var rotateAroundY = RotateSpeed * controllerInput.GetAxisRightThumbstickX();

        transform.Translate(moveHorizontal, moveVertical, moveDepth);
        transform.Rotate(0, -rotateAroundY, 0);
    }
コード例 #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);
     * }*/

    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();
    }
コード例 #6
0
    private void move()
    {
        GameObject arrayRan     = GameObject.Find("sceneOrderData");
        random     randomScript = arrayRan.GetComponent <random>();
        string     sceneName    = randomScript.sceneOrder[GlobalControl.counter].sceneName;
        float      rotationY    = randomScript.sceneOrder[GlobalControl.counter].rotationY;


        char shape = sceneName[0];

        if (shape == '1')    // torus
        {
            float moveZAxis = MoveZAxisSpeed * controllerInput.GetAxisLeftThumbstickY();
            torus.transform.Translate(0, 0, moveZAxis, Space.World);
        }
        if (shape == '0')     //plane
        {
            float moveZAxis = MoveZAxisSpeed * controllerInput.GetAxisLeftThumbstickY();
            plane.transform.Translate(0, 0, moveZAxis, Space.World);
        }
    }
    private void moveForwardBack()
    {
        // xbox control
        if (controllerInput.GetAxisLeftThumbstickY() > 0)
        {
            rb.AddForce(forceforward, ForceMode.Acceleration);
            if (transform.rotation.x < 0.25f)
            {
                transform.Rotate(Vector3.right * controllerInput.GetAxisLeftThumbstickY() * 45 * Time.deltaTime);
            }
        }
        else if (controllerInput.GetAxisLeftThumbstickY() < 0)
        {
            rb.AddForce(forceback, ForceMode.Acceleration);
            if (transform.rotation.x > -0.25f)
            {
                transform.Rotate(Vector3.left * -controllerInput.GetAxisLeftThumbstickY() * 45 * Time.deltaTime);
            }
        }

        // keyboard control
        if (Input.GetKey(KeyCode.UpArrow))
        {
            rb.AddForce(forceforward, ForceMode.Acceleration);
            if (transform.rotation.x < 0.25f)
            {
                transform.Rotate(Vector3.right * 45 * Time.deltaTime);
            }
        }

        if (Input.GetKey(KeyCode.DownArrow))
        {
            rb.AddForce(forceback, ForceMode.Acceleration);
            if (transform.rotation.x > -0.25f)
            {
                transform.Rotate(Vector3.left * 45 * Time.deltaTime);
            }
        }
    }
コード例 #8
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);
        }
    }
コード例 #9
0
    private void FixedUpdate()
    {
        float h      = MoveHorizontalSpeed * controllerInput.GetAxisLeftThumbstickX();
        float v      = MoveVerticalSpeed * controllerInput.GetAxisLeftThumbstickY();
        bool  crouch = controllerInput.GetButton(ControllerButton.B);

        if (m_Cam != null)
        {
            m_CamForward = Vector3.Scale(m_Cam.forward, new Vector3(1, 0, 1)).normalized;
            m_Move       = v * m_CamForward + h * m_Cam.right;
        }

        m_Character.Move(m_Move, crouch, m_Jump);
        m_Jump = false;
    }
コード例 #10
0
    private void translateRotateScale()
    {
        float moveHorizontal = MoveHorizontalSpeed * controllerInput.GetAxisLeftThumbstickX();
        float moveVertical   = MoveVerticalSpeed * controllerInput.GetAxisLeftThumbstickY();

        transform.Translate(moveHorizontal, moveVertical, 0);

        RaycastHit hit;

        if (Physics.Raycast(transform.position, Vector3.forward, out hit, maxRayDistance))
        {
            transform.Translate(0, 0, hit.distance - 0.01f);
            mKey = hit.transform.gameObject;

            if (mKey.tag == "Keys")
            {
                if (mKey != prev_mKey && prev_mKey.tag == "Keys")
                {
                    prev_mKey.GetComponent <KeyboardItem>().r.material = mKey.GetComponent <KeyboardItem>().theme.GetThemeValue(KeyState.Default);
                }
                mKey.GetComponent <KeyboardItem>().r.material = mKey.GetComponent <KeyboardItem>().theme.GetThemeValue(KeyState.Focused);
            }

            if (controllerInput.GetButtonDown(ControllerButton.A))
            {
                if (mKey == GameObject.Find("Start"))
                {
                    Manager.GetComponent <Controller>().startClicked();
                    Manager.GetComponent <PhraseSet>().listStart();
                }
                else if (mKey == GameObject.Find("Submit"))
                {
                    Manager.GetComponent <Controller>().submitClicked();
                    Manager.GetComponent <PhraseSet>().listSubmit();
                }
                else if (mKey.tag == "Keys")
                {
                    mKey.GetComponent <KeyboardItem>().r.material = mKey.GetComponent <KeyboardItem>().theme.GetThemeValue(KeyState.Pressed);
                    KeyboardMaster.GetComponent <KeyboardCreator>().HandleTap(mKey.GetComponent <KeyboardItem>());
                }
            }
            prev_mKey = mKey;
        }
        else
        {
            transform.Translate(0, 0, 2.0f - transform.position.z);
        }
    }
コード例 #11
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);
            }
        }
    }
コード例 #12
0
ファイル: GeoMaker.cs プロジェクト: ly774508966/hololens
    private void Update()
    {
        if (!PlayspaceManager.Instance.IsScanningComplete())
        {
            return;
        }

        // Get current joypad axis values
#if UNITY_EDITOR
        float hor     = Input.GetAxis("Horizontal");
        float ver     = Input.GetAxis("Vertical");
        bool  buttonA = Input.GetKeyDown(KeyCode.Joystick1Button0);
        bool  buttonB = Input.GetKeyDown(KeyCode.Joystick1Button1);
#else
        m_xboxController.Update();
        float hor     = m_xboxController.GetAxisLeftThumbstickX();
        float ver     = m_xboxController.GetAxisLeftThumbstickY();
        bool  buttonA = m_xboxController.GetButtonDown(ControllerButton.A);
        bool  buttonB = m_xboxController.GetButtonDown(ControllerButton.B);
#endif

        float delta = (Mathf.Abs(ver) > 0.25f ? ver : 0) * Time.deltaTime;

        if (m_state == State.Select)
        {
            m_selection.Raycast(Camera.main.transform.position, Camera.main.transform.forward);
            Vector3[] vertices;
            int[]     triangles;
            Vector2[] uv;
            m_selection.GenerateMeshData(out vertices, out triangles, out uv);
            if (vertices.Length > 0)
            {
                m_mesh.Clear();
                m_mesh.vertices  = vertices;
                m_mesh.uv        = uv;
                m_mesh.triangles = triangles;
                m_mesh.RecalculateBounds();
                //TODO: make a GetTransform function
                m_gameObject.transform.rotation   = m_selection.rotation;
                m_gameObject.transform.position   = m_selection.position;
                m_gameObject.transform.localScale = m_selection.scale;
                if (buttonA)
                {
                    m_state        = State.ExtrudeSimple;
                    m_meshExtruder = new MeshExtruder(m_selection);
                }
                else if (buttonB)
                {
                    m_state        = State.ExtrudeCapped;
                    m_meshExtruder = new MeshExtruder(m_selection);
                }
            }
        }
        else if (m_state == State.ExtrudeSimple)
        {
            m_extrudeLength += delta;
            Vector3[] vertices;
            int[]     triangles;
            Vector2[] uv;
            m_meshExtruder.ExtrudeSimple(out vertices, out triangles, out uv, m_extrudeLength, m_topUV, m_sideUV, m_extrudeLength * 100);// SelectionTile.SIDE_CM);
            m_mesh.Clear();
            m_mesh.vertices  = vertices;
            m_mesh.uv        = uv;
            m_mesh.triangles = triangles;
            m_mesh.RecalculateBounds();
            m_mesh.RecalculateNormals();
            m_meshRenderer.material   = extrudeMaterial;
            m_meshCollider.sharedMesh = null;
            m_meshCollider.sharedMesh = m_mesh;
            if (buttonA)
            {
                m_state = State.Finished;
            }
        }
        else if (m_state == State.ExtrudeCapped)
        {
            m_extrudeLength += delta;
            Vector3[] vertices;
            int[]     triangles;
            Vector2[] uv;
            m_meshExtruder.ExtrudeCapped(out vertices, out triangles, out uv, m_extrudeLength, m_topUV, m_sideUV, m_sideUV);
            m_mesh.Clear();
            m_mesh.vertices  = vertices;
            m_mesh.uv        = uv;
            m_mesh.triangles = triangles;
            m_mesh.RecalculateBounds();
            m_mesh.RecalculateNormals();
            m_meshRenderer.material   = extrudeMaterial;
            m_meshCollider.sharedMesh = null;
            m_meshCollider.sharedMesh = m_mesh;
            if (buttonA)
            {
                m_state = State.Finished;
            }
        }
    }
コード例 #13
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);
        }
    }
コード例 #14
0
    // Update is called once per frame
    void Update()
    {
        controllerInput.Update();
        GameObject cloud = GameObject.Find("cloudMeshMap");

        if (enable == false)
        {
            return;
        }

        if (Input.GetAxis("Vertical") > 0 || controllerInput.GetAxisLeftThumbstickY() > 0)
        {
            Vector3 current_position = this.transform.localPosition;
            current_position.y++;
            if (current_position.y + resolution / 2 <= row_num / 2)
            {
                this.transform.localPosition = current_position;
                cloud.GetComponent <cloud_mesh>().Update_position(current_position);
                send_coor(current_position);
            }
        }
        if (Input.GetAxis("Vertical") < 0 || controllerInput.GetAxisLeftThumbstickY() < 0)
        {
            Vector3 current_position = this.transform.localPosition;
            current_position.y--;
            if (current_position.y - resolution / 2 >= -row_num / 2)
            {
                this.transform.localPosition = current_position;
                cloud.GetComponent <cloud_mesh>().Update_position(current_position);
                send_coor(current_position);
            }
        }
        if (Input.GetAxis("Horizontal") < 0 || controllerInput.GetAxisLeftThumbstickX() < 0)
        {
            Vector3 current_position = this.transform.localPosition;
            current_position.x--;
            if (current_position.x - resolution / 2 >= -col_num / 2)
            {
                this.transform.localPosition = current_position;
                cloud.GetComponent <cloud_mesh>().Update_position(current_position);
                send_coor(current_position);
            }
        }
        if (Input.GetAxis("Horizontal") > 0 || controllerInput.GetAxisLeftThumbstickX() > 0)
        {
            Vector3 current_position = this.transform.localPosition;
            current_position.x++;
            if (current_position.x + resolution / 2 <= col_num / 2)
            {
                this.transform.localPosition = current_position;
                cloud.GetComponent <cloud_mesh>().Update_position(current_position);
                send_coor(current_position);
            }
        }
        if (Input.GetKeyDown(KeyCode.JoystickButton8) || (controllerInput.GetButton(ControllerButton.LeftThumbstick)))
        {
            Vector3 current_position = new Vector3(0, 0, 0);
            this.transform.localPosition = current_position;
            cloud.GetComponent <cloud_mesh>().Update_position(current_position);
            send_coor(current_position);
        }

/*
 *      if (Input.GetKeyDown(KeyCode.JoystickButton4))
 *      {
 *          if (resolution > 49)
 *          {
 *              resolution = resolution / 2;
 *              Vector3 current_position = this.transform.localPosition;
 *              cloud.GetComponent<cloud_mesh>().resize_view(resolution, current_position);
 *              send_coor(current_position);
 *          }
 *
 *      }
 *
 *      if (Input.GetKeyDown(KeyCode.JoystickButton5))
 *      {
 *          if (resolution < 101)
 *          {
 *              resolution = resolution * 2;
 *              Vector3 current_position = this.transform.localPosition;
 *              if (current_position.y + resolution / 2 > row_num / 2)
 *              {
 *                  current_position.y = row_num / 2 - resolution / 2;
 *              }
 *              if (current_position.y - resolution / 2 < -row_num / 2)
 *              {
 *                  current_position.y = -row_num / 2 + resolution / 2;
 *              }
 *              if (current_position.x + resolution / 2 > col_num / 2)
 *              {
 *                  current_position.x = col_num / 2 - resolution / 2;
 *              }
 *              if (current_position.x - resolution / 2 < -col_num / 2)
 *              {
 *                  current_position.x = -col_num / 2 + resolution / 2;
 *              }
 *              this.transform.localPosition = current_position;
 *              cloud.GetComponent<cloud_mesh>().resize_view(resolution, current_position);
 *              send_coor(current_position);
 *          }
 *      }
 */
    }