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; } }
//---------------------------------------------------------------------------------------------LEFT-GRABBING-------------------------------------------------------- void OnTriggerStay(Collider col) { if (col.gameObject.CompareTag("Throwable") || col.gameObject.CompareTag("Moveable")) //Debug.Log("I can pick this up"); { if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { GrabObject(col); if (col.gameObject.CompareTag("Throwable")) { ballReset.ballGrab = true; } } else if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { DropObject(col); if (col.gameObject.CompareTag("Throwable")) { ballReset.ballGrab = false; } } } }
private void Update() { device = SteamVR_Controller.Input((int)trackedObj.index); lineRenderer.SetPosition(0, transform.position); RaycastHit hit; if (Physics.Raycast(transform.position, transform.forward, out hit, Mathf.Infinity)) { if (hit.transform.tag == "Teleport") { lineRenderer.SetPosition(1, hit.point); if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { // Move player to pointed position transform.parent.position = hit.point; } } } else { lineRenderer.SetPosition(1, transform.position); } }
private ControllerState controllerEvents() { #if SteamVR_Legacy if (controller.GetPressDown(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger)) { return(ControllerState.DOWN); } if (controller.GetPressUp(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger)) { return(ControllerState.UP); } #elif SteamVR_2 if (m_controllerPress.GetStateDown(trackedObj.inputSource)) { return(ControllerState.DOWN); } if (m_controllerPress.GetStateUp(trackedObj.inputSource)) { return(ControllerState.UP); } #endif return(ControllerState.NONE); }
public void OnTriggerStay(Collider coli) { if (coli.gameObject.CompareTag("throwable") || coli.gameObject.CompareTag("Ball")) { if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { if (coli.gameObject.CompareTag("Ball")) { ballIsLive = false; gameLogic.RoundBegin(); } ThrowObject(coli); } else if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { if (coli.gameObject.CompareTag("Ball")) { ballIsLive = true; gameLogic.RoundBegin(); } GrabObject(coli); } } }
// Update is called once per frame void Update() { Controller = SteamVR_Controller.Input((int)trackedObj.index); // Getting the Touchpad Axis if (Controller.GetAxis() != Vector2.zero) { Debug.Log(gameObject.name + Controller.GetAxis()); } // Getting the Trigger press if (Controller.GetHairTriggerDown()) { Debug.Log(gameObject.name + " Trigger Press"); Raycasting(); } // Getting the Trigger Release if (Controller.GetHairTriggerUp()) { Debug.Log(gameObject.name + " Trigger Release"); } // Getting the Grip Press if (Controller.GetPressDown(SteamVR_Controller.ButtonMask.Grip)) { Debug.Log(gameObject.name + " Grip Press"); } // Getting the Grip Release if (Controller.GetPressUp(SteamVR_Controller.ButtonMask.Grip)) { Debug.Log(gameObject.name + " Grip Release"); } }
void OnTriggerStay(Collider col) { device = SteamVR_Controller.Input((int)trackedObj.index); if (col.gameObject.CompareTag("Throwable")) { if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { //Multi Throwing col.transform.SetParent(null); Rigidbody rigidBody = col.GetComponent <Rigidbody>(); rigidBody.isKinematic = false; rigidBody.velocity = device.velocity * throwForce; rigidBody.angularVelocity = device.angularVelocity; } else if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { col.GetComponent <Rigidbody>().isKinematic = true; col.transform.SetParent(gameObject.transform); device.TriggerHapticPulse(2000); } } }
void Update() { device = SteamVR_Controller.Input((int)trackedObject.index); if (device.GetAxis().x != 0 || device.GetAxis().y != 0) { Debug.Log(device.GetAxis().x + " " + device.GetAxis().y); } if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger)) { print("Trigger touched"); } if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { if (pc.calibrating) { pc.CalibratePosition(calibrationPoint); device.TriggerHapticPulse(1000); } Debug.Log("Trigger " + device.index + " pressed"); } }
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; } }
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) } }
// Update is called once per frame void Update() { Controller = SteamVR_Controller.Input((int)trackedObj.index); // Getting the Touchpad Axis checkSwipe(); // Getting the Trigger press if (Controller.GetHairTriggerDown()) { Debug.Log(gameObject.name + " Trigger Press"); } // Getting the Trigger Release if (Controller.GetHairTriggerUp()) { Debug.Log(gameObject.name + " Trigger Release"); } // Getting the Grip Press if (Controller.GetPressDown(SteamVR_Controller.ButtonMask.Grip)) { //Debug.Log(gameObject.name + " Grip Press"); } // Getting the Grip Release if (Controller.GetPressUp(SteamVR_Controller.ButtonMask.Grip)) { //Debug.Log(gameObject.name + " Grip Release"); GameObject lc = GameObject.Find("Controller (left)"); GameObject rc = GameObject.Find("Controller (right)"); lc.GetComponentInChildren <Canvas> ().enabled = !lc.GetComponentInChildren <Canvas> ().enabled; rc.GetComponentInChildren <Canvas> ().enabled = !rc.GetComponentInChildren <Canvas> ().enabled; } }
protected virtual void Update() { if (Controller == null || CurrentHandState == HandState.Uninitialized) { return; } foreach (var button in Inputs) { button.Value.Axis = Controller.GetAxis(button.Key); button.Value.SingleAxis = button.Value.Axis.x; button.Value.PressDown = Controller.GetPressDown(button.Key); button.Value.PressUp = Controller.GetPressUp(button.Key); button.Value.IsPressed = Controller.GetPress(button.Key); button.Value.TouchDown = Controller.GetTouchDown(button.Key); button.Value.TouchUp = Controller.GetTouchUp(button.Key); button.Value.IsTouched = Controller.GetTouch(button.Key); } HoldButtonPressed = Inputs[HoldButton].IsPressed; HoldButtonDown = Inputs[HoldButton].PressDown; HoldButtonUp = Inputs[HoldButton].PressUp; HoldButtonAxis = Inputs[HoldButton].SingleAxis; UseButtonPressed = Inputs[UseButton].IsPressed; UseButtonDown = Inputs[UseButton].PressDown; UseButtonUp = Inputs[UseButton].PressUp; UseButtonAxis = Inputs[UseButton].SingleAxis; if (CurrentInteractionStyle == InterationStyle.GripDownToInteract) { if (HoldButtonUp == true) { VisibilityLocked = false; } if (HoldButtonDown == true) { if (CurrentlyInteracting == null) { PickupClosest(); } } else if (HoldButtonUp == true && CurrentlyInteracting != null) { EndInteraction(null); } } else if (CurrentInteractionStyle == InterationStyle.GripToggleToInteract) { if (HoldButtonDown == true) { if (CurrentHandState == HandState.Idle) { PickupClosest(); if (IsInteracting) { CurrentHandState = HandState.GripToggleOnInteracting; } else if (NVRPlayer.Instance.PhysicalHands == true) { CurrentHandState = HandState.GripToggleOnNotInteracting; } } else if (CurrentHandState == HandState.GripToggleOnInteracting) { CurrentHandState = HandState.Idle; VisibilityLocked = false; EndInteraction(null); } else if (CurrentHandState == HandState.GripToggleOnNotInteracting) { CurrentHandState = HandState.Idle; VisibilityLocked = false; } } } if (IsInteracting == true) { CurrentlyInteracting.InteractingUpdate(this); } UpdateVisibilityAndColliders(); }
// Update is called once per frame void FixedUpdate() { device = SteamVR_Controller.Input((int)leftHand.index); //if (device.GetPress(SteamVR_Controller.ButtonMask.Trigger)) //{ // if (GameManager.instance.currentTool != null && GameManager.instance.currentTool.GetComponent<DisToolBase>().toolIsOther != null) // { // if (GameManager.instance.currentTool.GetComponent<DisToolBase>().toolIsOther.GetComponent<Part>().partType == PartType.螺栓) // { // if (!GameManager.instance.currentTool.GetComponent<DisToolBase>().toolIsOther.GetComponent<BoltPart>().isLimitTrigger) // { // if (GameManager.instance.currentTool.GetComponent<DisToolBase>().isToolPost) // { // if (!GameManager.instance.currentTool.GetComponentInParent<DisToolBase>().toolIsOther.GetComponent<BoltPart>().isLimitAudio) // { // GameManager.instance.audios.PlayOneShot(Audio.instance.LoadAudio("电钻")); // GameManager.instance.currentTool.GetComponent<DisToolBase>().toolIsOther.GetComponent<BoltPart>().isLimitAudio = true; // } // if (GameManager.instance.currentTool.GetComponent<DisToolBase>().toolIsOther.tag == "HelpPos") // { // GameManager.instance.currentTool.GetComponent<DisToolBase>().ToolIsOtherTranslate(); // Vector3.forward // if (!GameManager.instance.audios.isPlaying) // { // BtnBase.instance.ShowToolOperObj(GameManager.instance.toolCabObjs, ToolType.套筒扳手); // BtnBase.instance.HideToolOperObj(GameManager.instance.toolHandObjs, ToolType.套筒扳手); // GameObject.FindWithTag("CylinderTool").GetComponent<MeshCollider>().enabled = true; // GameManager.instance.currentTool.GetComponent<DisToolBase>().toolIsOther.transform.SetParent(GameObject.FindWithTag("CylinderTool").gameObject.transform); // GameManager.instance.accNumber = -1; // GameManager.instance.currentTool.transform.parent = null; // GameManager.instance.currentTool.GetComponent<DisToolBase>().ToolSetParent(); // GameManager.instance.currentTool.GetComponent<DisToolBase>().toolIsOther.GetComponent<BoltPart>().isLimitTrigger = true; // } // } // else if (GameManager.instance.currentTool.GetComponent<DisToolBase>().toolIsOther.tag == "BoltBackpart") // { // GameManager.instance.currentTool.GetComponent<DisToolBase>().ToolIsOtherTranslate(); // -Vector3.forward // if (!GameManager.instance.audios.isPlaying) // { // GameManager.instance.currentTool.transform.parent = null; // GameManager.instance.currentTool.GetComponent<DisToolBase>().toolIsOther.transform.SetParent(GameManager.instance.currentTool.transform); // GameManager.instance.currentTool.GetComponent<DisToolBase>().ToolSetParent(); // GameManager.instance.currentTool.GetComponent<DisToolBase>().toolIsOther.GetComponent<BoltPart>().isLimitTrigger = true; // } // } // else if (GameManager.instance.currentTool.GetComponent<DisToolBase>().toolIsOther.tag == "HelpPos2") // { // GameManager.instance.currentTool.GetComponent<DisToolBase>().ToolIsOtherTranslate(); // -Vector3.forward // if (!GameManager.instance.audios.isPlaying) // { // GameManager.instance.boltsPos2Number++; // if (GameManager.instance.boltsPos2Number == 2) // { // BtnBase.instance.ShowToolOperObj(GameManager.instance.toolCabObjs, ToolType.套筒扳手); // BtnBase.instance.HideToolOperObj(GameManager.instance.toolHandObjs, ToolType.套筒扳手); // GameManager.instance.accNumber = -1; // GameManager.instance.currentTool.transform.parent = null; // GameManager.instance.currentTool.GetComponent<DisToolBase>().ToolSetParent(); // GameObject.FindWithTag("RearPart").GetComponent<BoxCollider>().enabled = true; // GameManager.instance.currentTool.GetComponent<DisToolBase>().toolIsOther.GetComponent<BoltPart>().isLimitTrigger = true; // } // GameManager.instance.currentTool.GetComponent<DisToolBase>().toolIsOther.transform.SetParent(GameObject.FindWithTag("RearPart").gameObject.transform); // } // } // else if (GameManager.instance.currentTool.GetComponent<DisToolBase>().toolIsOther.tag == "BoltFrontpart") // { // GameManager.instance.currentTool.GetComponent<DisToolBase>().ToolIsOtherTranslate(); // Vector3.forward // if (!GameManager.instance.audios.isPlaying) // { // GameManager.instance.currentTool.transform.parent = null; // GameManager.instance.currentTool.GetComponent<DisToolBase>().toolIsOther.transform.SetParent(GameManager.instance.currentTool.transform); // GameManager.instance.currentTool.GetComponent<DisToolBase>().ToolSetParent(); // GameManager.instance.currentTool.GetComponent<DisToolBase>().toolIsOther.GetComponent<BoltPart>().isLimitTrigger = true; // } // } // else if (GameManager.instance.currentTool.GetComponent<DisToolBase>().toolIsOther.tag == "LocationPart") // { // GameManager.instance.currentTool.GetComponent<DisToolBase>().ToolIsOtherTranslate(); // (Vector3.forward) // if (!GameManager.instance.audios.isPlaying) // { // GameManager.instance.currentTool.transform.parent = null; // GameManager.instance.currentTool.GetComponent<DisToolBase>().toolIsOther.transform.SetParent(GameManager.instance.currentTool.transform); // GameManager.instance.currentTool.GetComponent<DisToolBase>().ToolSetParent(); // GameManager.instance.currentTool.GetComponent<DisToolBase>().toolIsOther.GetComponent<BoltPart>().isLimitTrigger = true; // } // } // else // { // GameManager.instance.currentTool.GetComponent<DisToolBase>().ToolIsOtherTranslate(); // Vector3.forward // if (!GameManager.instance.audios.isPlaying) // { // GameManager.instance.currentTool.transform.parent = null; // GameManager.instance.currentTool.GetComponent<DisToolBase>().toolIsOther.transform.SetParent(GameManager.instance.currentTool.transform); // GameManager.instance.currentTool.GetComponent<DisToolBase>().ToolSetParent(); // GameManager.instance.currentTool.GetComponent<DisToolBase>().toolIsOther.GetComponent<BoltPart>().isLimitTrigger = true; // } // } // } // } // } // } //} if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { if (GameManager.instance.currentTool != null) { if (GameManager.instance.currentTool.GetComponent <DisToolBase>().toolIsOther != null) { if (GameManager.instance.currentTool.GetComponent <DisToolBase>().toolIsOther.GetComponent <Part>().partType == PartType.螺栓) { GameManager.instance.audios.PlayOneShot(Audio.instance.LoadAudio("电钻")); // 开始播放 isPlayAudio = true GameManager.instance.currentTool.GetComponent <DisToolBase>().toolIsOther.GetComponent <BoltPart>().isPlayAudio = true; } if (GameManager.instance.currentTool.GetComponent <DisToolBase>().toolIsOther.GetComponent <Part>().partType == PartType.气缸盖) { GameManager.instance.currentTool.GetComponent <DisToolBase>().toolIsOther.transform.SetParent(GameManager.instance.rightHandParent.transform); } if (GameManager.instance.currentTool.GetComponent <DisToolBase>().toolIsOther.name == "定位销子") { GameManager.instance.currentTool.GetComponent <DisToolBase>().toolIsOther.transform.SetParent(GameManager.instance.rightHandParent.transform); } if (GameManager.instance.currentTool.GetComponent <DisToolBase>().toolIsOther.name == "电机转子") { GameManager.instance.currentTool.GetComponent <DisToolBase>().toolIsOther.transform.SetParent(GameManager.instance.rightHandParent.transform); } if (GameManager.instance.currentTool.GetComponent <DisToolBase>().toolIsOther.name == "偏心轴") { GameManager.instance.currentTool.GetComponent <DisToolBase>().toolIsOther.transform.SetParent(GameManager.instance.rightHandParent.transform); } if (GameManager.instance.currentTool.GetComponent <DisToolBase>().toolIsOther.name == "huosai2") { GameManager.instance.currentTool.GetComponent <DisToolBase>().toolIsOther.transform.SetParent(GameManager.instance.rightHandParent.transform); } if (GameManager.instance.currentTool.GetComponent <DisToolBase>().toolIsOther.name == "huosai1") { GameManager.instance.currentTool.GetComponent <DisToolBase>().toolIsOther.transform.SetParent(GameManager.instance.rightHandParent.transform); } } } } if (GameManager.instance.currentTool != null && GameManager.instance.currentTool.GetComponent <DisToolBase>().toolIsOther != null) { if (GameManager.instance.currentTool.GetComponent <DisToolBase>().toolIsOther.GetComponent <Part>().partType == PartType.螺栓) { if (GameManager.instance.currentTool.GetComponent <DisToolBase>().toolIsOther.GetComponent <BoltPart>().isPlayAudio) { if (!GameManager.instance.audios.isPlaying) { if (GameManager.instance.currentTool.GetComponent <DisToolBase>().toolIsOther.GetComponent <BoltPart>().boltModelType != BoltModelType.BOLT_HELP_UP01 && GameManager.instance.currentTool.GetComponent <DisToolBase>().toolIsOther.GetComponent <BoltPart>().boltModelType != BoltModelType.BOLT_HELP_DOWN02 && GameManager.instance.currentTool.GetComponent <DisToolBase>().toolIsOther.GetComponent <BoltPart>().boltModelType != BoltModelType.BOLT_HELP_LEFT03 && GameManager.instance.currentTool.GetComponent <DisToolBase>().toolIsOther.GetComponent <BoltPart>().boltModelType != BoltModelType.BOLT_HELP_RIGHT04 && GameManager.instance.currentTool.GetComponent <DisToolBase>().toolIsOther.GetComponent <BoltPart>().boltModelType != BoltModelType.BOLT_HELP_FRONT05 && GameManager.instance.currentTool.GetComponent <DisToolBase>().toolIsOther.GetComponent <BoltPart>().boltModelType != BoltModelType.BOLT_HELP_BEHIND06) { GameManager.instance.currentTool.transform.parent = null; GameManager.instance.currentTool.GetComponent <DisToolBase>().toolIsOther.transform.SetParent(GameManager.instance.currentTool.transform); GameManager.instance.currentTool.GetComponent <DisToolBase>().ToolSetParent(); GameManager.instance.currentTool.GetComponent <DisToolBase>().toolIsOther.GetComponent <BoltPart>().isPlayAudio = false; } else { GameManager.instance.willAddColliderPartNumber++; WillDisPartAttr[] willDisPartObj = GameObject.FindGameObjectWithTag("DisEquipment").GetComponentsInChildren <WillDisPartAttr>(); for (int i = 0; i < willDisPartObj.Length; i++) { if ((int)willDisPartObj[i].willDisPartType == GameManager.instance.willAddColliderPartNumber) { if (willDisPartObj[i].GetComponent <BoxCollider>() != null) { willDisPartObj[i].GetComponent <BoxCollider>().enabled = true; } else if (willDisPartObj[i].GetComponent <MeshCollider>() != null) { willDisPartObj[i].GetComponent <MeshCollider>().enabled = true; } GameManager.instance.currentTool.GetComponent <DisToolBase>().toolIsOther.transform.SetParent(willDisPartObj[i].transform); } } BtnBase.instance.ShowToolOperObj(GameManager.instance.toolCabObjs, ToolType.套筒扳手); BtnBase.instance.HideToolOperObj(GameManager.instance.toolHandObjs, ToolType.套筒扳手); BtnBase.instance.CurrentTool(1); GameManager.instance.currentTool.transform.parent = null; GameManager.instance.currentTool.GetComponent <DisToolBase>().ToolSetParent(); GameManager.instance.currentTool.GetComponent <DisToolBase>().toolIsOther.GetComponent <BoltPart>().isPlayAudio = false; } } else { GameManager.instance.currentTool.GetComponent <DisToolBase>().ToolIsOtherTranslate(); } } } } }
// Update is called once per frame void FixedUpdate() { if (cont == null)//set controller { cont = GetComponentInParent <Hand>().controller; } else { if (speedImmune > 0) { speedImmune--; } if (punchBuffer > 0) { punchBuffer--; } if (cont.GetHairTriggerDown()) { punchBuffer = punchWaiter + 1; } if (cont.GetPressDown(Valve.VR.EVRButtonId.k_EButton_Axis0)) { lFist = null; rFist = null; } if (lFist == null || reSync) { if (cont == SteamVR_Controller.Input(SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.FarthestLeft))) { lFist = this; } if (cont == SteamVR_Controller.Input(SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.FarthestRight))) { rFist = lFist; rFist = this; } } if (rFist == null || reSync) { if (cont == SteamVR_Controller.Input(SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.FarthestRight))) { rFist = this; } if (cont == SteamVR_Controller.Input(SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.FarthestLeft))) { lFist = rFist; lFist = this; } } if (rFist == this) {// right fist stuff if (speedImmune > 0) { speedImmune--; } if (cont.GetState().rAxis0.x >= .1f || cont.GetState().rAxis0.x <= -.1f)//rotate here { rigidScript.Rig3D.transform.Rotate(new Vector3(0, 1, 0), cont.GetState().rAxis0.x * 2f); } transform.GetChild(0).localScale = new Vector3(-50, -50, 50);//boxing glove scale } else { //setup for movement Vector3 ovel = rigidScript.Rig3D.velocity; Vector3 vel = rigidScript.Rig3D.velocity; Vector2 axis = new Vector3(cont.GetState().rAxis0.x, cont.GetState().rAxis0.y); float y = vel.y; ovel.y = 0; vel.y = 0; if (GroundScript.OnGround) { if (axis.sqrMagnitude > .01f) { rigidScript.Rig3D.useGravity = false; if (axis.x < 0) //left { if (axis.y < 0) //backwards { vel += Vector3.ClampMagnitude(GroundScript.Back.normalized * Mathf.Abs(axis.y) + GroundScript.Left.normalized * Mathf.Abs(axis.x), (GroundScript.OnGround) ? Acceleration : .08f) * axis.magnitude; } else//forwards { vel += Vector3.ClampMagnitude(GroundScript.Forward.normalized * Mathf.Abs(axis.y) + GroundScript.Left.normalized * Mathf.Abs(axis.x), (GroundScript.OnGround) ? Acceleration : .08f) * axis.magnitude; } } else//right { if (axis.y < 0)//backwards { vel += Vector3.ClampMagnitude(GroundScript.Back.normalized * Mathf.Abs(axis.y) + GroundScript.Right.normalized * Mathf.Abs(axis.x), (GroundScript.OnGround) ? Acceleration : .08f) * axis.magnitude; } else//forwards { vel += Vector3.ClampMagnitude(GroundScript.Forward.normalized * Mathf.Abs(axis.y) + GroundScript.Right.normalized * Mathf.Abs(axis.x), (GroundScript.OnGround) ? Acceleration : .08f) * axis.magnitude; } } } else { rigidScript.Rig3D.useGravity = true; } } else { vel += Vector3.ClampMagnitude(Head.lookDir * axis.y + Head.rightDir * axis.x, (GroundScript.OnGround) ? Acceleration : .12f) * axis.magnitude; vel += Vector3.ClampMagnitude(Head.lookDir * axis.y + Head.rightDir * axis.x, (GroundScript.OnGround) ? Acceleration : .12f) * axis.magnitude; } if (vel.magnitude > MoveSpeed * axis.sqrMagnitude && ovel.magnitude > vel.magnitude) { //this is where we move vel.y = y; if (GroundScript.OnGround) { rigidScript.Rig3D.velocity = vel * .9f;//NOW WITH 10 PERCENT TIGHTER TURNS } } else if (Vector3.Dot(axis, vel) > MoveSpeed) { //this is so we dont break velocity cap } else { //this is also a valid move condiditon vel.y = y; rigidScript.Rig3D.velocity = vel; } transform.GetChild(0).localScale = new Vector3(-50, -50, -50);//fist scale } if (punchTimer > 0)//this is where we set the fists ideal location to the punch destination { idealPoint = new Vector3(0, -maxDist / 2, -.065f + maxDist / 2); punchTimer--; punchWaiter = 20; } else { if (punchWaiter > 0)//this is where we wait to punch { punchWaiter--; if (transform.localPosition == idealPoint && punchWaiter < 19) { punchWaiter = 0; } } else if (punchBuffer > 0)//this is where we punch { canLaunch = true; punchTimer = 20; if (whoosh != null) { whoosh.pitch = Random.Range(0.8f, 1.2f); // randomizes pitch whoosh.Play(); // plays whoosh sound when punch } } idealPoint = new Vector3(0, 0, -.065f); } transform.localPosition = transform.localPosition + Vector3.ClampMagnitude(idealPoint - transform.localPosition, maxSpeed); if (cont.GetPress(Valve.VR.EVRButtonId.k_EButton_Grip) && Physics.Raycast(transform.position - (transform.forward - transform.up).normalized * .1f, transform.forward - transform.up, maxDist)) { for (int i = 0; i < transform.childCount; i++) { if (transform.GetChild(i).CompareTag("Projection")) { transform.GetChild(i).gameObject.SetActive(true); } } } else { for (int i = 0; i < transform.childCount; i++) { if (transform.GetChild(i).CompareTag("Projection")) { transform.GetChild(i).gameObject.SetActive(false); } } } if (cont.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis1).x > .01 && Physics.Raycast(transform.position - (transform.forward - transform.up).normalized * .1f, transform.forward - transform.up, out info, .4f)) { if (info.transform.tag == "playButton") { Scene currentScene = SceneManager.GetActiveScene(); SceneManager.LoadScene((currentScene.buildIndex + 1) % SceneManager.sceneCountInBuildSettings); } if (info.transform.tag == "Enemy") { Destroy(info.transform.gameObject); } if (info.transform.tag == "Missile") { Destroy(info.transform.gameObject); } if (info.transform.tag != "Boost" && info.transform.tag != "enemy" && info.transform.name != "Player" && canLaunch) { canLaunch = false; cont.TriggerHapticPulse(3000, Valve.VR.EVRButtonId.k_EButton_Axis4); Vector3 vel = rigidScript.Rig3D.velocity; vel.y = 0; if ((vel + ((transform.forward - transform.up).normalized * -.3f / Time.deltaTime * .55f)).magnitude < vel.magnitude) { vel += ((transform.forward - transform.up).normalized * -.3f / Time.deltaTime * .55f) * 2; } else { vel += ((transform.forward - transform.up).normalized * -.3f / Time.deltaTime * .55f); } punchTimer = 0; rigidScript.Rig3D.velocity = vel; if (info.collider.gameObject.tag == "Pillar") { rigidScript.Rig3D.AddForce(((transform.forward - transform.up).normalized * -.3f / Time.deltaTime * 800f * 2)); } if (punch != null) { punch.pitch = Random.Range(0.8f, 1.2f); punch.Play(); } } } } if (speedImmune > 0) { rigidScript.Rig3D.velocity = Vector3.ClampMagnitude(rigidScript.Rig3D.velocity, 25 * speedImmune * speedImmune); } else { rigidScript.Rig3D.velocity = Vector3.ClampMagnitude(rigidScript.Rig3D.velocity, 25); } prevLocalPos = transform.localPosition; prevpos = transform.position; ////////////Wind Sounds/////////// if (wind != null) { if (GroundScript.OnGround) { wind.volume -= 0.5f * Time.deltaTime; // fade out } else if (rigidScript.Rig3D.velocity.magnitude != 0) { wind.volume = (rigidScript.Rig3D.velocity.magnitude / 25); // wind volume depends on velocity } else { wind.volume -= 0.2f * Time.deltaTime; // fade out } } /////////Footstep Sounds///////// if (foot1 != null) { int num = Random.Range(1, 3); if (GroundScript.OnGround && rigidScript.Rig3D.velocity.magnitude > 1.0f && rigidScript.Rig3D.velocity.magnitude < 5.0f && timeForSteps > 50.0f) // walking speed { foot1.pitch = Random.Range(0.8f, 1.2f); foot1.Play(); timeForSteps = 0; } else if (GroundScript.OnGround && rigidScript.Rig3D.velocity.magnitude >= 5.0f && timeForSteps > 25.0f) // running speed { foot1.pitch = Random.Range(0.8f, 1.2f); foot1.Play(); timeForSteps = 0; } timeForSteps++; } //////////Landing Sound/////////// if (wind != null) { if (GroundScript.OnGround == false) { wasInAir = true; } if (GroundScript.OnGround == true && wasInAir == true) { landing.Play(); wasInAir = false; } } }
// Update is called once per frame void Update() { if (useVR == 2) { deviceL = SteamVR_Controller.Input((int)trackedObjectL.index); deviceR = SteamVR_Controller.Input((int)trackedObjectR.index); if (Input.GetKeyDown(PathChangeButton) || deviceL.GetPressDown(gripButton)) { if (PathNum < Paths.Length - 1) { PathNum++; } else { PathNum = 0; } CurrentWayPointID = 0; } } if (useVR == 1) { if (Input.GetKeyDown(PathChangeButton) || OVRInput.GetDown(OVRInput.Button.Four)) { if (PathNum < Paths.Length - 1) { PathNum++; } else { PathNum = 0; } CurrentWayPointID = 0; } } if (Paths.Length != 0) { PathToFollow = Paths[PathNum].GetComponent <FollowPath>(); /*if (PathNum < 1) * { * Debug.Log("enable cube"); * CubeCollider.SetActive(true); * SphereCollider.SetActive(false); * * } * * if (PathNum < 2) * { * if (PathNum > 0) * { * Debug.Log("enable sphere"); * CubeCollider.SetActive(false); * SphereCollider.SetActive(true); * } * }*/ //Debug.Log(PathToFollow.name); /*if (Input.GetKeyDown(path01)) * { * PathToFollow = Paths[PathNum=0].GetComponent<FollowPath>(); * } * if (Input.GetKeyDown(path02)) * { * PathToFollow = Paths[PathNum = 1].GetComponent<FollowPath>(); * }*/ float distance = Vector3.Distance(PathToFollow.path_objs[CurrentWayPointID].position, transform.position); transform.position = Vector3.MoveTowards(transform.position, PathToFollow.path_objs[CurrentWayPointID].position, Time.deltaTime * speed); var rotation = Quaternion.LookRotation(PathToFollow.path_objs[CurrentWayPointID].position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * rotationspeed); if (distance <= reachDistace) { CurrentWayPointID++; } if (CurrentWayPointID >= PathToFollow.path_objs.Count) { CurrentWayPointID = 0; } } }
void Update() { bool gripDown = isOculusRift? OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger, OculusController) || OVRInput.GetDown(OVRInput.Button.SecondaryIndexTrigger, OculusController) : controller.GetPressDown(gripButton); bool gripUp = isOculusRift ? OVRInput.GetUp(OVRInput.Button.PrimaryIndexTrigger, OculusController) || OVRInput.GetUp(OVRInput.Button.SecondaryIndexTrigger, OculusController) : controller.GetPressUp(gripButton); bool gripping = isOculusRift ? OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger, OculusController) || OVRInput.GetUp(OVRInput.Button.SecondaryIndexTrigger, OculusController) : controller.GetPress(gripButton); //bool upButtonDown = isOculusRift? // OVRInput.GetDown(OVRInput.Button.PrimaryThumbstickDown, OculusController) || OVRInput.GetDown(OVRInput.Button.SecondaryThumbstickDown, OculusController) // : if (gripDown && intersectingGrabbables.Any(x => x != null) && draggingObjects.Count == 0) { var potentialDrags = intersectingGrabbables.Where(x => x != null).ToList(); potentialDrags.Sort((x, y) => y.GetComponent <Grabbable>().GetPriority() - x.GetComponent <Grabbable>().GetPriority()); if (potentialDrags.Count() > 0) { PropergateOnGrab(potentialDrags.First().gameObject); } } else if (gripUp && draggingObjects.Count > 0) { draggingObjects.Where(x => x != null).ForEach(x => x.GetComponent <Grabbable>().OnRelease(this)); draggingObjects.Clear(); } else if (gripping && draggingObjects.Count > 0) { draggingObjects.Where(x => x != null).ForEach(x => x.GetComponent <Grabbable>().OnDrag(this)); } if (draggingObjects.Count > 0) { if (!isOculusRift) { controller.TriggerHapticPulse(100); } } //brush actions : SteamVR_Controller.ButtonMask.Grip bool padPressDown = isOculusRift ? OVRInput.Get(OVRInput.Button.PrimaryThumbstick, OculusController) || OVRInput.Get(OVRInput.Button.SecondaryThumbstick, OculusController) : controller.GetPress(padButton); bool padPressUp = isOculusRift ? OVRInput.GetUp(OVRInput.Button.PrimaryThumbstick, OculusController) || OVRInput.GetUp(OVRInput.Button.SecondaryThumbstick, OculusController) : controller.GetPressUp(padButton); #region details on demand //detail on demand actions if (VisualisationAttributes.detailsOnDemand) { if (padPressDown) { bool detail3Dscatterplots = false; GameObject[] listCandidatesBrush3D = GameObject.FindGameObjectsWithTag("Scatterplot3D"); for (int i = 0; i < listCandidatesBrush3D.Length; i++) { { if (Vector3.Distance(listCandidatesBrush3D[i].transform.position, transform.position) < 0.3f) { detail3Dscatterplots = true; brushingPoint.gameObject.SetActive(true); currentDetailView = listCandidatesBrush3D[i]; brushingPoint.transform.position = transform.position + transform.forward * 0.1f; brushingPoint.transform.localScale = new Vector3(0.01f, 0.01f, 0.01f); if (currentDetailView.GetComponent <Visualization>() != null) { currentDetailView.GetComponent <Visualization>().OnDetailOnDemand(this, brushingPoint.transform.position, currentDetailView.transform.InverseTransformPoint(brushingPoint.transform.position), true); } else { Debug.Log("the object is null/..."); } } } } if (!detail3Dscatterplots) { RaycastHit hit; Ray downRay = new Ray(transform.position, transform.forward); if (Physics.Raycast(downRay, out hit)) { if (hit.transform.gameObject.GetComponent <Brushable>() != null) { brushingPoint.gameObject.SetActive(true); currentDetailView = hit.transform.gameObject; brushingPoint.transform.position = hit.point; brushingPoint.transform.rotation = currentDetailView.transform.rotation; brushingPoint.transform.localScale = new Vector3(0.01f, 0.01f, 0.0f); currentDetailView.GetComponent <Visualization>().OnDetailOnDemand( this, hit.point, currentDetailView.transform.InverseTransformPoint(hit.point), false); } } } } if (padPressUp) { if (currentDetailView != null) { currentDetailView.GetComponent <Visualization>().OnDetailOnDemand(null, Vector3.zero, Vector3.zero, false); currentDetailView.GetComponent <Visualization>().OnDetailOnDemandRelease(this); currentDetailView = null; brushingPoint.gameObject.SetActive(false); } } } #endregion tracking.RemoveAt(0); tracking.Add(transform.TransformPoint(new Vector3(0, -0.04f, 0))); }
// Update is called once per frame void Update() { device = SteamVR_Controller.Input((int)trackedObj.index); Ray laser = new Ray(transform.position, transform.up); line.SetPosition(0, laser.origin); if (Physics.Raycast(laser, out laserHit, 200)) { line.SetPosition(1, laserHit.point); //TODO: get button press in addition to collision to trigger actions if (laserHit.collider.name == "TriangleBreak Cube") { for (int i = 0; i < cubes.Length; i++) { if (i == 0) { cubes[i].GetComponent <Renderer>().material = selected; } else { cubes[i].GetComponent <Renderer>().material = defaultMat; } } //set up scene if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad)) { manager.startTriangleBreak(); manager.score = 0; } } else if (laserHit.collider.name == "Diamond Break Cube") { for (int i = 0; i < cubes.Length; i++) { if (i == 1) { cubes[i].GetComponent <Renderer>().material = selected; } else { cubes[i].GetComponent <Renderer>().material = defaultMat; } } //set up scene if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad)) { manager.startDiamondBreak(); manager.score = 0; } } else if (laserHit.collider.name == "Scenario1 Cube") { for (int i = 0; i < cubes.Length; i++) { if (i == 2) { cubes[i].GetComponent <Renderer>().material = selected; } else { cubes[i].GetComponent <Renderer>().material = defaultMat; } } //set up scene if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad)) { manager.startScenario1(); manager.score = 0; } } else if (laserHit.collider.name == "Scenario2 Cube") { for (int i = 0; i < cubes.Length; i++) { if (i == 3) { cubes[i].GetComponent <Renderer>().material = selected; } else { cubes[i].GetComponent <Renderer>().material = defaultMat; } } //set up scene if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad)) { manager.startScenario2(); manager.score = 0; } } else { //remove material from all cubes for (int i = 0; i < cubes.Length; i++) { cubes[i].GetComponent <Renderer>().material = defaultMat; } //for } //else } else { line.SetPosition(1, laser.GetPoint(200)); //change cubes to default material if nothing is selected for (int i = 0; i < cubes.Length; i++) { cubes[i].GetComponent <Renderer>().material = defaultMat; } } //else } //Update
public void CheckController(SteamVR_TrackedObject controller) { SteamVR_Controller.Device input = null; if (controller != null) { input = SteamVR_Controller.Input((int)controller.index); } Vector3 origin; Vector3 direction; Quaternion rotation; origin = controller.transform.position; direction = controller.transform.rotation * new Vector3(0, 0, 100); rotation = controller.transform.rotation; bool hitScreen = false; // Mouse simulation if (Visible()) { RaycastHit[] rcasts = Physics.RaycastAll(origin, direction); foreach (RaycastHit rcast in rcasts) { if (rcast.collider.gameObject != this.gameObject) { continue; } hitScreen = true; if (m_manager.ShowLine) { m_line.enabled = true; m_line.SetPosition(0, origin); m_line.SetPosition(1, rcast.point); } else { m_line.enabled = false; } float dx = m_manager.GetScreenWidth(Screen); float dy = m_manager.GetScreenHeight(Screen); float vx = rcast.textureCoord.x; float vy = rcast.textureCoord.y; vy = 1 - vy; float x = (vx * dx); float y = (vy * dy); int iX = (int)x; int iY = (int)y; m_manager.SetCursorPos(iX, iY); if (m_lastShowClick == 0) { //if (m_manager.EnableZoom) if (m_manager.ViveZoom != VdmDesktopManager.ViveButton.None) { if (input.GetPressDown(MyButtonToViveButton(m_manager.ViveZoom))) { VdmDesktopManager.ActionInThisFrame = true; m_distanceBeforeZoom = (controller.transform.position - rcast.point).magnitude; float distanceDelta = m_distanceBeforeZoom - m_manager.ControllerZoomDistance; Vector3 vectorMove = rotation * new Vector3(0, 0, -distanceDelta); m_positionZoomed = m_positionNormal + vectorMove; m_rotationZoomed = m_rotationNormal; //m_positionZoomed = controller.transform.position + controller.transform.rotation * new Vector3(0, 0, m_manager.ControllerZoomDistance); ZoomIn(); } if (input.GetPressUp(MyButtonToViveButton(m_manager.ViveZoom))) { VdmDesktopManager.ActionInThisFrame = true; ZoomOut(); } } } if (m_manager.ViveLeftClick != VdmDesktopManager.ViveButton.None) { if (input.GetPressDown(MyButtonToViveButton(m_manager.ViveLeftClick))) { m_lastLeftTriggerClick = Time.time; m_manager.SimulateMouseLeftDown(); VdmDesktopManager.ActionInThisFrame = true; } if (input.GetPressUp(MyButtonToViveButton(m_manager.ViveLeftClick))) { if (m_lastLeftTriggerClick != 0) { m_manager.SimulateMouseLeftUp(); m_lastLeftTriggerClick = 0; VdmDesktopManager.ActionInThisFrame = true; } } } if (m_manager.ViveTouchPadForClick) { if (input.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad) && (input.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0).x < -0.2f)) { m_lastLeftTouchClick = Time.time; m_manager.SimulateMouseLeftDown(); VdmDesktopManager.ActionInThisFrame = true; } if (input.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad) && (input.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0).x > -0.2f)) { m_lastRightTouchClick = Time.time; m_manager.SimulateMouseRightDown(); VdmDesktopManager.ActionInThisFrame = true; } } if (m_lastLeftTouchClick != 0) { if (input.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad)) { m_manager.SimulateMouseLeftUp(); m_lastLeftTouchClick = 0; VdmDesktopManager.ActionInThisFrame = true; } } if (m_lastRightTouchClick != 0) { if (input.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad)) { m_manager.SimulateMouseRightUp(); m_lastRightTouchClick = 0; VdmDesktopManager.ActionInThisFrame = true; } } } } if ((Visible() == false) || (hitScreen)) { if (input.GetPressDown(MyButtonToViveButton(m_manager.ViveShow))) { if (m_lastShowClick == 0) { VdmDesktopManager.ActionInThisFrame = true; if (hitScreen == false) { Show(); // Don't set m_positionNormal. Vector3 startDistance = controller.transform.rotation * new Vector3(0, 0, m_manager.ControllerZoomDistance); transform.position = controller.transform.position + startDistance; transform.rotation = controller.transform.rotation; m_lastShowClick = Time.time - 10; } else { m_lastShowClick = Time.time; } transform.SetParent(controller.transform); m_controllerAttach = true; } } } if (input.GetPressUp(MyButtonToViveButton(m_manager.ViveShow))) { if (m_lastShowClick != 0) { if (Time.time - m_lastShowClick < 0.5f) { Hide(); } VdmDesktopManager.ActionInThisFrame = true; m_lastShowClick = 0; transform.SetParent(m_manager.transform); m_controllerAttach = false; m_positionNormal = transform.position; m_rotationNormal = transform.rotation; } } }
void Update() { //---------------------------------------------------------------------------TELEPORTATION------------------------------------------------------------------------------------------------ deviceLeft = SteamVR_Controller.Input((int)trackedObj.index); deviceRight = SteamVR_Controller.Input((int)trackedObjRight.index); if (deviceLeft.GetPress(SteamVR_Controller.ButtonMask.Touchpad)) { laser.gameObject.SetActive(true); teleportAimerObject.SetActive(true); laser.SetPosition(0, LeftController.transform.position); RaycastHit hit; if (Physics.Raycast(LeftController.transform.position, LeftController.transform.forward, out hit, 15, laserMask)) { //Debug.Log("The ray can collide with something"); teleportLocation = hit.point; //Debug.Log("hit.point = " + hit.point); laser.SetPosition(1, teleportLocation); // aimer position teleportAimerObject.transform.position = new Vector3(teleportLocation.x, teleportLocation.y + yNudgeAmount, teleportLocation.z); } else { // Debug.Log("using the height raycast method"); teleportLocation = new Vector3(LeftController.transform.forward.x * 15 + LeftController.transform.position.x, LeftController.transform.forward.y * 15 + LeftController.transform.position.y, LeftController.transform.forward.z * 15 + LeftController.transform.position.z); RaycastHit groundRay; if (Physics.Raycast(teleportLocation, -Vector3.up, out groundRay, 17, laserMask)) { //Debug.Log("Lasermask Condition met"); teleportLocation = new Vector3(LeftController.transform.forward.x * 15 + LeftController.transform.position.x, groundRay.point.y, LeftController.transform.forward.z * 15 + LeftController.transform.position.z); } else { teleportLocation = player.transform.position; } laser.SetPosition(1, LeftController.transform.forward * 15 + LeftController.transform.position); // aimer position teleportAimerObject.transform.position = teleportLocation + new Vector3(0, yNudgeAmount, 0); } } if (deviceLeft.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad)) { laser.gameObject.SetActive(false); teleportAimerObject.SetActive(false); player.transform.position = new Vector3(teleportLocation.x, player.transform.position.y, teleportLocation.z); } //-------------------------------------------------------------MENU---------------------------------------------- if (deviceRight.GetTouch(SteamVR_Controller.ButtonMask.Touchpad)) { objectmenu.SetActive(true); touchPoint = deviceRight.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad).x; if (touchPoint > 0.7f) { if (!hasJustSelected) { objectMenuManager.MenuRight(); hasJustSelected = true; // StartCoroutine("MenuCoolDown"); } } else if (touchPoint < -0.7f) { if (!hasJustSelected) { objectMenuManager.MenuLeft(); hasJustSelected = true; //StartCoroutine("MenuCoolDown"); } } if (touchPoint > -0.1f && touchPoint < 0.1f) { hasJustSelected = false; } if (deviceRight.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { SpawnObject(); } } if (deviceRight.GetTouchUp(SteamVR_Controller.ButtonMask.Touchpad)) { objectmenu.SetActive(false); } }
// Update is called once per frame void Update() { device = SteamVR_Controller.Input((int)trackedObj.index); leftDevice = SteamVR_Controller.Input(leftIndex); rightDevice = SteamVR_Controller.Input(rightIndex); // Detect a shot if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { ShootProjectile(); } /**** Teleportation ****/ if (allowWalking && leftDevice.GetPress(SteamVR_Controller.ButtonMask.Grip)) { movementDirection = playerCam.transform.forward; movementDirection = new Vector3(movementDirection.x, 0, movementDirection.z); // this assumes floor is always at y = 0 movementDirection = movementDirection * moveSpeed * Time.deltaTime; player.transform.position += movementDirection; } if (isDashing && useDash) { lerpTime += 1 * dashSpeed; player.transform.position = Vector3.Lerp(dashStartPosition, teleportLocation + new Vector3(0, playerHeight, 0), lerpTime); if (lerpTime >= 1) { isDashing = false; lerpTime = 0; } } else { if (leftDevice.GetPress(SteamVR_Controller.ButtonMask.Touchpad) && leftController) { canTeleport = false; //laser.gameObject.SetActive(true); teleportAimerObject.SetActive(true); //laser.SetPosition(0, gameObject.transform.position); RaycastHit hit; if (Physics.Raycast(transform.position, transform.forward, out hit, teleporterMaxHorizontal, laserMask)) { //disabledAimerObject.SetActive(false); teleportAimerObject.GetComponent <Renderer>().material.color = new Color(.42f, .82f, .56f, .39f); canTeleport = true; teleportLocation = hit.point; //laser.SetPosition(1, teleportLocation); //aimer position teleportAimerObject.transform.position = new Vector3(teleportLocation.x, teleportLocation.y + yNudgeAmount, teleportLocation.z); } else { //disabledAimerObject.SetActive(true); //laser.gameObject.SetActive(false); teleportAimerObject.SetActive(false); canTeleport = false; teleportLocation = new Vector3(transform.forward.x * teleporterMaxHorizontal + transform.position.x, transform.forward.y * teleporterMaxHorizontal + transform.position.y, transform.forward.z * teleporterMaxHorizontal + transform.position.z); RaycastHit groundRay; if (Physics.Raycast(teleportLocation, -Vector3.up, out groundRay, teleporterMaxVertical, laserMask)) { //disabledAimerObject.SetActive(false); //laser.gameObject.SetActive(true); teleportAimerObject.SetActive(true); canTeleport = true; teleportLocation = new Vector3(transform.forward.x * teleporterMaxHorizontal + transform.position.x, groundRay.point.y, transform.forward.z * teleporterMaxHorizontal + transform.position.z); } //laser.SetPosition(1, transform.forward * teleporterMaxHorizontal + transform.position); //aimer teleportAimerObject.transform.position = teleportLocation + new Vector3(0, yNudgeAmount, 0); } } } if (leftDevice.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad) && leftController) { //disabledAimerObject.SetActive(false); //laser.gameObject.SetActive(false); teleportAimerObject.SetActive(false); if (canTeleport) { if (useDash) { dashStartPosition = player.transform.position; isDashing = true; } else { player.transform.position = new Vector3(teleportLocation.x + xOffset, teleportLocation.y + playerHeight, teleportLocation.z + zOffset); } } } /**** End Teleportation ****/ }
// Update is called once per frame void Update() { if (isHit) { // If the player has been hit, rumble the controller for the designated time threshold controller.TriggerHapticPulse(2000); rumbleTimer += Time.deltaTime; if (rumbleTimer > rumbleDelay) { isHit = false; rumbleTimer = 0; } } // Check if the controller has been intialised if (controller == null) { Debug.Log("Controller not initialized."); return; } // Check if the menu button has been pressed if (controller.GetPressDown(menuButton)) { GameObject.FindGameObjectWithTag("GameManager").GetComponent <GameManager>().isPausingNext = true; } // If the button is pressed, pick up the object if (controller.GetPressDown(triggerButton)) { if (obj.tag == "SpawnBox") { GameObject objectClone; GameObject spawnClone = obj.GetComponent <SpawnBoxController>().spawnObject; objectClone = Instantiate(spawnClone, transform.position, transform.rotation); objectClone.GetComponent <Rigidbody>().isKinematic = false; obj = objectClone; fJoint.connectedBody = objectClone.GetComponent <Rigidbody>(); } print("triggered!"); PickUpObj(); } // If the button is not pressed, drop the object if (controller.GetPressUp(triggerButton)) { DropObj(); } if (obj != null && obj.tag != "SpawnBox") { // For melee weapons, if the held/detected object is a certain colour, change all the rest of its pieces to that colour if (obj.GetComponentInParent <MeleeHandler>() != null) { if (obj.transform.GetChild(0).GetComponent <MeshRenderer>().material != obj.GetComponentInParent <MeleeHandler>().OutlineMaterial) { obj.GetComponentInParent <MeleeHandler>().OutlineMaterial = obj.transform.GetChild(0).GetComponent <MeshRenderer>().material; } } // EASTER EGG: if the object contains a hidden sound, change the BGM to it if (obj.GetComponent <ProjectileHandler>().hiddenSound != null) { if (gameOverseer.Music != obj.GetComponent <ProjectileHandler>().hiddenSound) { gameOverseer.Music = obj.GetComponent <ProjectileHandler>().hiddenSound; } // Otherwise, change it back to the ordinary music } else if (gameOverseer.bgmObj.clip != gameOverseer.normalBGM) { gameOverseer.Music = gameOverseer.normalBGM; } } }
public override void OnUpdate() { var i = -1; if ((int)trackedObj.index > i++) { device = SteamVR_Controller.Input((int)trackedObj.index); switch (menuType) { case setMenuType.getPress: var padDown = device.GetTouchUp(SteamVR_Controller.ButtonMask.ApplicationMenu); if (padDown) { Fsm.Event(sendEvent); } storeResult.Value = padDown; break; case setMenuType.getPressUp: var padDownUp = device.GetPressUp(SteamVR_Controller.ButtonMask.ApplicationMenu); if (padDownUp) { Fsm.Event(sendEvent); } storeResult.Value = padDownUp; break; case setMenuType.getPressDown: var padDownDown = device.GetPressDown(SteamVR_Controller.ButtonMask.ApplicationMenu); if (padDownDown) { Fsm.Event(sendEvent); } storeResult.Value = padDownDown; break; case setMenuType.getTouch: var padTouch = device.GetTouch(SteamVR_Controller.ButtonMask.ApplicationMenu); if (padTouch) { Fsm.Event(sendEvent); } storeResult.Value = padTouch; break; case setMenuType.getTouchUp: var padTouchUp = device.GetTouchUp(SteamVR_Controller.ButtonMask.ApplicationMenu); if (padTouchUp) { Fsm.Event(sendEvent); } storeResult.Value = padTouchUp; break; case setMenuType.getTouchDown: var padTouchDown = device.GetTouchDown(SteamVR_Controller.ButtonMask.ApplicationMenu); if (padTouchDown) { Fsm.Event(sendEvent); } storeResult.Value = padTouchDown; break; } } }
private void Update() { controllerIndex = (uint)trackedController.index; //Only continue if the controller index has been set to a sensible number //SteamVR seems to put the index to the uint max value if it can't find the controller if (controllerIndex >= uint.MaxValue) { return; } device = SteamVR_Controller.Input((int)controllerIndex); Vector2 currentTriggerAxis = device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger); Vector2 currentTouchpadAxis = device.GetAxis(); //Trigger Pressed if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { OnTriggerPressed(SetButtonEvent(ref triggerPressed, true, currentTriggerAxis.x)); EmitAlias(ButtonAlias.Trigger_Press, true, currentTriggerAxis.x, ref triggerPressed); } else if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { OnTriggerReleased(SetButtonEvent(ref triggerPressed, false, 0f)); EmitAlias(ButtonAlias.Trigger_Press, false, 0f, ref triggerPressed); } //Trigger Touched if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger)) { OnTriggerTouchStart(SetButtonEvent(ref triggerTouched, true, currentTriggerAxis.x)); EmitAlias(ButtonAlias.Trigger_Touch, true, currentTriggerAxis.x, ref triggerTouched); } else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger)) { OnTriggerTouchEnd(SetButtonEvent(ref triggerTouched, false, 0f)); EmitAlias(ButtonAlias.Trigger_Touch, false, 0f, ref triggerTouched); } //Trigger Hairline if (device.GetHairTriggerDown()) { OnTriggerHairlineStart(SetButtonEvent(ref triggerHairlinePressed, true, currentTriggerAxis.x)); EmitAlias(ButtonAlias.Trigger_Hairline, true, currentTriggerAxis.x, ref triggerHairlinePressed); } else if (device.GetHairTriggerUp()) { OnTriggerHairlineEnd(SetButtonEvent(ref triggerHairlinePressed, false, 0f)); EmitAlias(ButtonAlias.Trigger_Hairline, false, 0f, ref triggerHairlinePressed); } //Trigger Clicked if (!triggerClicked && currentTriggerAxis.x == 1f) { OnTriggerClicked(SetButtonEvent(ref triggerClicked, true, currentTriggerAxis.x)); EmitAlias(ButtonAlias.Trigger_Click, true, currentTriggerAxis.x, ref triggerClicked); } else if (triggerClicked && currentTriggerAxis.x < 1f) { OnTriggerUnclicked(SetButtonEvent(ref triggerClicked, false, 0f)); EmitAlias(ButtonAlias.Trigger_Click, false, 0f, ref triggerClicked); } //Trigger Axis if (Vector2ShallowEquals(triggerAxis, currentTriggerAxis)) { triggerAxisChanged = false; } else { OnTriggerAxisChanged(SetButtonEvent(ref triggerAxisChanged, true, currentTriggerAxis.x)); } //ApplicationMenu if (device.GetPressDown(SteamVR_Controller.ButtonMask.ApplicationMenu)) { OnApplicationMenuPressed(SetButtonEvent(ref applicationMenuPressed, true, 1f)); EmitAlias(ButtonAlias.Application_Menu, true, 1f, ref applicationMenuPressed); } else if (device.GetPressUp(SteamVR_Controller.ButtonMask.ApplicationMenu)) { OnApplicationMenuReleased(SetButtonEvent(ref applicationMenuPressed, false, 0f)); EmitAlias(ButtonAlias.Application_Menu, false, 0f, ref applicationMenuPressed); } //Grip if (device.GetPressDown(SteamVR_Controller.ButtonMask.Grip)) { OnGripPressed(SetButtonEvent(ref gripPressed, true, 1f)); EmitAlias(ButtonAlias.Grip, true, 1f, ref gripPressed); } else if (device.GetPressUp(SteamVR_Controller.ButtonMask.Grip)) { OnGripReleased(SetButtonEvent(ref gripPressed, false, 0f)); EmitAlias(ButtonAlias.Grip, false, 0f, ref gripPressed); } //Touchpad Pressed if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad)) { OnTouchpadPressed(SetButtonEvent(ref touchpadPressed, true, 1f)); EmitAlias(ButtonAlias.Touchpad_Press, true, 1f, ref touchpadPressed); } else if (device.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad)) { OnTouchpadReleased(SetButtonEvent(ref touchpadPressed, false, 0f)); EmitAlias(ButtonAlias.Touchpad_Press, false, 0f, ref touchpadPressed); } //Touchpad Touched if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Touchpad)) { OnTouchpadTouchStart(SetButtonEvent(ref touchpadTouched, true, 1f)); EmitAlias(ButtonAlias.Touchpad_Touch, true, 1f, ref touchpadTouched); } else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Touchpad)) { OnTouchpadTouchEnd(SetButtonEvent(ref touchpadTouched, false, 0f)); EmitAlias(ButtonAlias.Touchpad_Touch, false, 0f, ref touchpadTouched); } if (Vector2ShallowEquals(touchpadAxis, currentTouchpadAxis)) { touchpadAxisChanged = false; } else { OnTouchpadAxisChanged(SetButtonEvent(ref touchpadTouched, true, 1f)); touchpadAxisChanged = true; } // Save current touch and trigger settings to detect next change. touchpadAxis = new Vector2(currentTouchpadAxis.x, currentTouchpadAxis.y); triggerAxis = new Vector2(currentTriggerAxis.x, currentTriggerAxis.y); hairTriggerDelta = device.hairTriggerDelta; }
// Update is called once per frame void Update() { // return if I am not a hunter player if (!isActive || !isLocalPlayer) return; // Flags for determining controller state per frame bool leftActive = true; bool leftTriggerPulled = false; bool rightTriggerPulled = false; bool leftGripPressed = false; bool rightGripPressed = false; // Setup Vive Controller try { rightController = SteamVR_Controller.Input((int)rightTrackedObject.index); rightTriggerPulled = rightController.GetPressDown(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger); rightGripPressed = rightController.GetPressDown(Valve.VR.EVRButtonId.k_EButton_Grip); } catch (System.Exception) { Debug.Log ("No controllers Connected"); } bool triggersPulled = (leftTriggerPulled || rightTriggerPulled); bool gripsPressed = (leftGripPressed || rightGripPressed); // waiting for some time at the beginning of the game // such that the hiders have enough time to hide if (waiting) { int secondsElapsed = (int)Time.timeSinceLevelLoad; if (secondsElapsed < 15) { UIText.text = "Wait for " + (15 - secondsElapsed) + " second(s)"; return; } else { waiting = false; GetComponent<myViveController>().enabled = true; } } // return if game is over if (timer.GameOver()) { GetComponent<myPlayerController>().enabled = false; UIText.text = "Game Over!"; GetComponent<PointCounter> ().stopCounting (); return; } // time counter: can only shoot when a certain amount of time (FireRate) has passed timeCounter += Time.deltaTime; // Raycasting - used for shooting and opening doors if (isServer) { //Ray leftControllerRay = new Ray (leftTrackedObject.transform.position, leftTrackedObject.transform.forward); Ray rightControllerRay = new Ray (rightTrackedObject.transform.position, rightTrackedObject.transform.forward); RaycastHit objectHit; GameObject obj = null; if (Physics.Raycast(rightControllerRay, out objectHit, ShootDistance)) { obj = objectHit.transform.gameObject; // if aiming at a player if (obj.tag.Equals("Player")) { } else if (obj.tag.Equals("Door") && objectHit.distance < InteractDistance) { UIText.text = "Press the trigger button to open/close the door"; // VIVE REIMPLEMENT if (triggersPulled) { GetComponent<AudioSource>().PlayOneShot(doorSound, 2f); doorController.CmdMoveDoor(obj); } } else { UIText.text = ""; } } else { UIText.text = ""; } // VIVE REIMPLEMENT if (triggersPulled && timeCounter > FireRate) { // reset time counter timeCounter = 0.0f; // play the gun sound effect GetComponent<AudioSource>().Play(); // Haptic feedback! rightController.TriggerHapticPulse (1200); if (obj != null && obj.tag.Equals("Player")) { GameObject playerHit = obj; playerHit.GetComponent<PropController>().TakeDamage(Damage); this.gameObject.GetComponent<PointCounter> ().addKillPoints (); Debug.Log("Hit: " + playerHit); } } } else { Ray camRay = myCamera.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2)); RaycastHit objectHit; GameObject obj = null; if (Physics.Raycast(camRay, out objectHit, ShootDistance)) { obj = objectHit.transform.gameObject; // if aiming at a player if (obj.tag.Equals("Player")) { } else if (obj.tag.Equals("Door") && objectHit.distance < InteractDistance) { UIText.text = "Press the Grip button to open/close the door"; // VIVE REIMPLEMENT if (triggersPulled) { GetComponent<AudioSource>().PlayOneShot(doorSound, 2f); doorController.CmdMoveDoor(obj); } } else { UIText.text = ""; } } else { UIText.text = ""; } // VIVE REIMPLEMENT if (triggersPulled && timeCounter > FireRate) { // reset time counter timeCounter = 0.0f; rightController.TriggerHapticPulse(700); // play the gun sound effect GetComponent<AudioSource>().Play(); if (obj != null && obj.tag.Equals("Player")) { GameObject playerHit = obj; playerHit.GetComponent<PropController>().TakeDamage(Damage); Debug.Log("Hit: " + playerHit); } } } }
// 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); } ); }
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); }
private void OnTriggerStay(Collider other) { if (other.gameObject.CompareTag("Rubish") || other.gameObject.CompareTag("Beer") || other.gameObject.CompareTag("Packet") || other.gameObject.CompareTag("BBQ") || other.gameObject.CompareTag("Stick") || other.gameObject.CompareTag("After")) { if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { ThrowObject(other); } else if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { GrabObject(other); other.GetComponentInChildren <NUmberPlay>().enabled = true; other.GetComponentInChildren <GameObject>().SetActive(true); } } if (other.gameObject.CompareTag("Bin")) { if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { Bin(other); } else if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { GrabObject(other); } } if (other.gameObject.CompareTag("Usa")) { if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { Bin(other); } else if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { Usa(other); } } if (other.gameObject.CompareTag("Button") && gameManager.score >= Reward) { if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { LitterStick(); LitterSticdelivered.Play(); StartCoroutine("Example"); intscore.number[2] = intscore.number[2] + 1; } } if (other.gameObject.CompareTag("Button1") && gameManager.score >= Reward1) { if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { ClimbingBoots(); bootsdelivered.Play(); RewardhasbeenclaimedBoots.text = "Reward has been claimed"; StartCoroutine("Example1"); } } if (other.gameObject.CompareTag("Buttonchose right")) { if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { Application.Quit(); Destroy(paneldecizLeftOnentry1); Destroy(paneldecizRightOnentry1); } } if (other.gameObject.CompareTag("ButtonChoseLeft")) { if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { Destroy(paneldecizLeftOnentry1); paneldecizRightOnentry1.SetActive(false); } } }
//updates for interaction hand implementation private void Update() { if (ControllerDevice == null) { return; } //menu if (ControllerDevice.GetPressDown(EVRButtonId.k_EButton_ApplicationMenu)) { OnButtonChanged(dynamic, isRight, "vive_menubtn", true, CurrentButtonStates); } if (ControllerDevice.GetPressUp(EVRButtonId.k_EButton_ApplicationMenu)) { OnButtonChanged(dynamic, isRight, "vive_menubtn", false, CurrentButtonStates); } //home ?? doesn't record event correctly //if (ControllerDevice.GetPressDown(EVRButtonId.k_EButton_Dashboard_Back)) // OnButtonChanged(dynamic, isRight, "vive_homebtn", true); //if (ControllerDevice.GetPressUp(EVRButtonId.k_EButton_Dashboard_Back)) // OnButtonChanged(dynamic, isRight, "vive_homebtn", false); //grip if (ControllerDevice.GetPressDown(EVRButtonId.k_EButton_Grip)) { OnButtonChanged(dynamic, isRight, "vive_grip", true, CurrentButtonStates); } if (ControllerDevice.GetPressUp(EVRButtonId.k_EButton_Grip)) { OnButtonChanged(dynamic, isRight, "vive_grip", false, CurrentButtonStates); } { //touchpad touched/pressed if (ControllerDevice.GetPressDown(EVRButtonId.k_EButton_SteamVR_Touchpad)) { CurrentTouchpadState = TouchpadState.Press; var touchpadaxis = ControllerDevice.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0); var x = touchpadaxis.x; var y = touchpadaxis.y; int force = 100; Vector3 currentVector = new Vector3(x, y, force); OnVectorChanged(dynamic, isRight, "vive_touchpad", force, touchpadaxis, CurrentButtonStates); LastTouchpadVector = currentVector; } else if (ControllerDevice.GetTouchDown(EVRButtonId.k_EButton_SteamVR_Touchpad)) { CurrentTouchpadState = TouchpadState.Touch; var touchpadaxis = ControllerDevice.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0); var x = touchpadaxis.x; var y = touchpadaxis.y; int force = 50; Vector3 currentVector = new Vector3(x, y, force); OnVectorChanged(dynamic, isRight, "vive_touchpad", force, touchpadaxis, CurrentButtonStates); LastTouchpadVector = currentVector; } else if (ControllerDevice.GetPressUp(EVRButtonId.k_EButton_SteamVR_Touchpad)) { CurrentTouchpadState = TouchpadState.Touch; var touchpadaxis = ControllerDevice.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0); var x = touchpadaxis.x; var y = touchpadaxis.y; int force = 0; if (ControllerDevice.GetTouch(Valve.VR.EVRButtonId.k_EButton_Axis0)) { force = 50; } Vector3 currentVector = new Vector3(x, y, force); OnVectorChanged(dynamic, isRight, "vive_touchpad", force, touchpadaxis, CurrentButtonStates); LastTouchpadVector = currentVector; } else if (ControllerDevice.GetTouchUp(EVRButtonId.k_EButton_SteamVR_Touchpad)) { CurrentTouchpadState = TouchpadState.None; var touchpadaxis = ControllerDevice.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0); var x = touchpadaxis.x; var y = touchpadaxis.y; int force = 0; Vector3 currentVector = new Vector3(x, y, force); OnVectorChanged(dynamic, isRight, "vive_touchpad", force, touchpadaxis, CurrentButtonStates); LastTouchpadVector = currentVector; } } //trigger clicked if (ControllerDevice.GetPressDown(EVRButtonId.k_EButton_SteamVR_Trigger)) { if (LastTrigger != 100) { var triggeramount = ControllerDevice.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger).x; int currentTrigger = (int)(triggeramount * 100); LastTrigger = currentTrigger; OnButtonChanged(dynamic, isRight, "vive_trigger", true, CurrentButtonStates); } } else if (ControllerDevice.GetPressUp(EVRButtonId.k_EButton_SteamVR_Trigger)) { if (LastTrigger != 0) { LastTrigger = 0; OnButtonChanged(dynamic, isRight, "vive_trigger", false, CurrentButtonStates); } } if (Time.time > nextUpdateTime) { RecordAnalogInputs(); //should this go at the end? double inputs on triggers nextUpdateTime = Time.time + UpdateRate; } if (CurrentButtonStates.Count > 0) { List <ButtonState> copy = new List <ButtonState>(CurrentButtonStates.Count); for (int i = 0; i < CurrentButtonStates.Count; i++) { copy.Add(CurrentButtonStates[i]); //move the reference over to the copy } CurrentButtonStates.Clear(); DynamicManager.RecordControllerEvent(dynamic.DataId, copy); } }
void Update() { controllerIndex = (uint)trackedController.index; device = SteamVR_Controller.Input((int)controllerIndex); Vector2 currentTriggerAxis = device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger); Vector2 currentTouchpadAxis = device.GetAxis(); if (Vector2ShallowEquals(triggerAxis, currentTriggerAxis)) { triggerAxisChanged = false; } else { OnTriggerAxisChanged(SetButtonEvent(ref triggerPressed, true, currentTriggerAxis.x)); triggerAxisChanged = true; } if (Vector2ShallowEquals(touchpadAxis, currentTouchpadAxis)) { touchpadAxisChanged = false; } else { OnTouchpadAxisChanged(SetButtonEvent(ref touchpadTouched, true, 1f)); touchpadAxisChanged = true; } touchpadAxis = new Vector2(currentTouchpadAxis.x, currentTouchpadAxis.y); triggerAxis = new Vector2(currentTriggerAxis.x, currentTriggerAxis.y); //Trigger if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger)) { OnTriggerClicked(SetButtonEvent(ref triggerPressed, true, currentTriggerAxis.x)); EmitAlias(ButtonAlias.Trigger, true, currentTriggerAxis.x, ref triggerPressed); } else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger)) { OnTriggerUnclicked(SetButtonEvent(ref triggerPressed, false, 0f)); EmitAlias(ButtonAlias.Trigger, false, 0f, ref triggerPressed); } //ApplicationMenu if (device.GetTouchDown(SteamVR_Controller.ButtonMask.ApplicationMenu)) { OnApplicationMenuClicked(SetButtonEvent(ref applicationMenuPressed, true, 1f)); EmitAlias(ButtonAlias.Application_Menu, true, 1f, ref applicationMenuPressed); } else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.ApplicationMenu)) { OnApplicationMenuUnclicked(SetButtonEvent(ref applicationMenuPressed, false, 0f)); EmitAlias(ButtonAlias.Application_Menu, false, 0f, ref applicationMenuPressed); } //Grip if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Grip)) { OnGripClicked(SetButtonEvent(ref gripPressed, true, 1f)); EmitAlias(ButtonAlias.Grip, true, 1f, ref gripPressed); } else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Grip)) { OnGripUnclicked(SetButtonEvent(ref gripPressed, false, 0f)); EmitAlias(ButtonAlias.Grip, false, 0f, ref gripPressed); } //Touchpad Clicked if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad)) { OnTouchpadClicked(SetButtonEvent(ref touchpadPressed, true, 1f)); EmitAlias(ButtonAlias.Touchpad_Press, true, 1f, ref touchpadPressed); } else if (device.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad)) { OnTouchpadUnclicked(SetButtonEvent(ref touchpadPressed, false, 0f)); EmitAlias(ButtonAlias.Touchpad_Press, false, 0f, ref touchpadPressed); } //Touchpad Touched if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Touchpad)) { OnTouchpadTouched(SetButtonEvent(ref touchpadTouched, true, 1f)); EmitAlias(ButtonAlias.Touchpad_Touch, true, 1f, ref touchpadTouched); } else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Touchpad)) { OnTouchpadUntouched(SetButtonEvent(ref touchpadTouched, false, 0f)); EmitAlias(ButtonAlias.Touchpad_Touch, false, 0f, ref touchpadTouched); } }
// Update is called once per frame private void Update() { if (GameController.GameState != State.Invalid && GameController.GameState != State.Loading) //Not loading or errored { //Fetch device states try { leftDevice = SteamVR_Controller.Input((int)leftTrackedObject.index); rightDevice = SteamVR_Controller.Input((int)rightTrackedObject.index); } catch (IndexOutOfRangeException) { return; } //Turn controls only work when the game is in the Running and Main Menu phases if (GameController.GameState == State.Running || GameController.GameState == State.MainMenu) { //Debug.Log("Normal Input Active"); Transform LNearest = GetNearestTurnable(LeftObject); if (leftDevice.GetPressDown(EVRButtonId.k_EButton_A) && Vector3.Distance(LeftObject.transform.position, LNearest.position) <= activationDistance) { //Debug.Log("Attempting to turn " + LNearest + " left"); LNearest.GetComponent <ITurnable>().TurnLeft(); } Transform RNearest = GetNearestTurnable(RightObject); if (rightDevice.GetPressDown(EVRButtonId.k_EButton_A) && Vector3.Distance(RightObject.transform.position, RNearest.position) <= activationDistance) { //Debug.Log("Attempting to turn " + RNearest + " right"); RNearest.GetComponent <ITurnable>().TurnRight(); } if (leftDevice.GetPressDown(EVRButtonId.k_EButton_ApplicationMenu) || rightDevice.GetPressDown(EVRButtonId.k_EButton_ApplicationMenu)) { GameController.PauseGame(); } } else if (GameController.GameState == State.Paused) { //Debug.Log("Menu Input Active"); if (leftDevice.GetPressDown(EVRButtonId.k_EButton_ApplicationMenu) || rightDevice.GetPressDown(EVRButtonId.k_EButton_ApplicationMenu)) { GameController.ResumeGame(); } if (rightDevice.GetPressDown(EVRButtonId.k_EButton_SteamVR_Trigger) && GetComponent <UIManager>().SelectedButton != null) { GetComponent <UIManager>().SelectedButton.OnSubmit(new BaseEventData(GetComponent <UIManager>().SelectedButton.transform.parent.parent.GetComponent <EventSystem>())); } } Vector2 stickValue = leftDevice.GetAxis(EVRButtonId.k_EButton_SteamVR_Touchpad); Vector3 movementValue = new Vector3(stickValue.x, 0, stickValue.y); GameObject head = CamRig.transform.Find("Camera (eye)").gameObject; movementValue = (head.transform.rotation * movementValue).normalized; movementValue.y = 0; movementValue.Normalize(); CamRig.GetComponent <Rigidbody>().velocity = movementValue * speed; //If TP system isn't resetting if (teleportState != TeleportState.Deactivating) { //If one is pushed and the other isn't if (leftDevice.GetPress(EVRButtonId.k_EButton_SteamVR_Touchpad) ^ rightDevice.GetPress(EVRButtonId.k_EButton_SteamVR_Touchpad)) { //If left is pushed if (leftDevice.GetPress(EVRButtonId.k_EButton_SteamVR_Touchpad)) { teleportState = TeleportState.LTargeting; ShowArc(leftObject); //Show Arc L } //If button is released and we're targeting left if (leftDevice.GetPressUp(EVRButtonId.k_EButton_SteamVR_Touchpad) && teleportState == TeleportState.LTargeting) { //Teleport L } //If right is pushed if (rightDevice.GetPress(EVRButtonId.k_EButton_SteamVR_Touchpad)) { teleportState = TeleportState.RTargeting; ShowArc(rightObject); //Show Arc R } //If the button is released and we're targeting right if (rightDevice.GetPressUp(EVRButtonId.k_EButton_SteamVR_Touchpad) && teleportState == TeleportState.RTargeting) { //Teleport R } } //If both are pushed else if (leftDevice.GetPress(EVRButtonId.k_EButton_SteamVR_Touchpad) && rightDevice.GetPress(EVRButtonId.k_EButton_SteamVR_Touchpad)) { //Set to deactivate teleportState = TeleportState.Deactivating; } } if (teleportState == TeleportState.Deactivating) { if (!leftDevice.GetPress(EVRButtonId.k_EButton_SteamVR_Touchpad) && !rightDevice.GetPress(EVRButtonId.k_EButton_SteamVR_Touchpad)) { teleportState = TeleportState.Inactive; } } } }
private void Update() { GetCurrentController(); // Erstma wieder Controller festlegen #region interact with object if (currentController != null && pickup != null && stayInHand && currentController.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) // Muss am Anfang hier stehen, da sonst der Trigger bereits ein Mal ausgelöst würde { if (currentController.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { var scriptAccess = pickup.GetComponent <PickableObject>(); scriptAccess.interact(); } } #endregion//_______________________________________________________________________ if (currentController != null) { #region controllerVisible #endregion #region das Objekt aufheben // Objekt aufnehmen und festlegen, ob es ein gehaltenes Objekt ist if (pickup == null && currentController.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { reachableObjects(); if (pickup != null) { var scriptAccess = pickup.GetComponent <PickableObject>(); stayInHand = scriptAccess.stayInHand; // gleich loslassen oder halten scriptAccess.switchPhysics(); pickup.SetParent(transform); scriptAccess.takePosition(); } } #endregion//_____________________________________________________________________________ #region Objekt fallen lassen, wenn es nicht interaktiv ist // Wenn das Objekt kein interaktives ist, dann muss der Trigger losgelassen werden, um das Objekt fallen zu lassen else if (pickup != null && !stayInHand && currentController.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { if (pickup != null) { var scriptAccess = pickup.GetComponent <PickableObject>(); dropObject(); scriptAccess.addVelocity(currentController.velocity, currentController.angularVelocity); // Methode des Objects } } #endregion//___________________________________________________________________________________ #region Objekt fallen lassen, wenn es interaktiv ist //Wenn das Objekt ein interaktives ist, dann muss der Grip Button gedrückt werden, um das Objekt fallen zu lassen else if (pickup != null && stayInHand && currentController.GetPressDown(SteamVR_Controller.ButtonMask.Grip)) { if (pickup != null) // Überprüft, ob es ein Gegenstand ist, der gleich wieder losgelassen wird { var scriptAccess = pickup.GetComponent <PickableObject>(); dropObject(); scriptAccess.addVelocity(currentController.velocity, currentController.angularVelocity); // Methode des Objects } } #endregion//_____________________________________________________________________________________ } }
private void ProcessControls(bool vrControls) { bool triggerCooldown = false; BeatMap.EditorState currentState = BeatMap.GetCurrentState(); if (vrControls && steamVRController.GetPressDown(EVRButtonId.k_EButton_SteamVR_Trigger) || Input.GetKeyDown(KeyCode.Space) && !vrControls) { triggerDown = true; if (!BeatMap.Inverted) { map.InvertNotes(); } } else if (vrControls && steamVRController.GetPressUp(EVRButtonId.k_EButton_SteamVR_Trigger) || Input.GetKeyUp(KeyCode.Space) && !vrControls) { triggerDown = false; if (BeatMap.Inverted) { map.InvertNotes(); } } else if (vrControls && steamVRController.GetPressDown(EVRButtonId.k_EButton_ApplicationMenu) || Input.GetKeyDown(KeyCode.A) && !vrControls) { menuButtonDown = true; bool bothControllersPressing = otherSaber.menuButtonDown; if (bothControllersPressing) { if (currentState == BeatMap.EditorState.Editing || currentState == BeatMap.EditorState.PlaybackPaused) { map.ResumeSong(); triggerCooldown = true; return; } else if (currentState == BeatMap.EditorState.Playback || currentState == BeatMap.EditorState.Recording) { map.PauseSong(); triggerCooldown = true; return; } } else { if (currentState == BeatMap.EditorState.Editing) { if (selector.GetAttachedObject() != null) { Note note = selector.GetAttachedObject().GetComponent <Note>(); if (note != null) { if (!note.noteDetails.inverted) { note.MakeNeutral(); if (isLeft) { note.Invert(true); } DetachSelector(); triggerCooldown = true; } } } } } } else if (vrControls && steamVRController.GetPressUp(EVRButtonId.k_EButton_ApplicationMenu) || Input.GetKeyUp(KeyCode.A) && !vrControls) { menuButtonDown = false; } if (vrControls && steamVRController.GetPressDown(EVRButtonId.k_EButton_SteamVR_Touchpad) || Input.GetKeyDown(KeyCode.Y) && !vrControls) { } if (vrControls && steamVRController.GetTouchDown(EVRButtonId.k_EButton_SteamVR_Touchpad) || Input.GetKeyDown(KeyCode.T) && !vrControls) { if (currentState == BeatMap.EditorState.Recording) { BeatMap.currentNoteMode = BeatMap.NoteMode.HalfNote; } } else if (vrControls && steamVRController.GetTouchUp(EVRButtonId.k_EButton_SteamVR_Touchpad) || Input.GetKeyUp(KeyCode.T) && !vrControls) { if (currentState == BeatMap.EditorState.Recording) { BeatMap.currentNoteMode = BeatMap.NoteMode.WholeNote; } } if (vrControls && steamVRController.GetPressDown(EVRButtonId.k_EButton_Grip) || Input.GetKeyDown(KeyCode.G) && !vrControls) { if (gripHeldFor == 0) // Fresh push { if (selector.HasTarget()) { BeatMap.Log("Calling Grab on object " + selector.GetAttachedObject().name); Grab(selector.GetAttachedObject()); if (selector.GetAttachedObject().GetComponent <MiniMap>() != null) { map.PauseSong(); } triggerCooldown = true; } } gripHeldFor += Time.deltaTime; } else if (vrControls && steamVRController.GetPressUp(EVRButtonId.k_EButton_Grip) || Input.GetKeyUp(KeyCode.G) && !vrControls) { BeatMap.Log("Grip let go, grabbing? " + grabbing); gripHeldFor = 0; if (grabbing) { UnGrab(); triggerCooldown = true; } } // KEYBOARD ONLY // if (!vrControls) { if (Input.GetKeyDown(KeyCode.W)) { transform.position += transform.forward; } else if (Input.GetKeyDown(KeyCode.A)) { transform.position += -transform.right; } else if (Input.GetKeyDown(KeyCode.S)) { transform.position += -transform.forward; } else if (Input.GetKeyDown(KeyCode.D)) { transform.position += transform.right; } else if (Input.GetKeyDown(KeyCode.Q)) { transform.position += transform.up; } else if (Input.GetKeyDown(KeyCode.E)) { transform.position += -transform.up; } else if (Input.GetKeyDown(KeyCode.RightArrow)) { BeatMap.SkipToBeat(BeatMap.GetCurrentBeat() + 10); } else if (Input.GetKeyDown(KeyCode.LeftArrow)) { BeatMap.SkipToBeat(BeatMap.GetCurrentBeat() - 10); } else if (Input.GetKeyDown(KeyCode.P) && !IsOnCoolDown() && isLeft) { triggerCooldown = true; if (BeatMap.GetCurrentState() == BeatMap.EditorState.Editing) { map.ResumeSong(); } else if (BeatMap.GetCurrentState() == BeatMap.EditorState.PlaybackPaused) { map.ResumeSong(); } else if (BeatMap.GetCurrentState() == BeatMap.EditorState.Playback) { map.PauseSong(); } else if (BeatMap.GetCurrentState() == BeatMap.EditorState.Recording) { map.PauseSong(); } } } if (triggerCooldown) { currentCooldown += Time.deltaTime; } }
// Update is called once per frame void Update() { if (input.GetPressDown(Valve.VR.EVRButtonId.k_EButton_A)) { obj = ObjectPooler.current.getPooledObject(); growBalloon(obj, 1); } else if (input.GetPressDown(Valve.VR.EVRButtonId.k_EButton_Grip)) { obj = ObjectPooler.current.getPooledObject(); growBalloon(obj, 2); } else if (input.GetPressDown(Valve.VR.EVRButtonId.k_EButton_ApplicationMenu)) { obj = ObjectPooler.current.getPooledObject(); growBalloon(obj, 3); } else if (input.GetPressDown(1ul << 8)) { obj = ObjectPooler.current.getPooledObject(); growBalloon(obj, 4); } else if (input.GetPressDown(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad)) { part.transform.position = gameObject.transform.position; part.transform.rotation = gameObject.transform.rotation; part.transform.forward = gameObject.transform.forward; part.Clear(); part.Stop(); part.Play(); } else if (input.GetPressDown(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger)) { laser = true; } if (input.GetPress(Valve.VR.EVRButtonId.k_EButton_A)) { growBalloon(obj, 1); } else if (input.GetPress(Valve.VR.EVRButtonId.k_EButton_Grip)) { growBalloon(obj, 2); } else if (input.GetPress(Valve.VR.EVRButtonId.k_EButton_ApplicationMenu)) { growBalloon(obj, 3); } else if (input.GetPress(1ul << 8)) { growBalloon(obj, 4); } if (input.GetPressUp(Valve.VR.EVRButtonId.k_EButton_A)) { releaseBalloon(obj); } else if (input.GetPressUp(Valve.VR.EVRButtonId.k_EButton_Grip)) { releaseBalloon(obj); } else if (input.GetPressUp(Valve.VR.EVRButtonId.k_EButton_ApplicationMenu)) { releaseBalloon(obj); } else if (input.GetPressUp(1ul << 8)) { releaseBalloon(obj); } if (input.GetPressUp(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger)) { laser = false; GetComponent <LineRenderer>().SetPosition(0, transform.position); GetComponent <LineRenderer>().SetPosition(1, transform.position); } if (laser) { RaycastHit collide; bool hit = Physics.Raycast(gameObject.transform.position, gameObject.transform.forward, out collide, 100); if (hit) { if (collide.collider.tag.Equals("projectile")) { collide.collider.gameObject.GetComponent <DestroyBalloon>().RemoveBalloon(); } } GetComponent <LineRenderer>().SetPosition(0, transform.position); GetComponent <LineRenderer>().SetPosition(1, transform.position + transform.forward * 2f); } }
public override void OnUpdate() { var i = -1; if ((int)trackedObj.index > i++) { device = SteamVR_Controller.Input((int)trackedObj.index); switch (touchpadType) { case setTouchpadType.getPress: var padDown = device.GetTouchUp(SteamVR_Controller.ButtonMask.Touchpad); if (padDown) { Fsm.Event(sendEvent); } storeResult.Value = padDown; break; case setTouchpadType.getPressUp: var padDownUp = device.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad); if (padDownUp) { Fsm.Event(sendEvent); } storeResult.Value = padDownUp; break; case setTouchpadType.getPressDown: var padDownDown = device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad); if (padDownDown) { Fsm.Event(sendEvent); } storeResult.Value = padDownDown; break; case setTouchpadType.getTouch: var padTouch = device.GetTouch(SteamVR_Controller.ButtonMask.Touchpad); if (padTouch) { Fsm.Event(sendEvent); } storeResult.Value = padTouch; break; case setTouchpadType.getTouchUp: var padTouchUp = device.GetTouchUp(SteamVR_Controller.ButtonMask.Touchpad); if (padTouchUp) { Fsm.Event(sendEvent); } storeResult.Value = padTouchUp; break; case setTouchpadType.getTouchDown: var padTouchDown = device.GetTouchDown(SteamVR_Controller.ButtonMask.Touchpad); if (padTouchDown) { Fsm.Event(sendEvent); } storeResult.Value = padTouchDown; break; } } }
private void Update() { controllerIndex = (uint)trackedController.index; device = SteamVR_Controller.Input((int)controllerIndex); Vector2 currentTriggerAxis = device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger); Vector2 currentTouchpadAxis = device.GetAxis(); //Trigger if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger)) { OnTriggerPressed(SetButtonEvent(ref triggerPressed, true, currentTriggerAxis.x)); EmitAlias(ButtonAlias.Trigger, true, currentTriggerAxis.x, ref triggerPressed); } else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger)) { OnTriggerReleased(SetButtonEvent(ref triggerPressed, false, 0f)); EmitAlias(ButtonAlias.Trigger, false, 0f, ref triggerPressed); } else { if (Vector2ShallowEquals(triggerAxis, currentTriggerAxis)) { triggerAxisChanged = false; } else { OnTriggerAxisChanged(SetButtonEvent(ref triggerAxisChanged, true, currentTriggerAxis.x)); } } //ApplicationMenu if (device.GetTouchDown(SteamVR_Controller.ButtonMask.ApplicationMenu)) { OnApplicationMenuPressed(SetButtonEvent(ref applicationMenuPressed, true, 1f)); EmitAlias(ButtonAlias.Application_Menu, true, 1f, ref applicationMenuPressed); } else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.ApplicationMenu)) { OnApplicationMenuReleased(SetButtonEvent(ref applicationMenuPressed, false, 0f)); EmitAlias(ButtonAlias.Application_Menu, false, 0f, ref applicationMenuPressed); } //Grip if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Grip)) { OnGripPressed(SetButtonEvent(ref gripPressed, true, 1f)); EmitAlias(ButtonAlias.Grip, true, 1f, ref gripPressed); } else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Grip)) { OnGripReleased(SetButtonEvent(ref gripPressed, false, 0f)); EmitAlias(ButtonAlias.Grip, false, 0f, ref gripPressed); } //Touchpad Pressed if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad)) { OnTouchpadPressed(SetButtonEvent(ref touchpadPressed, true, 1f)); EmitAlias(ButtonAlias.Touchpad_Press, true, 1f, ref touchpadPressed); } else if (device.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad)) { OnTouchpadReleased(SetButtonEvent(ref touchpadPressed, false, 0f)); EmitAlias(ButtonAlias.Touchpad_Press, false, 0f, ref touchpadPressed); } //Touchpad Touched if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Touchpad)) { OnTouchpadTouchStart(SetButtonEvent(ref touchpadTouched, true, 1f)); EmitAlias(ButtonAlias.Touchpad_Touch, true, 1f, ref touchpadTouched); } else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Touchpad)) { OnTouchpadTouchEnd(SetButtonEvent(ref touchpadTouched, false, 0f)); EmitAlias(ButtonAlias.Touchpad_Touch, false, 0f, ref touchpadTouched); } else { if (Vector2ShallowEquals(touchpadAxis, currentTouchpadAxis)) { touchpadAxisChanged = false; } else { OnTouchpadAxisChanged(SetButtonEvent(ref touchpadTouched, true, 1f)); touchpadAxisChanged = true; } } // Save current touch and trigger settings to detect next change. touchpadAxis = new Vector2(currentTouchpadAxis.x, currentTouchpadAxis.y); triggerAxis = new Vector2(currentTriggerAxis.x, currentTriggerAxis.y); }
void FixedUpdate() { device = SteamVR_Controller.Input((int)trackedObj.index); if (menuActive) { switch (orientation) { case 0: side1.GetComponent <MeshRenderer>().material = matArray[next, 0]; side2.GetComponent <MeshRenderer>().material = defaultMat; side3.GetComponent <MeshRenderer>().material = matArray[prev, 0]; side4.GetComponent <MeshRenderer>().material = matArray[current, 1]; break; case 1: side1.GetComponent <MeshRenderer>().material = matArray[current, 1]; side2.GetComponent <MeshRenderer>().material = matArray[next, 0]; side3.GetComponent <MeshRenderer>().material = defaultMat; side4.GetComponent <MeshRenderer>().material = matArray[prev, 0]; break; case 2: side1.GetComponent <MeshRenderer>().material = matArray[prev, 0]; side2.GetComponent <MeshRenderer>().material = matArray[current, 1]; side3.GetComponent <MeshRenderer>().material = matArray[next, 0]; side4.GetComponent <MeshRenderer>().material = defaultMat; break; case 3: side1.GetComponent <MeshRenderer>().material = defaultMat; side2.GetComponent <MeshRenderer>().material = matArray[prev, 0]; side3.GetComponent <MeshRenderer>().material = matArray[current, 1]; side4.GetComponent <MeshRenderer>().material = matArray[next, 0]; break; default: Debug.Log("orientation not valid"); break; } } // show timeline interactor if (device.GetPressUp(SteamVR_Controller.ButtonMask.ApplicationMenu)) { // display Cube if (!menuActive) { sceneSwitcher.SetActive(true); menuActive = true; switchSceneOK = true; switcherActive = true; } // hide Cube else { sceneSwitcher.SetActive(false); menuActive = false; switchSceneOK = false; switcherActive = false; } } // Select Scene if (device.GetPressDown(SteamVR_Controller.ButtonMask.Grip) && switchSceneOK) { sceneSwitcher.SetActive(false); menuActive = false; switchSceneOK = false; switcherActive = false; // Set current position as start position for next scene SetStartposition.position = camrig.transform.position; SetStartposition.currentYear = current; // switch to currently selected scene & get to default position switchScene(current); } /* * if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad) && device.GetAxis().y >= 0.0f && switchSceneOK) * { * sceneSwitcher.SetActive(false); * menuActive = false; * switchSceneOK = false; * switcherActive = false; * * // Set default Position as start position for next scene * SetStartposition.position = SetStartposition.defaultposition; * * // switch to currently selected scene & get to default position * switchScene(current); * } * * if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad) && device.GetAxis().y < 0.0f && switchSceneOK) * { * sceneSwitcher.SetActive(false); * menuActive = false; * switchSceneOK = false; * switcherActive = false; * * // Set current position as start position for next scene * SetStartposition.position = camrig.transform.position; * SetStartposition.currentYear = current; * * // switch to currently selected scene & keep current position * switchScene(current); * } */ /* * // Switch to Test scene * if (device.GetPress(SteamVR_Controller.ButtonMask.Grip) && switchSceneOK) * { * sceneSwitcher.SetActive(false); * menuActive = false; * switchSceneOK = false; * switcherActive = false; * * SetStartposition.currentYear = current; * SceneManager.LoadScene(testscene); * } */ // Checks for Touchpad touch swipe if (device.GetTouch(SteamVR_Controller.ButtonMask.Touchpad) && menuActive) { if (!touched) { touched = true; x_move = device.GetAxis().x; } else { x_current = device.GetAxis().x; movement = x_move - x_current; // Set Rotation angle Transform transform = sceneSwitcher.transform; sceneSwitcher.transform.Rotate(0.0f, movement * speed, 0.0f); x_move = x_current; // get current position based on movement current_rot += movement * speed; // get values from 0 to 3 to get current orientation of cube orientation = (int)current_rot / 90; // korrektur divison neg zahlen if (current_rot > 0) { orientation += 1; } orientation %= 4; if (orientation < 0) { orientation += 4; } // get values from 0 to size -1 for current exhibition current = (int)current_rot / 90; // korrektur divison neg zahlen if (current_rot > 0) { current += 1; } current %= size; if (current < 0) { current += size; } next = (current + 1) % size; prev = (current - 1 + size) % size; } } // reset x_move to zero when touch is released if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Touchpad)) { x_move = 0.0f; touched = false; } }