GetPress() public method

public GetPress ( EVRButtonId buttonId ) : bool
buttonId EVRButtonId
return bool
    void FixedUpdate()
    {
        device = SteamVR_Controller.Input ((int)trackedObj.index);

        if (device.GetTouch (SteamVR_Controller.ButtonMask.Trigger)) {
            Debug.Log ("You are holding 'touch' on the trigger");
        }
        if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger))
        {
            Debug.Log("You activated TouchDown on the trigger");
        }
        if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger))
        {
            Debug.Log("You activated TouchUp on the trigger");
        }

        if (device.GetPress(SteamVR_Controller.ButtonMask.Trigger))
        {
            Debug.Log("You are holding 'press' on the trigger");
        }
        if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger))
        {
            Debug.Log("You activated PressDown on the trigger");
        }
        if (device.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad))
        {
            Debug.Log("You activated PressUp on the touchpad");
            sphere.transform.position = Vector3.zero;
            sphere.GetComponent<Rigidbody>().velocity = Vector3.zero;
            sphere.GetComponent<Rigidbody>().angularVelocity = Vector3.zero;
        }
    }
Ejemplo n.º 2
0
 void myTouchPadDetect(SteamVR_Controller.Device device)
 {
     if (device.GetPress(SteamVR_Controller.ButtonMask.Touchpad))
     {
         isTouchPadPress = true;
     }
     else
     {
         isTouchPadPress = false;
     }
     if (device.GetTouch(SteamVR_Controller.ButtonMask.Touchpad))
     {
         isTouchPadTouch  = true;
         touchpadPosition = device.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0);
     }
     else
     {
         isTouchPadTouch  = false;
         touchpadPosition = new Vector2(0, 0);
     }
 }
Ejemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        if (_rightObj.index == SteamVR_TrackedObject.EIndex.None)
        {
            return;
        }
        _rightController = SteamVR_Controller.Input((int)_rightObj.index);
        if (_rightController.GetPress(SteamVR_Controller.ButtonMask.Touchpad))
        {
            Vector2 touchpad = _rightController.GetAxis(EVRButtonId.k_EButton_SteamVR_Touchpad);

            if (touchpad.y > 0.5f)
            {
                transform.Translate(new Vector3(0, 2, 0) * Time.deltaTime);
            }
            else if (touchpad.y < -0.5f)
            {
                transform.Translate(new Vector3(0, -2, 0) * Time.deltaTime);
            }
        }
    }
Ejemplo n.º 4
0
    private void switchDoorState(SteamVR_Controller.Device controller)
    {
        UnityEngine.Debug.Log("current state: " + this.PanelState);

        switch (this.PanelState)
        {
        case PanelStates.IN_FRONT:
            if (controller.GetPress(EVRButtonId.k_EButton_SteamVR_Trigger))
            {
                this.StartCoroutine(this.doAnimation("Closing", PanelStates.IN_BACKGROUND));
            }
            break;

        case PanelStates.IN_BACKGROUND:
            this.StartCoroutine(this.doAnimation("Openning", PanelStates.IN_FRONT));
            break;

        default:
            break;
        }
    }
    private void OnTriggerStay(Collider other)
    {
        if (other.transform.tag == "Grabbable")
        {
            if (device.GetPress(SteamVR_Controller.ButtonMask.Trigger) && fj == null)
            {
                fj = rb.gameObject.AddComponent <FixedJoint>();
                fj.connectedBody      = other.transform.GetComponent <Rigidbody>();
                fj.breakForce         = breakForce;
                fj.breakTorque        = breakForce;
                fj.connectedBody.mass = 100f;

                if (other.transform.parent != grabParent.transform && !other.transform.name.Contains("Laser"))
                {
                    fj.connectedBody.isKinematic = false;
                    other.transform.SetParent(grabParent.transform);
                    other.transform.GetComponent <Collider>().isTrigger = false;
                }
            }
        }
    }
Ejemplo n.º 6
0
    void OnTriggerStay(Collider col)
    {
        if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger))
        {
            col.attachedRigidbody.isKinematic = true;
            col.gameObject.transform.SetParent(this.gameObject.transform);
        }

        if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger))
        {
            col.gameObject.transform.SetParent(null);
            col.attachedRigidbody.isKinematic = false;

            //tossObject(col.attachedRigidbody);
        }

        if (device.GetPress(SteamVR_Controller.ButtonMask.Grip))
        {
            //hitObject (col.attachedRigidbody);
        }
    }
Ejemplo n.º 7
0
    // Update is called once per frame
    void Update()
    {
        device = SteamVR_Controller.Input((int)controller.index);
        //If finger is on touchpad
        if (device.GetPress(SteamVR_Controller.ButtonMask.Trigger))
        {
            //teleport();
        }
        //else { data.setTrigger(false); }

        if (device.GetTouch(SteamVR_Controller.ButtonMask.Touchpad))
        {
            //Read the touchpad values
            touchpad = device.GetAxis(EVRButtonId.k_EButton_SteamVR_Touchpad);


            // Handle movement via touchpad
            if (touchpad.y > 0.2f || touchpad.y < -0.2f)
            {
                float speed = 8;
                // Move Forward
                //if (device.GetPress(SteamVR_Controller.ButtonMask.Trigger)) { speed = 20; data.setTrigger(true); }
                //else { data.setTrigger(false); }

                player.transform.position += player.transform.forward * Time.deltaTime * (touchpad.y * speed);
                // Adjust height to terrain height at player positin
                //playerPos = player.transform.position;
                //playerPos.y = Terrain.activeTerrain.SampleHeight(player.transform.position);
                //player.transform.position = playerPos;
            }

            // handle rotation via touchpad
            if (touchpad.x > 0.3f || touchpad.x < -0.3f)
            {
                player.transform.Rotate(0, touchpad.x * sensitivityX, 0);
            }

            //Debug.Log ("Touchpad X = " + touchpad.x + " : Touchpad Y = " + touchpad.y);
        }
    }
Ejemplo n.º 8
0
    void Update()
    {
        // Initializes device variable every frame
        //trackedObj = hand.handTrackedRight;
        //device = hand.handDeviceRight;

        SteamVR_Controller.Device device = SteamVR_Controller.Input((int)trackedObj.index);

        triggerAxis = device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger).x; //Gets depth of trigger press

        if (enableSprint)
        {
            // Enable sprinting when the touchpad is pressed and stamina != 0
            if (device.GetPress(SteamVR_Controller.ButtonMask.Touchpad) && staminaAmnt >= 0f)
            {
                staminaAmnt  -= staminaDrain * Time.deltaTime;
                sprintInertia = Mathf.Lerp(sprintInertia, 1, Time.deltaTime * sprintInertiaSpeed);
                isSprinting   = true;
                sprintSpeed   = (staminaAmnt / staminaAmntMax);

                if (staminaAmnt >= .1f)
                {
                    SprintSound();
                    sprintingAudio.volume = Mathf.Lerp(sprintingAudio.volume, .07f, Time.deltaTime / 2);
                }
            }
            else
            {
                sprintSpeed           = 0;
                sprintInertia         = Mathf.Lerp(sprintInertia, 0, Time.deltaTime / 2f);
                sprintingAudio.volume = Mathf.Lerp(sprintingAudio.volume, 0f, Time.deltaTime);
                staminaAmnt          += staminaRecovery * Time.deltaTime;
                if (staminaAmnt >= staminaAmntMax)
                {
                    staminaAmnt = staminaAmntMax;
                }
                sprintSoundPlayed = false;
            }
        }
    }
Ejemplo n.º 9
0
        void UpdateStateRight(SteamVR_Utils.RigidTransform pose, SteamVR_Controller.Device state)
        {
            if (state.GetPress(EVRButtonId.k_EButton_SteamVR_Touchpad))
            {
                Vector2 touchAxis = state.GetAxis(EVRButtonId.k_EButton_SteamVR_Touchpad);

                Vector3 fwdDirection = Scene.HmdRotation * Vector3.forward;
                fwdDirection.y = 0f; // allow only planar movement
                Vector3 fwdDisplacement = fwdDirection.normalized * (movementVelocity * touchAxis.y) * Time.deltaTime;

                Vector3 rightDirection = Scene.HmdRotation * Vector3.right;
                rightDirection.y = 0f; // allow only planar movement
                Vector3 rightDisplacement = rightDirection.normalized * (movementVelocity * touchAxis.x) * Time.deltaTime;

                Scene.CurrentPosition += fwdDisplacement + rightDisplacement;
            }

            if (state.GetPressDown(EVRButtonId.k_EButton_ApplicationMenu))
            {
                KerbalVR.ResetInitialHmdPosition();
            }
        }
Ejemplo n.º 10
0
    // Update is called once per frame
    void Update()
    {
        if (device.GetPress(SteamVR_Controller.ButtonMask.Touchpad))
        {
            Vector2 touchpad = (device.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0));
            print("Pressing Touchpad");

            GameObject hihat  = GameObject.Find("HiHat");
            GameObject kick   = GameObject.Find("Kick");
            GameObject snare  = GameObject.Find("Snare");
            GameObject crash  = GameObject.Find("Crash");
            GameObject melody = GameObject.Find("Melody");

            if (touchpad.y > 0.7f)
            {
                Debug.Log("moving up");
            }
            else if (touchpad.y < -0.7f)
            {
                Debug.Log("moving down");
            }
            if (touchpad.x > 0.7f)  // right
            {
                hihat.transform.RotateAround(hihat.GetComponent <Collider>().bounds.center, Vector3.down, rotAmount * Time.deltaTime);
                kick.transform.RotateAround(kick.GetComponent <Collider>().bounds.center, Vector3.down, rotAmount * Time.deltaTime);
                snare.transform.RotateAround(snare.GetComponent <Collider>().bounds.center, Vector3.down, rotAmount * Time.deltaTime);
                crash.transform.RotateAround(crash.GetComponent <Collider>().bounds.center, Vector3.down, rotAmount * Time.deltaTime);
                melody.transform.RotateAround(melody.GetComponent <Collider>().bounds.center, Vector3.down, rotAmount * Time.deltaTime);
            }
            else if (touchpad.x < -0.7f)  // left
            {
                hihat.transform.RotateAround(hihat.GetComponent <Collider>().bounds.center, Vector3.up, rotAmount * Time.deltaTime);
                kick.transform.RotateAround(kick.GetComponent <Collider>().bounds.center, Vector3.up, rotAmount * Time.deltaTime);
                snare.transform.RotateAround(snare.GetComponent <Collider>().bounds.center, Vector3.up, rotAmount * Time.deltaTime);
                crash.transform.RotateAround(crash.GetComponent <Collider>().bounds.center, Vector3.up, rotAmount * Time.deltaTime);
                melody.transform.RotateAround(melody.GetComponent <Collider>().bounds.center, Vector3.up, rotAmount * Time.deltaTime);
            }
        }
    }
Ejemplo n.º 11
0
    void OnTriggerStay(Collider col)
    {
        if (col.gameObject.CompareTag("Throwable"))
        {
            if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger))
            {
                ThrowObject(col);
            }
            else if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger))
            {
                GrabObject(col);
            }
        }

        if (col.gameObject.CompareTag("Restart"))
        {
            if (device.GetPress(SteamVR_Controller.ButtonMask.Trigger))
            {
                RestartGame();
            }
        }
    }
Ejemplo n.º 12
0
    // Update is called once per frame
    void Update()
    {
        this.deviceL = this.leftHand.controller;
        this.deviceR = this.rightHand.controller;

        float h = Input.GetAxis("Horizontal");

        this.myBody.velocity = new Vector3(-h * this.moveForce, 0f, 0f);

        if (deviceL.GetPress(SteamVR_Controller.ButtonMask.Touchpad))
        {
            Vector2 touchpad = (deviceL.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0));
            print("Pressing Touchpad " + touchpad.x);
            h = touchpad.x;
            this.myBody.velocity = new Vector3(-h * this.moveForce, 0f, 0f);
        }

        if (deviceR.GetHairTriggerDown())
        {
            this.myBody.AddForce(Vector3.up * 2000f, ForceMode.Impulse);
        }
    }
Ejemplo n.º 13
0
    // Update is called once per frame
    void Update()
    {
        device = SteamVR_Controller.Input((int)trackedObj.index);

        if (device.GetPress(SteamVR_Controller.ButtonMask.Touchpad))
        {
            laser.gameObject.SetActive(true);
            teleportAimerObject.SetActive(true);

            //set start pos of laser
            laser.SetPosition(0, gameObject.transform.position);
            RaycastHit hit;
            if (Physics.Raycast(transform.position, transform.forward, out hit, 15, laserMask))
            {
                teleportLocation = hit.point;
                laser.SetPosition(1, teleportLocation);
                //aimer position
                teleportAimerObject.transform.position = new Vector3(teleportLocation.x, teleportLocation.y + yNudgeAmount, teleportLocation.z);
            }
            else
            {
                teleportLocation = new Vector3(transform.forward.x * 15 + transform.position.x, transform.forward.y * 15 + transform.position.y, transform.forward.z * 15 + transform.position.z);
                RaycastHit groundRay;
                if (Physics.Raycast(teleportLocation, -Vector3.up, out groundRay, 17, laserMask))
                {
                    teleportLocation = new Vector3(transform.forward.x * 15 + transform.position.x, groundRay.point.y, transform.forward.z * 15 + transform.position.z);
                }
                //aimer position
                teleportAimerObject.transform.position = teleportLocation + new Vector3(0, yNudgeAmount, 0);
                laser.SetPosition(1, teleportAimerObject.transform.position);
            }
        }
        if (device.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad))
        {
            laser.gameObject.SetActive(false);
            teleportAimerObject.SetActive(false);
            player.transform.position = teleportLocation;
        }
    }
Ejemplo n.º 14
0
    void UpdateTeleportRotation()
    {
        Vector2 sticks  = new Vector2();
        bool    pressed = false;

        SteamVR_Controller.Device device = SteamVR_Controller.Input((int)rightController.GetComponent <SteamVR_TrackedController>().controllerIndex);
        if (UnityEngine.XR.XRDevice.model == "Vive MV")
        {
            bool    pressTouchpad = device.GetPress(EVRButtonId.k_EButton_SteamVR_Touchpad);
            Vector2 touch         = device.GetAxis(EVRButtonId.k_EButton_SteamVR_Touchpad);
            pressed = pressTouchpad;
            sticks  = pressTouchpad ? touch : new Vector2(0, 0); // to emulate joystick press hard the touchpad
        }
        //print(sticks);

        if (joyPressedDashRot)
        {
            if (!pressed)
            {
                joyPressedDashRot = false;
            }
        }
        else
        {
            if (pressed)
            {
                joyPressedDashRot = true;
                GameObject pivot = new GameObject();
                pivot.transform.position = player.transform.Find("[CameraRig]").Find("Camera (eye)").transform.position;

                player.transform.SetParent(pivot.transform);

                pivot.transform.Rotate(Vector3.up, sticks[0] * 20);
                player.transform.SetParent(null);
                Destroy(pivot);
            }
        }
    }
Ejemplo n.º 15
0
	void WeaponUpdate()
	{
		SteamVR_TrackedObject trackedObj = manager.right.GetComponent<SteamVR_TrackedObject>();
		SteamVR_Controller.Device rightDevice = SteamVR_Controller.Input((int)trackedObj.index);

		switch (m_NowWeapon)
		{
			case WeaponName.Gun:
				// 入力を受け付けている
				//if (Input.GetMouseButton(0))
				if (rightDevice.GetPress(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger))
				{
					m_TimeCnt += Time.deltaTime;

					// 規定秒数を超えたら武器チェンジ
					if (m_TimeCnt > m_PushInTime)
					{
						SwitchWeapon();
						m_TimeCnt = -400000.0f;     // 連続で武器が切り替わることを適当に阻止
					}
				}
				else
				{
					// 離されている
					m_TimeCnt = 0.0f;
				}
				break;
			case WeaponName.Sword:
				// 入力を離した
				//if (!Input.GetMouseButton(0))
				if (rightDevice.GetPressUp(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger))
				{
					SwitchWeapon();
					m_TimeCnt = 0;
				}
					break;
		}
	}
Ejemplo n.º 16
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.I))
        {
            calibratingMode = !calibratingMode;
            return;
        }

        if ((_device_L.GetPressDown(SteamVR_Controller.ButtonMask.ApplicationMenu) &&
             _device_R.GetPress(SteamVR_Controller.ButtonMask.ApplicationMenu)) ||
            (_device_R.GetPressDown(SteamVR_Controller.ButtonMask.ApplicationMenu) &&
             _device_L.GetPress(SteamVR_Controller.ButtonMask.ApplicationMenu)))
        {
            calibratingMode = true;
            return;
        }

        if (calibratingMode && leftHandController != null && rightHandController != null && leftHandGuide != null && rightHandGuide != null && trackingOffset != null)
        {
            if (_device_R.GetPressDown(SteamVR_Controller.ButtonMask.Trigger))
            {
                // 左手首→右手首の位置から首の位置を求める
                Vector3 guideNeckPos = Vector3.Lerp(leftHandGuide.transform.position, rightHandGuide.transform.position, 0.5f);
                Vector3 trackNeckPos = Vector3.Lerp(leftHandController.transform.position, rightHandController.transform.position, 0.5f);

                // 左手首→右手首のベクトル を求めて、トラッキングと空間の回転角を出す
                Vector3 guideVectorL2R = rightHandGuide.transform.position - leftHandGuide.transform.position;
                Vector3 trackVectorL2R = rightHandController.transform.position - leftHandController.transform.position;
                var     _rot           = Quaternion.FromToRotation(trackVectorL2R, guideVectorL2R);

                // transform
                trackingOffset.transform.position += guideNeckPos - _rot * trackNeckPos;
                trackingOffset.transform.rotation  = _rot * trackingOffset.transform.rotation;

                calibratingMode = false;
            }
        }
    }
Ejemplo n.º 17
0
    // Update is called once per frame
    void FixedUpdate()
    {
        device = SteamVR_Controller.Input((int)trackedObj.index);
        if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger))
        {
            Debug.Log("You are holding 'Touch' on the Trigger");
        }
        if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger))
        {
            Debug.Log("Activated 'TouchDown' on the Trigger");
        }
        if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger))
        {
            Debug.Log("Activated 'TouchUp' on the Trigger");
        }

        if (device.GetPress(SteamVR_Controller.ButtonMask.Trigger))
        {
            Debug.Log("You are holding 'GetPress' on the Trigger");
        }
        if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger))
        {
            Debug.Log("Activated 'PressDown' on the Trigger");
        }
        if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger))
        {
            Debug.Log("Activated 'PressUp' on the Trigger");
        }

        if (device.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad))
        {
            device.TriggerHapticPulse(1000);
            GameObject.Instantiate(prefabSphere);
            //sphere.transform.position = new Vector3(0, 0, 0);
            //sphere.GetComponent<Rigidbody>().velocity = Vector3.zero;
            //sphere.GetComponent<Rigidbody>().angularVelocity = Vector3.zero;
        }
    }
Ejemplo n.º 18
0
 protected void CheckInput()
 {
     IsPressing = false;
     if (LaserVisible && _Target && !IsResizing)
     {
         if (Device.GetPressDown(EVRButtonId.k_EButton_Axis1))
         {
             IsPressing = true;
             VR.Input.Mouse.LeftButtonDown();
             mouseDownPosition = new Vector2?(Vector2.Scale(new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y), _ScaleVector));
         }
         if (Device.GetPress(EVRButtonId.k_EButton_Axis1))
         {
             IsPressing = true;
         }
         if (Device.GetPressUp(EVRButtonId.k_EButton_Axis1))
         {
             IsPressing = true;
             VR.Input.Mouse.LeftButtonUp();
             mouseDownPosition = null;
         }
     }
 }
Ejemplo n.º 19
0
    private ControllerState controllerEvents()
    {
#if SteamVR_Legacy
        if (controller.GetPress(SteamVR_Controller.ButtonMask.Touchpad))
        {
            return(ControllerState.TOUCHPAD_PRESS);
        }
        if (controller.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad))
        {
            return(ControllerState.TOUCHPAD_DOWN);
        }
#elif SteamVR_2
        if (m_touchpad.GetState(trackedObj.inputSource))
        {
            return(ControllerState.TOUCHPAD_PRESS);
        }
        if (m_touchpad.GetStateDown(trackedObj.inputSource))
        {
            return(ControllerState.TOUCHPAD_DOWN);
        }
#endif
        return(ControllerState.NONE);
    }
Ejemplo n.º 20
0
    void UpdateButtonState()
    {
        bool currentState = false;

        SteamVR_Controller.Device device = SteamVR_Controller.Input((int)GetComponent <SteamVR_TrackedObject>().index);
        currentState = device.GetPress(EVRButtonId.k_EButton_SteamVR_Trigger);

        //if (m_device == Device.left)
        //{
        //  currentState = SteamVRManager.m_deviceLeft.GetPress(EVRButtonId.k_EButton_SteamVR_Trigger);
        //}
        //else
        //{
        //  currentState = SteamVRManager.m_deviceRight.GetPress(EVRButtonId.k_EButton_SteamVR_Trigger);
        //}

        if (currentState != m_isButtonDown)
        {
            // state
            m_isButtonDown = currentState;
            Test();
        }
    }
Ejemplo n.º 21
0
    void Update()
    {
        //Test to see if the button is pressed down on the left controller
        if (leftDevice.GetPress(SteamVR_Controller.ButtonMask.Grip))
        {
            //get the x and the y position of the molecule
            int xVal = molecule.transform.position.x;
            int yVal = molecule.transform.position.y;

            //IF the left grip button is pressed scale the molecule down one
            molecule.transform.localScale += new Vector3(xVal, -1, yVal);
        }
        //Test to see if the button is pressed down on the right controller
        if (rightDevice.GetPress(SteamVR_Controller.ButtonMask.Grip))
        {
            //get the x and the y position of the molecule
            int xVal = molecule.transform.position.x;
            int yVal = molecule.transform.position.y;

            //IF the right grip button is pressed scale the molecule up one
            molecule.transform.localScale += new Vector3(xVal, 1, yVal);
        }
    }
Ejemplo n.º 22
0
    private void OnTriggerStay(Collider collider)
    {
        pickup = collider.gameObject;
        if (device.GetPress(SteamVR_Controller.ButtonMask.Trigger) && pickup != null)
        {
            pickup.transform.parent = this.transform;
            pickup.GetComponent <Rigidbody>().isKinematic = true;
        }
        if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger) && pickup != null)
        {
            if (!onLeg)
            {
                pickup.transform.parent = null;
                pickup.GetComponent <Rigidbody>().isKinematic = false;

                tossObject(collider.attachedRigidbody);
            }
            else
            {
                pickup.transform.parent = collider.gameObject.transform;
            }
        }
    }
Ejemplo n.º 23
0
    // Update is called once per frame
    void Update()
    {
        SteamVR_Controller.Device device = SteamVR_Controller.Input((int)trackObj.index);
        if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger))
        {
            //GameObject fireObj = Instantiate(fire, transform.position, Quaternion.identity) as GameObject;
            target.position = transform.position + new Vector3(0.0f, 0.07f, 0.0f);
            //ps.velocityOverLifetime = device.velocity;
        }

        Vector2 pos = device.GetAxis();

        if (device.GetPress(SteamVR_Controller.ButtonMask.Touchpad))
        {
            ps.startColor += new Color(-pos.x / 500.0f, 0, pos.x / 500.0f, 0);
            if (ps.startColor[2] < 0.0f)
            {
                ps.startColor = new Color(ps.startColor[0], ps.startColor[1], 0.0f, ps.startColor[3]);
            }
            else if (ps.startColor[2] > 1.0f)
            {
                ps.startColor = new Color(ps.startColor[0], ps.startColor[1], 1.0f, ps.startColor[3]);
            }
            if (ps.startColor[0] < 0.0f)
            {
                ps.startColor = new Color(0.0f, ps.startColor[1], ps.startColor[2], ps.startColor[3]);
            }
            else if (ps.startColor[0] > 1.0f)
            {
                ps.startColor = new Color(1.0f, ps.startColor[1], ps.startColor[2], ps.startColor[3]);
            }

            print(ps.startColor);
            ps.startLifetime += pos.y / 20.0f;
            //print (pos.y);
        }
    }
Ejemplo n.º 24
0
    void UpdateFreeMove()
    {
        // get joystick left position
        SteamVR_Controller.Device device = SteamVR_Controller.Input((int)leftController.GetComponent <SteamVR_TrackedController>().controllerIndex);
        Vector2 sticks = new Vector2();

        if (UnityEngine.XR.XRDevice.model == "Vive MV")
        {
            bool    pressTouchpad = device.GetPress(EVRButtonId.k_EButton_SteamVR_Touchpad);
            Vector2 touch         = device.GetAxis(EVRButtonId.k_EButton_SteamVR_Touchpad);
            sticks = pressTouchpad ? touch : new Vector2(0, 0); // to emulate joystick press hard the touchpad
        }

        else if (UnityEngine.XR.XRDevice.model == "Lenovo Explorer")
        {
            sticks = device.GetAxis(EVRButtonId.k_EButton_Axis2);
        }
        else if (UnityEngine.XR.XRDevice.model == "Oculus Rift CV1")
        {
            sticks = device.GetAxis(EVRButtonId.k_EButton_SteamVR_Touchpad);
        }

        //print(sticks);

        // get hmd y orientation
        float angle = hmd.transform.rotation.eulerAngles.y - player.transform.rotation.eulerAngles.y;

        int speedReducer = 40;

        float x = sticks[0] / speedReducer;
        float y = 0;
        float z = sticks[1] / speedReducer;

        Vector3 vector = new Vector3(x, y, z);

        player.transform.Translate(Quaternion.AngleAxis(angle, Vector3.up) * vector, Space.Self);
    }
Ejemplo n.º 25
0
    // Update is called once per frame
    void Update()
    {
        device = SteamVR_Controller.Input((int)trackedObject.index);

        if (device.GetPress(SteamVR_Controller.ButtonMask.Touchpad))
        {
            laser.gameObject.SetActive(true);
            teleportAimerObject.SetActive(true);

            setLaserStart(gameObject.transform.position);
            RaycastHit hit;
            if (Physics.Raycast(transform.position, transform.forward, out hit, 15, laserMask))
            {
                teleportLocation = hit.point;
            }
            else
            {
                teleportLocation = transform.position + 15 * transform.forward;
                RaycastHit groundRay;
                if (Physics.Raycast(teleportLocation, -Vector3.up, out groundRay, 17, laserMask))
                {
                    teleportLocation.y = groundRay.point.y;
                }
            }
            setLaserEnd(teleportLocation);
            // aimer
            teleportAimerObject.transform.position = teleportLocation + yNudgeVector;
        }

        if (device.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad))
        {
            laser.gameObject.SetActive(false);
            teleportAimerObject.SetActive(false);
            player.transform.position = teleportLocation;
        }
    }
Ejemplo n.º 26
0
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.F))
     {
         controlType = (controlType == FingerControlType.TypeA) ? FingerControlType.TypeB : FingerControlType.TypeA;
     }
     if (_animator != null)
     {
         if (_device_L != null)
         {
             if (_device_L.GetPress(SteamVR_Controller.ButtonMask.Grip))
             {
                 _animator.SetInteger("LeftHandPose", updateHandPose(_device_L, Hand.left));
             }
         }
         if (_device_R != null)
         {
             if (_device_R.GetPress(SteamVR_Controller.ButtonMask.Grip))
             {
                 _animator.SetInteger("RightHandPose", updateHandPose(_device_R, Hand.right));
             }
         }
     }
 }
Ejemplo n.º 27
0
    void FixedUpdate()
    {
        device = SteamVR_Controller.Input((int)trackedObj.index);
        if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger))
        {
            //Debug.Log("You are holding down the trigger222.");
        }
        if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger))
        {
            //Debug.Log("You have activated TouchDown on trigger.");
        }
        if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger))
        {
            //Debug.Log("You have activated TouchUp on trigger.");
        }

        if (device.GetPress(SteamVR_Controller.ButtonMask.Trigger))
        {
            //Debug.Log("You are holding Press on the trigger.");
        }
        if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger))
        {
            //Debug.Log("You have activated PressDown on trigger.");
        }
        if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger))
        {
            //Debug.Log("You have activated PressUp on trigger.");
        }
        if (device.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad))
        {
            //!!!!!! reset ball position
            sphere.transform.position = Vector3.zero;
            sphere.GetComponent <Rigidbody>().velocity        = Vector3.zero;
            sphere.GetComponent <Rigidbody>().angularVelocity = Vector3.zero;
        }
    }
Ejemplo n.º 28
0
    private int updateHandPose(SteamVR_Controller.Device device, Hand hand)
    {
        var pos = device.GetAxis();

        if (pos.magnitude < 0.5f)
        {
            return(0);
        }
        else
        {
            Vector2 zero;
            if (hand == Hand.left)
            {
                zero = new Vector2(1, 0);
            }
            else
            {
                zero = new Vector2(-1, 0);
            }
            var deg = Vector2.Angle(zero, pos);
            if (pos.y < 0)
            {
                deg = 360 - deg;
            }
            Debug.Log(deg);

            if (controlType == FingerControlType.TypeA)
            {
                return(getPoseByDegree(deg));
            }
            else
            {
                return(getPoseByDegreeWithShift(deg, device.GetPress(SteamVR_Controller.ButtonMask.Trigger)));
            }
        }
    }
Ejemplo n.º 29
0
 void FixedUpdate()
 {
     device = SteamVR_Controller.Input((int)trackedObj.index);
     if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger))
     {
         Debug.Log("You are holding 'Touch' on the Trigger");
     }
     if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger))
     {
         Debug.Log("You activated 'TouchDown' on the Trigger");
     }
     if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger))
     {
         Debug.Log("You activated 'TouchUp' on the Trigger");
     }
     if (device.GetPress(SteamVR_Controller.ButtonMask.Trigger))
     {
         Debug.Log("You are holding 'Press' on the Trigger");
     }
     if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger))
     {
         Debug.Log("You activated 'PressDown' on the Trigger");
     }
     if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger))
     {
         Debug.Log("You activated 'PressUp' on the Trigger");
     }
     if (device.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad))
     {
         Debug.Log("You activated 'PressUp' on the Touchpad");
         sphere.transform.position = new Vector3(0, 0, 0);
         sphere.GetComponent <Rigidbody>().velocity        = Vector3.zero;
         sphere.GetComponent <Rigidbody>().angularVelocity = Vector3.zero;
         // Vector3.zero is the same as new Vector3(0,0,0)
     }
 }
Ejemplo n.º 30
0
    // Update is called once per physics step (consistant)
    void FixedUpdate()
    {
        device = SteamVR_Controller.Input((int)trackedObj.index);
        if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger))
        {
            Debug.Log("you are Holding 'Touch' on the trigger");
        }
        if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger))
        {
            Debug.Log("you have acitvated touch down on the trigger");
        }
        if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger))
        {
            Debug.Log("you have acitvated touch up on the trigger");
        }

        if (device.GetPress(SteamVR_Controller.ButtonMask.Trigger))
        {
            Debug.Log("you are Holding 'Press' on the trigger");
        }
        if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger))
        {
            Debug.Log("you have acitvated Press down on the trigger");
        }
        if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger))
        {
            Debug.Log("you have acitvated Press up on the trigger");
        }

        if (device.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad))  //reset sphere position
        {
            Debug.Log("you have acitvated Press up on the Touchpad");
            sphere.transform.position = new Vector3(0, 1, 0);          //reset position
            sphere.GetComponent <Rigidbody>().velocity = Vector3.zero; // Vector3.zero short hand for: new Vector3(0,0,0) // reset veocoity so it stays still
        }
    }
    // Update is called once per frame
    void Update()
    {
        SteamVR_Controller.Device device = SteamVR_Controller.Input((int)trackedObjRight.index);
        Vector3 forwardleft  = trackedObjLeft.transform.forward;
        Vector3 forwardright = trackedObjRight.transform.forward;

        start = trackedObjLeft;
        end   = trackedObjRight;

        int last_choice = 0;

        if (device.GetPress(SteamVR_Controller.ButtonMask.Touchpad))
        {
            Vector2 touchpad = device.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0);
            if (touchpad.y > 0.7)
            {
                for (float i = 0; i < 2000; i += 1)
                {
                    Debug.Log('k');
                    device.TriggerHapticPulse(3999);
                }
                Debug.Log("UP");
                choice = 0;
            }
            else if (touchpad.y < -0.7)
            {
                for (float i = 0; i < 2000; i += 1)
                {
                    Debug.Log('k');
                    device.TriggerHapticPulse(3999);
                }
                last_choice = choice;
                choice      = 2;
                Debug.Log("Down");
            }
            else if (touchpad.x > 0.7)
            {
                for (float i = 0; i < 2000; i += 1)
                {
                    Debug.Log('k');
                    device.TriggerHapticPulse(3999);
                }
                Debug.Log("right");
                choice = 1;
            }
            else if (touchpad.x < -0.7)
            {
                for (float i = 0; i < 2000; i += 1)
                {
                    Debug.Log('k');
                    device.TriggerHapticPulse(3999);
                }
                Debug.Log("Left");
                choice = 3;
            }
        }

        // set points of Hermite curve
        Vector3 p0 = start.transform.position;
        Vector3 p1 = end.transform.position;
        //Vector3 m0 = startTangentPoint.transform.position - start.transform.position;
        //Vector3 m1 = endTangentPoint.transform.position - end.transform.position;

        // checking tangent
        Vector3 m0 = forwardleft;
        Vector3 m1 = forwardright;

        float   t;
        Vector3 position;

        switch (choice)
        {
        case 0:
            debugline.enabled = true;
            // for closed loop
            //debugline.loop = true;

            //debugline.startColor = colorstart;
            //debugline.endColor = colorend;
            //debugline.startWidth = width;
            //debugline.endWidth = width;
            //debugline.renderer.material.SetColor("_TintColor", new Color(1, 1, 1, 0.5f));
            if (numberOfPoints > 0)
            {
                // normal line comment me
                debugline.positionCount = numberOfPoints;
            }



            for (int i = 0; i < numberOfPoints; i++)
            {
                t        = i / (numberOfPoints - 1.0f);
                position = (2.0f * t * t * t - 3.0f * t * t + 1.0f) * p0
                           + (t * t * t - 2.0f * t * t + t) * m0
                           + (-2.0f * t * t * t + 3.0f * t * t) * p1
                           + (t * t * t - t * t) * m1;

                // mesh line comment me
                //line.AddPoint(position);

                // normal line comment me
                debugline.SetPosition(i, position);
            }

            break;

        case 1:
            debugline.enabled = true;
            // for closed loop
            debugline.loop = true;

            //debugline.startColor = colorstart;
            //debugline.endColor = colorend;
            //debugline.startWidth = width;
            //debugline.endWidth = width;
            //debugline.renderer.material.SetColor("_TintColor", new Color(1, 1, 1, 0.5f));
            if (numberOfPoints > 0)
            {
                // normal line comment me
                debugline.positionCount = numberOfPoints;
            }



            for (int i = 0; i < numberOfPoints; i++)
            {
                t        = i / (numberOfPoints - 1.0f);
                position = (2.0f * t * t * t - 3.0f * t * t + 1.0f) * p0
                           + (t * t * t - 2.0f * t * t + t) * m0
                           + (-2.0f * t * t * t + 3.0f * t * t) * p1
                           + (t * t * t - t * t) * m1;

                // mesh line comment me
                //line.AddPoint(position);

                // normal line comment me
                debugline.SetPosition(i, position);
            }
            break;

        case 2:
            materialnum = (materialnum + 1) % 3;
            choice      = last_choice;
            Debug.Log(materialnum);
            break;

        case 3:
            debugline.enabled = false;
            break;
        }

        if (choice == 3)
        {
            if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger))
            {
                GameObject line = new GameObject();
                currLine = line.AddComponent <LineRenderer> ();
                currLine.SetWidth(0.1f, 0.1f);
                numClicks = 0;
            }
        }

        if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger))
        {
            switch (choice)
            {
            case 0:

                GameObject newline = new GameObject();


                line = newline.AddComponent <LineRenderer> ();
                switch (materialnum)
                {
                case 0:
                    line.material = a;
                    break;

                case 1:
                    line.material = b;
                    break;

                case 2:
                    line.material = c;
                    break;
                }
                // for closed curve
                //line.loop = true;
                //start = trackedObjLeft;
                //end = trackedObjRight;

                // mesh line comment me
                //line.setWidth(0.1f);

                // normal line comment me
                line.startColor = colorstart;
                line.endColor   = colorend;
                line.startWidth = width;
                line.endWidth   = width;

                if (numberOfPoints > 0)
                {
                    // normal line comment me
                    line.positionCount = numberOfPoints;
                }

                // set points of Hermite curve
                p0 = start.transform.position;
                p1 = end.transform.position;

                // checking tangent
                m0 = forwardleft;
                m1 = forwardright;



                for (int i = 0; i < numberOfPoints; i++)
                {
                    t        = i / (numberOfPoints - 1.0f);
                    position = (2.0f * t * t * t - 3.0f * t * t + 1.0f) * p0
                               + (t * t * t - 2.0f * t * t + t) * m0
                               + (-2.0f * t * t * t + 3.0f * t * t) * p1
                               + (t * t * t - t * t) * m1;

                    // normal line comment me
                    line.SetPosition(i, position);
                }
                break;

            case 1:
                GameObject newlinex = new GameObject();


                line = newlinex.AddComponent <LineRenderer> ();
                switch (materialnum)
                {
                case 0:
                    line.material = a;
                    break;

                case 1:
                    line.material = b;
                    break;

                case 2:
                    line.material = c;
                    break;
                }
                // for closed curve
                line.loop = true;
                //start = trackedObjLeft;
                //end = trackedObjRight;

                // mesh line comment me
                //line.setWidth(0.1f);

                // normal line comment me
                line.startColor = colorstart;
                line.endColor   = colorend;
                line.startWidth = width;
                line.endWidth   = width;

                if (numberOfPoints > 0)
                {
                    // normal line comment me
                    line.positionCount = numberOfPoints;
                }

                // set points of Hermite curve
                p0 = start.transform.position;
                p1 = end.transform.position;

                // checking tangent
                m0 = forwardleft;
                m1 = forwardright;



                for (int i = 0; i < numberOfPoints; i++)
                {
                    t        = i / (numberOfPoints - 1.0f);
                    position = (2.0f * t * t * t - 3.0f * t * t + 1.0f) * p0
                               + (t * t * t - 2.0f * t * t + t) * m0
                               + (-2.0f * t * t * t + 3.0f * t * t) * p1
                               + (t * t * t - t * t) * m1;

                    // normal line comment me
                    line.SetPosition(i, position);
                }
                break;

            case 2:
                break;

            case 3:
                switch (materialnum)
                {
                case 1:
                    currLine.material = a;
                    break;

                case 2:
                    currLine.material = b;
                    break;

                case 3:
                    currLine.material = c;
                    break;
                }
                currLine.SetVertexCount(numClicks + 1);
                Vector3 pos = trackedObjRight.transform.position;
                currLine.SetPosition(numClicks, pos);
                numClicks++;
                break;
            }
        }
    }
Ejemplo n.º 32
0
    // Use this for initialization
    void Start()
    {
        GameObject controller = this.transform.parent.gameObject;
        SteamVR_TrackedObject trackedObject = controller.GetComponent<SteamVR_TrackedObject>();
        device = SteamVR_Controller.Input((int)trackedObject.index);

        this.UpdateAsObservable()
            .Subscribe(v => {
                var currentPosition = this.transform.position;
                speed = (currentPosition - oldPosition) / Time.deltaTime;
                oldPosition = currentPosition;

                var currenRotaion = this.transform.forward;
                angularVelocity = Quaternion.FromToRotation(oldRotation,currenRotaion);
                oldRotation = currenRotaion;
            });

        /*
        this.OnCollisionEnterAsObservable()
            .Where(v => speed.magnitude > 0.5f)
            .Subscribe(v =>
                {
                    v.gameObject.GetComponent<Rigidbody>().AddForce(speed / 0.5f, ForceMode.Impulse);
                }
            );*/

        //つかむ動作をしたとき
        this.OnTriggerStayAsObservable()
            .Where(v => v.GetComponent<GrabbableObject>() != null)
            .Where(v => grabbingObject == null)
            .Where(v => device.GetPress(SteamVR_Controller.ButtonMask.Trigger))
            .Select(v => v.gameObject)
            .Where(v => v.GetComponent<IGrabbable>().Grabbed == false)
            .Subscribe(v => GrabAction(v));

        //手を放したとき
        this.UpdateAsObservable()
            .Where(_ => device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger))
            .Where(_ => grabbingObject != null)
            .Where(_ => grabbingObject.GetComponent<IGrabbable>() != null)
            .Subscribe(_ => UnGrabAction(grabbingObject,true));

        //道具をつかんだとき
        this.OnTriggerStayAsObservable()
            .Where(v => v.GetComponent<IGrippable>() != null)
            .Where(v => grabbingObject == null)
            .Where(v => device.GetPress(SteamVR_Controller.ButtonMask.Trigger))
            .Select(v => v.gameObject)
            .Where(v => v.GetComponent<IGrippable>().Grabbed == false)
            .Subscribe(v => GripAction(v));

        //道具を放したとき
        this.UpdateAsObservable()
            .Where(_ => device.GetPressDown(SteamVR_Controller.ButtonMask.Grip))
            .Where(_ => grabbingObject != null)
            .Where(_ => grabbingObject.GetComponent<IGrippable>() != null)
            .Select(_ => grabbingObject)
            .Subscribe(v => UnGripAction(v,true));

        //道具を切り替えたとき
        this.OnTriggerStayAsObservable()
            .Where(v => v.GetComponent<IGrippable>() != null)
            .Where(v => grabbingObject == null)
            .Where(v => device.GetPress(SteamVR_Controller.ButtonMask.Trigger))
            .Select(v => v.gameObject)
            .Where(v => v.GetComponent<IGrippable>().Grabbed == true)
            .Subscribe(v => SwichGripAction(v,v.transform.parent.gameObject));

        //道具のトリガーを引いたとき
        this.UpdateAsObservable()
            .Where(_ => grabbingObject != null)
            .Where(_ => grabbingObject.GetComponent<IShootable>() != null)
            .Where(_ => Mathf.Abs(device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger).x) > 0.0f)
            .Select(_ => grabbingObject)
            .Subscribe(v =>
                {
                    grabbingObject.GetComponent<IShootable>().Shot(device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger).x);
                }
            );
    }
Ejemplo n.º 33
0
    void Update()
    {
        if (!isServer || !isLocalPlayer)
            return;
        float xLeftInput = 0;
        float zLeftInput = 0;
        float xRightInput = 0;
        float zRightInput = 0;
        bool leftActive = true;
        // Setting up the Vive controllers
        bool leftGripPressed = false;
        try {
            leftController = SteamVR_Controller.Input((int)leftTrackedObject.index);
            leftGripPressed = leftController.GetPressDown(Valve.VR.EVRButtonId.k_EButton_Grip);
            if (leftController.GetPress(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad)) {
                // Get the left inputs
                xLeftInput = leftController.GetAxis().x;
                zLeftInput = leftController.GetAxis ().y;
            }

        } catch (System.Exception) {
            //Just roll with it
            leftActive = false;
        }
        bool rightGripPressed = false;
        try {
            rightController = SteamVR_Controller.Input((int)rightTrackedObject.index);
            rightGripPressed = rightController.GetPressDown(Valve.VR.EVRButtonId.k_EButton_Grip);
            if (rightController.GetPress(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad)) {
                // Get the left inputs
                xRightInput = rightController.GetAxis().x;
                zRightInput = rightController.GetAxis ().y;
            }
        } catch (System.Exception) {
            if (!leftActive) {
                Debug.Log ("No controllers Connected");
            }
        }

        //Calculate movement velocity  as a 3D vector
        // Strafe
        float _xMov = xLeftInput + xRightInput;
        // Forward
        float _zMov = zLeftInput + zRightInput;

        Vector3 _movHorizontal;
        Vector3 _movVertical;

        // Move relative to the first person camera
        if (isServer) {
            _movHorizontal = firstPersonCam.transform.right * _xMov;
            _movVertical = firstPersonCam.transform.forward * _zMov;
        }

        finalSpeed = speed;

        // Final movement vector
        Vector3 _velocity = (_movHorizontal + _movVertical).normalized * finalSpeed;
        bool gripsPressed = (leftGripPressed || rightGripPressed);
        //if the player is jumping
        if (gripsPressed && !isFalling)
        {
            isFalling = true;
            playerAudio.PlayOneShot(jumpSound, 0.6f);
            motor.Jump();
        }

        // Apply movement
        motor.Move(_velocity);

        // Calculate rotation as a 3D vector (turning around)
        float _yRot = Input.GetAxisRaw("Mouse X");

        Vector3 _rotation = new Vector3(0f, _yRot, 0f) * lookSensitivity;

        // Apply rotation
        motor.Rotate(_rotation);

        // Calculate camera rotation as a 3D vector (turning around)
        float _xRot = Input.GetAxisRaw("Mouse Y");

        // REVERT: Change yRot to 0f
        Vector3 _cameraRotation = new Vector3(_xRot, _yRot, 0f) * lookSensitivity;

        // Apply rotation
        motor.RotateCamera(_cameraRotation);
    }