void Update() { if (_trackedObject.index == SteamVR_TrackedObject.EIndex.None) { // No device // TODO: Cancel events that were in progress? return; } SteamVR_Controller.Device device = SteamVR_Controller.Input((int)_trackedObject.index); triggerPosition = device.GetAxis(EVRButtonId.k_EButton_SteamVR_Trigger).x; // Trigger bool hairTriggerBegan = device.GetHairTriggerDown(); bool hairTriggerActive = device.GetHairTrigger(); bool hairTriggerEnded = device.GetHairTriggerUp(); if (hairTriggerBegan) { DelegateFireTriggerBegan(); } if (hairTriggerActive) { DelegateFireTriggerActive(); } if (hairTriggerEnded) { DelegateFireTriggerEnded(); } // Grip bool gripBegan = device.GetPressDown(EVRButtonId.k_EButton_Grip); bool gripActive = device.GetPress(EVRButtonId.k_EButton_Grip); bool gripEnded = device.GetPressUp(EVRButtonId.k_EButton_Grip); if (gripBegan) { DelegateFireGripBegan(); } if (gripActive) { DelegateFireGripActive(); } if (gripEnded) { DelegateFireGripEnded(); } }
private void checkTriggers(List <SteamVR_TrackedObject> vrControllers) { this.shotTriggered = false; IEnumerator controllersEnumerator = vrControllers.GetEnumerator(); while (controllersEnumerator.MoveNext()) { SteamVR_TrackedObject vrtrackedObj = (SteamVR_TrackedObject)controllersEnumerator.Current; SteamVR_Controller.Device vrController = SteamVR_Controller.Input((int)vrtrackedObj.index); if (vrController.GetHairTrigger()) { this.shotTriggered = true; } } }
/// <summary> /// Get the HTC Vive controller hair trigger state. /// </summary> /// <returns><c>true</c>, if hair trigger was gotten, <c>false</c> otherwise.</returns> public bool GetHairTrigger() { if (VRReplay.Instance.Mode == VRReplay.ModeType.Playback) { return(VRReplay.Instance.QueryVRInputBool(index, "HairTrigger", VRDeviceInputType.HairTrigger)); } bool state = device.GetHairTrigger(); if (VRReplay.Instance.Mode == VRReplay.ModeType.Record) { if (state) { VRReplay.Instance.RecordVRInputBool(index, "HairTrigger", VRDeviceInputType.HairTrigger, state); } } return(state); }
// Update is called once per frame void Update() { float deltaX = Input.GetAxis("Horizontal") * speed; float deltaZ = Input.GetAxis("Vertical") * speed; Vector3 movement = new Vector3(deltaX, 0, deltaZ); movement = Vector3.ClampMagnitude(movement, speed); movement *= Time.deltaTime; movement = transform.TransformDirection(movement); if (controller.GetHairTrigger()) { StartCoroutine(DoPulse(controller)); } }
private void checkLeft() { if (steamDevice.GetHairTrigger() && transform.GetChild(2).gameObject.GetComponent <ShieldController>().shieldEnergy > 0) { //Debug.Log(gameObject.name + " Trigger Press"); //currentCor = StartCoroutine(RumbleControllerRoutine(1000)); CmdShieldOn(); transform.GetChild(2).gameObject.GetComponent <ShieldController>().ShieldOn(); if (transform.GetChild(2).gameObject.GetComponent <ShieldController>().isShieldOpen == false) { RumbleTime(1000, 0.01f); } } else { //StopCoroutine(currentCor); CmdShieldOff(); //transform.GetChild(2).gameObject.GetComponent<ShieldController>().ShieldOff(); } }
/// <summary> /// Get the Steam VR hair trigger state. /// </summary> /// <returns>Trigger state.</returns> public bool GetHairTrigger() { if (CurrentInputMode == RVInputMode.Playback) { SteamVRInputInfo inputInfo = CurrentRecording.HasCurrentFrame() ? CurrentRecording.CurrentFrame.GetInputInfo(DeviceIndex, "HairTrigger") : null; return(inputInfo == null ? false : inputInfo.HairTriggerState); } bool stateValue = m_DeviceImpl.GetHairTrigger(); if (CurrentInputMode == RVInputMode.Record) { SteamVRInputInfo inputInfo = CurrentRecording.CurrentFrame.GetInputInfo(DeviceIndex, "HairTrigger"); if (inputInfo == null) { inputInfo = new SteamVRInputInfo(); } inputInfo.HairTriggerState = stateValue; CurrentRecording.CurrentFrame.AddInputInfo(DeviceIndex, "HairTrigger", inputInfo); } return(stateValue); }
void LateUpdate() { if (Input.GetKeyDown(KeyCode.P)) { SceneManager.LoadScene(0); } if (Input.GetKey(KeyCode.Escape)) { Application.Quit(); } controller1 = SteamVR_Controller.Input(SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Leftmost)); controller2 = SteamVR_Controller.Input(SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Rightmost)); Debug.DrawRay(trackedControllers[1].transform.position, trackedControllers[1].transform.up * -100 + new Vector3(0, -1, 0)); Vector2 q = controller2.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad); Vector2 cont2_axis = controller1.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad); bool comfort_zoom = false; string[] names = UnityEngine.Input.GetJoystickNames(); // make sure both controllers are active if (controller1 != null && controller2 != null) { UpdateDocuments(); distance = Vector3.Distance(trackedControllers[0].transform.localPosition, trackedControllers[1].transform.localPosition); // velocity of the controllers controller1_velocity = controller1.velocity; controller2_velocity = controller2.velocity; Vector3 v_rot = controller2.angularVelocity; // Comfort zooming variables float z_dist0 = Vector3.Distance(Camera.main.transform.position, trackedControllers[0].transform.position) * 2; float z_dist1 = Vector3.Distance(Camera.main.transform.position, trackedControllers[1].transform.position) * 2; // Archery variables controller_vector = trackedControllers[1].transform.position - trackedControllers[0].transform.position; direction = Vector3.Distance(trackedControllers[0].transform.localPosition, trackedControllers[1].transform.localPosition) * Vector3.Dot(controller_vector.normalized, trackedControllers[0].transform.forward); left_right = Vector3.Distance(trackedControllers[0].transform.localPosition, trackedControllers[1].transform.localPosition) * Vector3.Dot(controller_vector.normalized, trackedControllers[0].transform.right); if (controller1.GetHairTrigger() && controller2.GetHairTrigger() && lasers[0].studyState == 0 && lasers[1].studyState == 0) { zoomGesture = true; } /* * if (controller1.GetHairTrigger() && controller2.GetHairTrigger() && lasers[0].node != null && lasers[1].node != null) { * dotted_line.SetPosition(0, lasers[0].node.transform.position); * dotted_line.SetPosition(1, lasers[1].node.transform.position); * dotted_line.transform.GetChild(0).transform.position = new Vector3((lasers[0].node.transform.position.x + lasers[1].node.transform.position.x) / 2, * (lasers[0].node.transform.position.y + lasers[1].node.transform.position.y) / 2, * (lasers[0].node.transform.position.z + lasers[1].node.transform.position.z) / 2); * dotted_line.enabled = true; * } else { * //dotted_line.enabled = false; * } */ // Archery Zoom Check if (controller1.GetHairTrigger() == false && controller2.GetHairTrigger() == false) { zoomGesture = false; } if (controller2.GetPress(SteamVR_Controller.ButtonMask.Grip) && userStudyRunning == false) { rotateGraph_wController = true; } else { rotateGraph_wController = false; } if (zoomGesture) { if (leftHanded == false) { render_line.SetPosition(0, trackedControllers[0].transform.position); render_line.SetPosition(1, trackedControllers[1].transform.position); arrow_object.SetPosition(0, trackedControllers[0].transform.position); arrow_object.SetPosition(1, trackedControllers[1].transform.position); render_line.enabled = true; arrow_object.enabled = true; if (controller_vector.y < -0.4f) { Camera.main.transform.parent.position += Camera.main.transform.parent.up * -0.003f * (direction + 1); } if (controller_vector.y > 0.4f) { Camera.main.transform.parent.position += Camera.main.transform.parent.up * 0.003f * (direction + 1); } Camera.main.transform.parent.position += controller_vector * 0.08f * (direction + 1); } else { render_line.SetPosition(0, trackedControllers[1].transform.position); render_line.SetPosition(1, trackedControllers[0].transform.position); arrow_object.SetPosition(0, trackedControllers[1].transform.position); arrow_object.SetPosition(1, trackedControllers[0].transform.position); render_line.enabled = true; arrow_object.enabled = true; print(controller_vector); if (controller_vector.y < -0.4f) { Camera.main.transform.parent.position -= Camera.main.transform.parent.up * -0.003f * (direction + 1); } if (controller_vector.y > 0.4f) { Camera.main.transform.parent.position -= Camera.main.transform.parent.up * 0.003f * (direction + 1); } Camera.main.transform.parent.position -= controller_vector * 0.08f * (direction + 1); } } else { render_line.enabled = false; arrow_object.enabled = false; } if (rotateGraph_wController && userStudyRunning == false) { Quaternion rotation = (graph.transform.rotation * (trackedControllers[1].transform.rotation)); //graph.transform.rotation = trackedControllers[0].transform.rotation; graph.transform.rotation *= Quaternion.Euler(v_rot.x, v_rot.y, v_rot.z); //graph.transform.position = trackedControllers[0].transform.position; } if (q.x > 0.3f) { // graph.transform.Rotate(0, 0.5f, 0); } if (q.x < -0.3f) { // graph.transform.Rotate(0, -0.5f, 0); } } }
/// <summary> /// Check and assign tools accordingly. /// </summary> /// <returns></returns> IEnumerator checkForControllersCoroutine() { // Check whether the controllers are valid or not and assign the input components. while (!ControllerForGUI.isValid) { yield return(null); } m_SteamVRDeviceLeft = SteamVR_Controller.Input((int)ControllerForGUI.index); while (!ControllerForTools.isValid) { yield return(null); } m_SteamVRDeviceRight = SteamVR_Controller.Input((int)ControllerForTools.index); List <ControllerTool> toolList = new List <ControllerTool>(); bool leftControllerSet = false; bool rightcontrollerSet = false; // Wait until both controllers are set while (!m_ControllerGUISet || !m_ControllerToolsSet) { // let the controllers vibrate on input if (m_SteamVRDeviceLeft.GetHairTrigger()) { m_SteamVRDeviceLeft.TriggerHapticPulse(500); LeftBar.gameObject.SetActive(true); LeftBar.transform.localScale = new Vector3(1, m_SteamVRDeviceLeft.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis1).x, 1); } else { LeftBar.gameObject.SetActive(false); } if (m_SteamVRDeviceRight.GetHairTrigger()) { m_SteamVRDeviceRight.TriggerHapticPulse(500); RightBar.gameObject.SetActive(true); RightBar.transform.localScale = new Vector3(1, m_SteamVRDeviceRight.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis1).x, 1); } else { RightBar.gameObject.SetActive(false); } // Check for left controller if (m_SteamVRDeviceLeft.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis1).x > 0.99f && !leftControllerSet) { // if the left controller is not set yet if (!m_ControllerGUISet) { // then assign all tools from the left hand to the left controller foreach (ControllerTool t in LeftHandTools) { toolList.Add(Instantiate(t, ControllerForGUI.transform)); } m_ControllerGUISet = true; leftControllerSet = true; GUIText.gameObject.SetActive(false); ToolsText.gameObject.SetActive(true); } // otherwise assin all tools from the right hand to the left controller else { foreach (ControllerTool t in RightHandTools) { toolList.Add(Instantiate(t, ControllerForGUI.transform)); } m_ControllerToolsSet = true; leftControllerSet = true; InstructionCanvas.gameObject.SetActive(false); } } // Check for right controller if (m_SteamVRDeviceRight.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis1).x > 0.99f && !rightcontrollerSet) { // if the left controller is not set yet if (!m_ControllerGUISet) { // then assign all tools from the left hand to the right controller foreach (ControllerTool t in LeftHandTools) { toolList.Add(Instantiate(t, ControllerForTools.transform)); } m_ControllerGUISet = true; rightcontrollerSet = true; GUIText.gameObject.SetActive(false); ToolsText.gameObject.SetActive(true); } // otherwise assin all tools from the right hand to the right controller else { foreach (ControllerTool t in RightHandTools) { toolList.Add(Instantiate(t, ControllerForTools.transform)); } m_ControllerToolsSet = true; rightcontrollerSet = true; InstructionCanvas.gameObject.SetActive(false); } } if (leftControllerSet) { LeftBar.gameObject.SetActive(false); } if (rightcontrollerSet) { RightBar.gameObject.SetActive(false); } yield return(null); } InputManager.Instance.Initialize(toolList); }
// Update is called once per frame void FixedUpdate() { if (Global.mode == 3 && Global.isTips == 0) { if (deviceleft.GetHairTrigger()) { if (Global.handGripObj != null) { if (!Global.selectObjDict.Contains(Global.handGripObj)) { Global.selectObjDict.Add(Global.handGripObj); } foreach (GameObject g in Global.selectObjDict) { g.transform.parent = Global.handGripObj.transform; } if (device.GetHairTrigger()) { FixedJoint fixedjoint = handjoint.GetComponent <FixedJoint>(); fixedjoint.connectedBody = Global.handGripObj.GetComponent <Rigidbody>(); } if (device.GetHairTriggerUp()) { FixedJoint fixedjoint = handjoint.GetComponent <FixedJoint>(); fixedjoint.connectedBody = null; } if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad)) { float xx = device.GetState().rAxis0.x; float yy = device.GetState().rAxis0.y; if (xx < -0.5 && xx > -1 && yy < 0.5 && yy > -0.5) { Global.handGripObj.AddComponent <CombineMesh>(); Global.selectObjDict.Clear(); } } } else { foreach (GameObject g in Global.selectObjDict) { g.transform.parent = Global.sceneSet[Global.sceneSet.Count - 1].transform; } FixedJoint fixedjoint = handjoint.GetComponent <FixedJoint>(); fixedjoint.connectedBody = null; } foreach (GameObject g in Global.selectObjDict) { g.GetComponent <Renderer>().material.color = new Color(200, 255, 0); } } else { foreach (GameObject g in Global.selectObjDict) { g.GetComponent <Renderer>().material.color = new Color(255, 255, 255); } foreach (GameObject g in Global.selectObjDict) { g.transform.parent = Global.sceneSet[Global.sceneSet.Count - 1].transform; } Global.selectObjDict.Clear(); if (device.GetPress(SteamVR_Controller.ButtonMask.Trigger)) { if (Global.handGripObj != null) { FixedJoint fixedjoint = handjoint.GetComponent <FixedJoint>(); fixedjoint.connectedBody = Global.handGripObj.GetComponent <Rigidbody>(); } else if (Global.handGripObj == null) { FixedJoint fixedjoint = handjoint.GetComponent <FixedJoint>(); fixedjoint.connectedBody = null; } } if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { FixedJoint fixedjoint = handjoint.GetComponent <FixedJoint>(); fixedjoint.connectedBody = null; } if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad)) { float xx = device.GetState().rAxis0.x; float yy = device.GetState().rAxis0.y; // Debug.Log(xx+","+yy); if (xx < 1 && xx > 0.5 && yy < 0.5 && yy > -0.5) { if (Global.handGripObj != null) { GameObject copyobj = Copy(Global.handGripObj); FixedJoint fixedjoint = handjoint.GetComponent <FixedJoint>(); fixedjoint.connectedBody = copyobj.GetComponent <Rigidbody>(); } else if (Global.handGripObj == null) { FixedJoint fixedjoint = handjoint.GetComponent <FixedJoint>(); fixedjoint.connectedBody = null; } } else if (xx < -0.5 && xx > -1 && yy < 0.5 && yy > -0.5) { } if (xx < 0.5 && xx > -0.5 && yy < 1 && yy > 0.5) { SacleIncrease(Global.handGripObj); } if (xx < 0.5 && xx > -0.5 && yy < -0.5 && yy > -1) { SacleDecrease(Global.handGripObj); } } } } }
void Update() { if (cont != null) { if (heldItem != null)//held item stuff here { if (cont != null && cont.GetPressDown(Valve.VR.EVRButtonId.k_EButton_Grip) && grabTimer < 1) { heldItem.transform.parent = null; heldItem = null; } if (heldItem.GetComponent <Blaster>() != null) { Blaster gun = heldItem.GetComponent <Blaster>(); if (cont.GetHairTrigger()) { bool blasted = false; for (int i = 0; i < heldItem.transform.childCount; i++) { if (heldItem.transform.GetChild(i).CompareTag("FirePoint")) { blasted = true; gun.Blast(heldItem.transform.GetChild(i).transform.position, null, 100f); } } if (!blasted) { gun.Blast(null, 100f); } } } } if (cont.Equals(SteamVR_Controller.DeviceRelation.Leftmost) && GroundScript.OnGround)//left hand stuff goes here { Rigidbody Rig3D = Scenemanager.Player.GetComponent <Rigidbody>(); Vector3 ovel = Rig3D.velocity; Vector3 vel = Rig3D.velocity; Vector2 axis = new Vector3(cont.GetState().rAxis0.x, cont.GetState().rAxis0.y); float y = vel.y; if (GroundScript.OnGround && cont.GetPressDown(Valve.VR.EVRButtonId.k_EButton_Dashboard_Back) && jumpTimer > 29) { vel.y = 5f; jumpTimer = 0; } ovel.y = 0; vel.y = 0; vel += Vector3.ClampMagnitude(Head.head.transform.forward * axis.y + Rig3D.transform.right * axis.x, .3f * axis.magnitude); if (vel.magnitude > 6f * axis.magnitude && ovel.magnitude > vel.magnitude) { vel.y = y; Rig3D.velocity = vel; } else if (vel.magnitude > 6 * axis.magnitude) { } else { vel.y = y; Rig3D.velocity = vel; } } if (cont.Equals(SteamVR_Controller.DeviceRelation.Rightmost))//right hand stuff here { Scenemanager.Player.transform.Rotate(new Vector3(0, 10, 0) * cont.GetState().rAxis0.x); } } else { cont = GetComponentInParent <Hand>().controller; } }
// Token: 0x06005674 RID: 22132 RVA: 0x001DC090 File Offset: 0x001DA490 public override void Apply() { VRCInput.ClearChanges(); this._anyKey = false; bool flag = false; if (this.viveControllerManager == null && VRCTrackingManager.IsInitialized()) { this.viveControllerManager = VRCTrackingManager.GetTrackingComponent <SteamVR_ControllerManager>(); return; } if (!SteamVR.active) { return; } if (!this._isUsingViveControllers) { return; } SteamVR_TrackedObject component = this.viveControllerManager.left.GetComponent <SteamVR_TrackedObject>(); int index = (int)component.index; if (index >= 0 && component.isValid) { SteamVR_Controller.Device device = SteamVR_Controller.Input(index); Vector2 axis = device.GetAxis(EVRButtonId.k_EButton_Axis0); if (device.GetPress(EVRButtonId.k_EButton_Axis0)) { axis.Normalize(); this.inVertical.ApplyAxis(axis.y); this.inHorizontal.ApplyAxis(axis.x); this.inTouchpadLeftClick.ApplyButton(true); } else { this.inTouchpadLeftClick.ApplyButton(false); } if (device.GetTouch(EVRButtonId.k_EButton_Axis0)) { this.inTouchpadLeftX.ApplyAxis(axis.x); this.inTouchpadLeftY.ApplyAxis(axis.y); } else { this.inTouchpadLeftX.ApplyAxis(0f); this.inTouchpadLeftY.ApplyAxis(0f); } this.inBack.ApplyButton(device.GetPress(EVRButtonId.k_EButton_ApplicationMenu)); flag = VRCInput.IsChanged(); this.inRun.ApplyButton(true); VRCInput.ClearChanges(); this.inDropLeft.ApplyButton(device.GetPress(EVRButtonId.k_EButton_Grip)); this.inUseLeft.ApplyButton(device.GetHairTrigger()); this.inGrabLeft.ApplyButton(device.GetHairTrigger()); Vector2 axis2 = device.GetAxis(EVRButtonId.k_EButton_Axis1); this.inUseAxisLeft.ApplyAxis(axis2.x); this.inGrabAxisLeft.ApplyAxis(axis2.x); if (device.velocity.sqrMagnitude > 0.1f) { VRCInput.MarkChanged(); } } SteamVR_TrackedObject component2 = this.viveControllerManager.right.GetComponent <SteamVR_TrackedObject>(); int index2 = (int)component2.index; if (index2 >= 0 && component2.isValid) { SteamVR_Controller.Device device2 = SteamVR_Controller.Input(index2); Vector2 axis3 = device2.GetAxis(EVRButtonId.k_EButton_Axis0); if (device2.GetPress(EVRButtonId.k_EButton_Axis0)) { if (axis3.y > 0.7f) { if (device2.GetPressDown(EVRButtonId.k_EButton_Axis0)) { this.inJump.ApplyButton(true); } } else if (axis3.x > 0.7f) { this.inLookHorizontal.ApplyAxis(1f); this.inComfortRight.ApplyButton(true); } else if (axis3.x < -0.7f) { this.inLookHorizontal.ApplyAxis(-1f); this.inComfortLeft.ApplyButton(true); } this.inTouchpadRightClick.ApplyButton(true); } else { this.inTouchpadRightClick.ApplyButton(false); } if (device2.GetTouch(EVRButtonId.k_EButton_Axis0)) { this.inTouchpadRightX.ApplyAxis(axis3.x); this.inTouchpadRightY.ApplyAxis(axis3.y); } else { this.inTouchpadRightX.ApplyAxis(0f); this.inTouchpadRightY.ApplyAxis(0f); } this.inMenu.ApplyButton(device2.GetPress(EVRButtonId.k_EButton_ApplicationMenu)); this.inDropRight.ApplyButton(device2.GetPress(EVRButtonId.k_EButton_Grip)); this.inUseRight.ApplyButton(device2.GetHairTrigger()); this.inGrabRight.ApplyButton(device2.GetHairTrigger()); Vector2 axis4 = device2.GetAxis(EVRButtonId.k_EButton_Axis1); this.inUseAxisRight.ApplyAxis(axis4.x); this.inGrabAxisRight.ApplyAxis(axis4.x); if (device2.velocity.sqrMagnitude > 0.1f) { VRCInput.MarkChanged(); } } this._anyKey = (flag || VRCInput.IsChanged()); }