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; } }
void Update() { device = SteamVR_Controller.Input((int)trackedObj.index); if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { tracker.OnGrab(transform, handModel); } else if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { tracker.OnDrop(handModel, device.velocity * throwForce); } }
void CheckGripButtonIsHoldingDown() { if (handController.GetPress(SteamVR_Controller.ButtonMask.Grip)) { isBeingGrabbed = true; bounceTargetPosition = handObj.transform.position; dynamicTargetPosition = bounceTargetPosition; } else if (handController.GetPressUp(SteamVR_Controller.ButtonMask.Grip)) { isBeingGrabbed = false; } }
// Update is called once per frame void Update() { device = SteamVR_Controller.Input((int)trackedObj.index); if (device.GetPressDown(SteamVR_Controller.ButtonMask.ApplicationMenu)) { toolTips.SetActive(true); } else if (device.GetPressUp(SteamVR_Controller.ButtonMask.ApplicationMenu)) { toolTips.SetActive(false); } }
void FixedUpdate() { dev = SteamVR_Controller.Input((int)trackedObj.index); if (dev.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad)) { Debug.Log("PressUp the touchpad"); Debug.Log("Reset sphere position and velocity..."); sphere.transform.position = Vector3.zero; sphere.GetComponent <Rigidbody>().velocity = Vector3.zero; sphere.GetComponent <Rigidbody>().angularVelocity = Vector3.zero; } }
/// <summary> /// Get the Steam VR button press up state. /// </summary> /// <param name="buttonMask">Button Mask</param> /// <returns>Press up state</returns> public bool GetPressUp(ulong buttonMask) { if (CurrentInputMode == RVInputMode.Playback) { SteamVRInputInfo inputInfo = CurrentRecording.HasCurrentFrame() ? CurrentRecording.CurrentFrame.GetInputInfo(DeviceIndex, buttonMask.ToString()) : null; return(inputInfo == null ? false : inputInfo.PressUpState); } bool stateValue = m_DeviceImpl.GetPressUp(buttonMask); if (CurrentInputMode == RVInputMode.Record) { SteamVRInputInfo inputInfo = CurrentRecording.CurrentFrame.GetInputInfo(DeviceIndex, buttonMask.ToString()); if (inputInfo == null) { inputInfo = new SteamVRInputInfo(); } inputInfo.PressUpState = stateValue; CurrentRecording.CurrentFrame.AddInputInfo(DeviceIndex, buttonMask.ToString(), inputInfo); } return(stateValue); }
public static bool VRInputUpTrigger(ulong triggerMask) { if (!VR) { return(false); } SteamVR_Controller.Device device = GetVRDevice(); if (device == null) { return(false); } return(device.GetPressUp(triggerMask)); }
// 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()) { if (go == null) { go = GameObject.Find("Cube"); } //This line is the one that changes the value of photonView.isMine on the specified GameObject go.GetComponent <PhotonView> ().RequestOwnership(); go.GetComponent <TransformManager> ().SetNewParent(this.transform); } // Getting the Trigger Release if (Controller.GetHairTriggerUp()) { if (go == null) { go = GameObject.Find("Cube"); } // Make sure we have ownership before we do anything the the objects go.GetComponent <PhotonView> ().RequestOwnership(); go.GetComponent <TransformManager>().DetachParent(); } // Getting the Grip Press if (Controller.GetPressDown(SteamVR_Controller.ButtonMask.Grip)) { Debug.Log(gameObject.name + " Grip Press"); PhotonNetwork.Instantiate(spherePrefab.name, new Vector3(0, 3, 0), Quaternion.identity, 0); } // Getting the Grip Release if (Controller.GetPressUp(SteamVR_Controller.ButtonMask.Grip)) { Debug.Log(gameObject.name + " Grip Release"); } }
void Update() { switch (currentState) { case GameState.defaultState: controller = SteamVR_Controller.Input((int)trackedObj.index); //get integer representation of the controller if (controller.GetPress(triggerButton)) { Debug.Log("Select!"); } else if (controller.GetPress(touchpadButton)) { Debug.Log("You have placed the note"); } break; case GameState.recordingState: controller = SteamVR_Controller.Input((int)trackedObj.index); //get integer representation of the controller if (controller.GetPressUp(triggerButton)) { renderChange = false; Debug.Log("Stopped Recording!"); } else if (controller.GetPress(triggerButton)) { renderChange = true; Debug.Log("Recording!"); controller.TriggerHapticPulse(700); } else if (controller.GetPress(touchpadButton)) { Debug.Log("You have placed the note"); } if (renderChange) { mic.SetActive(true); hand.SetActive(false); GetComponent <SteamVR_LaserPointer>().enabled = false; } else { mic.SetActive(false); hand.SetActive(true); GetComponent <SteamVR_LaserPointer>().enabled = true; } break; } }
// Teleport and Swipe Logic void Update() { device = SteamVR_Controller.Input((int)trackedObject.index); //Debug.Log(trackedObject.index); //Teleportation Logic (need to include logic to only allow for left controller) //{ //deploy laser on press if (device.GetPress(SteamVR_Controller.ButtonMask.Touchpad)) { laser.gameObject.SetActive(true); teleportAimerObject.SetActive(true); //on ray hit laser.SetPosition(0, gameObject.transform.position); //create variable to store ray info RaycastHit hit; if (Physics.Raycast(transform.position, transform.forward, out hit, 15, laserMask)) { //true on collision within 15 teleportLocation = hit.point; laser.SetPosition(1, teleportLocation); //aimer position teleportAimerObject.transform.position = new Vector3(teleportLocation.x, teleportLocation.y + yNudge, teleportLocation.z); } //on no hit, move forward 15 else { teleportLocation = new Vector3(transform.forward.x * 15 + transform.position.x, transform.forward.y * 15 + transform.position.y, transform.forward.z * 15 + transform.position.z); RaycastHit groundRay; if (Physics.Raycast(teleportLocation, -Vector3.up, out groundRay, 17, laserMask)) { teleportLocation = new Vector3(transform.forward.x * 15 + transform.position.x, groundRay.point.y, transform.forward.z * 15 + transform.position.z); } laser.SetPosition(1, transform.forward * 15 + transform.position); //aimer teleportAimerObject.transform.position = teleportLocation + new Vector3(0, yNudge, 0); } } //teleport on press up if (device.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad)) { laser.gameObject.SetActive(false); teleportAimerObject.SetActive(false); //move player //if(factory.GetComponent<Collider>().bounds.Contains(teleportLocation) && teleportLocation.y < 1); player.transform.position = teleportLocation; } //} }
// Update is called once per frame void FixedUpdate() { device = SteamVR_Controller.Input((int)trackedObj.index); if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You are holding 'Touch' on the Trigger"); } if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("Activated 'TouchDown' on the Trigger"); } if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("Activated 'TouchUp' on the Trigger"); } if (device.GetPress(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You are holding 'GetPress' on the Trigger"); } if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("Activated 'PressDown' on the Trigger"); } if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("Activated 'PressUp' on the Trigger"); } if (device.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad)) { device.TriggerHapticPulse(1000); GameObject.Instantiate(prefabSphere); //sphere.transform.position = new Vector3(0, 0, 0); //sphere.GetComponent<Rigidbody>().velocity = Vector3.zero; //sphere.GetComponent<Rigidbody>().angularVelocity = Vector3.zero; } }
// Update is called once per frame void Update() { device = SteamVR_Controller.Input((int)trackedObj.index); if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("Activated 'PressDown' on the Trigger"); anim.SetBool("Walk", true); } else if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("Activated 'PressUP' on the Trigger"); anim.SetBool("Walk", false); } }
void OnTriggerStay(Collider col) { if (grabableObjects.Contains(col.gameObject.tag)) { if (controller.GetPressUp(SteamVR_Controller.ButtonMask.Grip)) { ReleaseAction(col); } else if (controller.GetPressDown(SteamVR_Controller.ButtonMask.Grip)) { GrabObject(col, transform); } } }
void OnTriggerStay(Collider col) { if (col.gameObject.CompareTag("Throwable") || col.gameObject.tag == "ObjectsWithMeshColliders") { if (device.GetPressUp(SteamVR_Controller.ButtonMask.Grip)) //release { ThrowObject(col); } else if (device.GetPressDown(SteamVR_Controller.ButtonMask.Grip)) //hold down { GrabObject(col); } } }
//------------------------------------------------- // Was the standard interaction button just released? In VR, this is a trigger press. In 2D fallback, this is a mouse left-click. //------------------------------------------------- public bool GetStandardInteractionButtonUp() { if (noSteamVRFallbackCamera) { return(Input.GetMouseButtonUp(0)); } else if (controller != null) { //return controller.GetHairTriggerUp(); return(controller.GetPressUp(EVRButtonId.k_EButton_Grip)); } return(false); }
void OnTriggerStay(Collider col) { if (col.gameObject.CompareTag("Throwable")) { if (device.GetPressUp(SteamVR_Controller.ButtonMask.Grip)) // throws nullreference exception at runtime { ThrowObject(col); } else if (device.GetPressDown(SteamVR_Controller.ButtonMask.Grip)) { GrabObject(col); } } }
void OnTriggerStay(Collider col) { if (col.gameObject.CompareTag("Throwable") || col.gameObject.CompareTag("Structure")) { if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { ThrowObject(col); } else if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { GrabObject(col); } } }
void OnTriggerStay(Collider col) { if (col.gameObject.CompareTag("grabable")) { if (controller.GetPressUp(SteamVR_Controller.ButtonMask.Grip)) { ThrowObject(col); } else if (controller.GetPressDown(SteamVR_Controller.ButtonMask.Grip)) { GrabObject(col); } } }
private void OnTriggerStay(Collider other) { if (other.gameObject.CompareTag("Throwable")) { if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { ThowObject(other); } else if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { GrabObject(other); } } }
public static bool GetPressUp(SteamVR_Controller.Device controller, ulong buttonType, Side handSide) { bool isIt = false; if (desktopMode) { isIt = GetMouseButtonUp(buttonType, handSide); } else if (controller != null) { isIt = controller.GetPressUp(buttonType); } return(isIt); }
void OnTriggerStay(Collider col) { if (col.gameObject.CompareTag("Throwable")) { if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { ThrowObject(col); } else if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { GrabObject(col); } } if (col.gameObject.CompareTag("Grabable")) { if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { DropObject(col); } else if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { GrabObject(col); } } if (col.gameObject.CompareTag("Flippable")) { handObject.GetComponent <Collider>().enabled = false; handObject.GetComponentInChildren <SkinnedMeshRenderer>().material = disabledColor; if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { FlipObject(col); } } }
private void Update() { if (Controller == null || CurrentHandState == HandState.Uninitialized) { return; } HoldButtonPressed = Controller.GetPress(HoldButton); HoldButtonDown = Controller.GetPressDown(HoldButton); HoldButtonUp = Controller.GetPressUp(HoldButton); UseButtonPressed = Controller.GetPress(UseButton); UseButtonDown = Controller.GetPressDown(UseButton); UseButtonUp = Controller.GetPressUp(UseButton); if (HoldButtonDown == true) { if (CurrentlyInteracting == null) { PickupClosest(); } } else if (HoldButtonUp == true && CurrentlyInteracting != null) { EndInteraction(null); } if (IsInteracting == true) { CurrentlyInteracting.InteractingUpdate(this); } if (VRIPlayer.Instance.PhysicalHands == true) { UpdateVisibilityAndColliders(); } }
// Update is called once per frame void Update() { SetFiringMode(); SetValuesByFiringMode(FiringMode); if (currentEnergy < maxEnergy && !isFiring) { currentEnergy += ChargeSpeed * Time.deltaTime; } UpdateRecoilTime(); device = SteamVR_Controller.Input((int)_trackedObject.index); if (!FullAuto) { if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { StartCoroutine(Burst()); } } if (FullAuto) { if (device.GetPress(SteamVR_Controller.ButtonMask.Trigger)) { isFiring = true; ShootBullet(); } if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { isFiring = false; } } if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad)) { if (device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad).x > 0.5f) { nextFiringMode = true; } if (device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad).x < 0.5f) { previousFiringMode = true; } } _audio.PlayOneShot(Shot, 1f); device.TriggerHapticPulse(3999); GetComponent <AudioSource>().PlayOneShot(C**k, 1f); }
public void OnManipulatorRightUpdated(SteamVR_Controller.Device state) { // right touchpad if (state.GetPress(EVRButtonId.k_EButton_SteamVR_Touchpad)) { Vector2 touchAxis = state.GetAxis(EVRButtonId.k_EButton_SteamVR_Touchpad); Vector3 fwdDirection = HmdRotation * Vector3.forward; fwdDirection.y = 0f; // allow only planar movement Vector3 fwdDisplacement = fwdDirection.normalized * (editorMovementSpeed * inverseWorldScale[HighLogic.LoadedScene] * touchAxis.y) * Time.deltaTime; Vector3 rightDirection = HmdRotation * Vector3.right; rightDirection.y = 0f; // allow only planar movement Vector3 rightDisplacement = rightDirection.normalized * (editorMovementSpeed * inverseWorldScale[HighLogic.LoadedScene] * touchAxis.x) * Time.deltaTime; CurrentPosition += fwdDisplacement + rightDisplacement; } // right menu button if (state.GetPressDown(EVRButtonId.k_EButton_ApplicationMenu)) { Core.ResetInitialHmdPosition(); } // simulate mouse touch events with the trigger if (state.GetPressDown(EVRButtonId.k_EButton_SteamVR_Trigger)) { foreach (var obj in DeviceManager.Instance.ManipulatorRight.FingertipCollidedGameObjects) { if (obj != null) { obj.SendMessage("OnMouseDown"); } } } if (state.GetPressUp(EVRButtonId.k_EButton_SteamVR_Trigger)) { foreach (var obj in DeviceManager.Instance.ManipulatorRight.FingertipCollidedGameObjects) { if (obj != null) { obj.SendMessage("OnMouseUp"); } } } }
/*** Grabbing and Throwing ****/ // To use this script, add colliders (say, sphere) to controller, enable Is Trigger, and decrease Radius to 0.2 // Then add rigidbody to controllers, setting Is Kinematic to true and Collison Detection to Continuous Dynamic. // Objects that you pick up should have colliders with rigidbody with collision detection set to Continuous and should have the Throwable tag on them private void OnTriggerStay(Collider col) { if (col.gameObject.CompareTag("Throwable")) { if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { ThrowObject(col); } else if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { // Normal grabbing functionality GrabObject(col); } } }
// Update is called once per physics step (consistant) void FixedUpdate() { device = SteamVR_Controller.Input((int)trackedObj.index); if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("you are Holding 'Touch' on the trigger"); } if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("you have acitvated touch down on the trigger"); } if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("you have acitvated touch up on the trigger"); } if (device.GetPress(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("you are Holding 'Press' on the trigger"); } if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("you have acitvated Press down on the trigger"); } if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("you have acitvated Press up on the trigger"); } if (device.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad)) //reset sphere position { Debug.Log("you have acitvated Press up on the Touchpad"); sphere.transform.position = new Vector3(0, 1, 0); //reset position sphere.GetComponent <Rigidbody>().velocity = Vector3.zero; // Vector3.zero short hand for: new Vector3(0,0,0) // reset veocoity so it stays still } }
void OnTriggerStay(Collider col) { if (col.gameObject.GetComponent <HandController>()) { SteamVR_Controller.Device device = col.gameObject.GetComponent <HandController>().device; if (device.GetPress(SteamVR_Controller.ButtonMask.Grip)) { lookAtTarget = col.gameObject.transform; } if (device.GetPressUp(SteamVR_Controller.ButtonMask.Grip)) { lookAtTarget = null; } } }
private ControllerState controllerEvents() { #if SteamVR_Legacy if (device.GetPressUp(SteamVR_Controller.ButtonMask.Axis0)) { return(ControllerState.TOUCHPAD_UP); } #elif SteamVR_2 if (m_touchpadPress.GetStateUp(trackedObj.inputSource)) { return(ControllerState.TOUCHPAD_UP); } #endif return(ControllerState.NONE); }
// Update is called once per frame void Update() { device = SteamVR_Controller.Input((int)tracked_object.index); if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("turn on spell"); SpellbookEnable(); } if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("turn off spell"); SpellbookDisable(); } }
private void OnTriggerStay(Collider col) { if (ScoreController.gameStarted && !ScoreController.gameEnded) { if (col.gameObject.tag == "Ball" && controller.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { col.attachedRigidbody.isKinematic = true; col.gameObject.transform.SetParent(gameObject.transform); } if (col.gameObject.tag == "Ball" && controller.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { throwBall(col); } } }
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; } }
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); }
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; } } }
// 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); } ); }