protected virtual void ReadInput() { DepressedButtons = 0; ScrollDelta = Vector2.zero; if (!nodeState.tracked) { return; } var leftClick = VRInput.GetAxis(nodeState, InputAxis.MainTrigger); if (leftClick > .9f) { DepressedButtons |= MouseButton.Left; } var rightClick = VRInput.GetAxis(nodeState, InputAxis.Grip); if (rightClick > .5f) { DepressedButtons |= MouseButton.Right; } switch (VRInput.GetJoypadType(nodeState)) { case JoyPadType.Joystick: ReadJoystick(); break; case JoyPadType.TouchPad: ReadTouchpad(); break; } }
protected virtual void ReadTouchpad() { var touchPoint = new Vector2(VRInput.GetAxis(nodeState, InputAxis.JoypadX), VRInput.GetAxis(nodeState, InputAxis.JoypadY)); var touchButton = VRInput.GetTouch(nodeState, InputAxis.Joypad) > .5f; if (touchButton) { var delta = touchPoint - lastTouchPoint; if (!touchIsScrolling) { if (delta.magnitude * trackpadScrollSpeed > scrollThreshold) { touchIsScrolling = true; lastTouchPoint = touchPoint; } else { //don't start updating the touch point yet } } else { ScrollDelta = new Vector2(-delta.x, delta.y) * trackpadScrollSpeed; lastTouchPoint = touchPoint; } } else { ScrollDelta = new Vector2(); lastTouchPoint = touchPoint; touchIsScrolling = false; } }
protected virtual void ReadJoystick() { ScrollDelta = new Vector2(); var offset = new Vector2( -VRInput.GetAxis(nodeState, InputAxis.JoypadX), VRInput.GetAxis(nodeState, InputAxis.JoypadY) ); offset.x = Mathf.Abs(offset.x) > scrollThreshold ? offset.x - Mathf.Sign(offset.x) * scrollThreshold : 0; offset.y = Mathf.Abs(offset.y) > scrollThreshold ? offset.y - Mathf.Sign(offset.y) * scrollThreshold : 0; offset = offset * offset.magnitude * joystickScrollSpeed * Time.deltaTime; ScrollDelta = offset; }
private void Update() { Vector3 newVel = Vector3.Lerp(velocity, Vector3.zero, acceleration); float x = VRInput.GetAxis(VRButton.LeftThumbHorizontal); float z = VRInput.GetAxis(VRButton.LeftThumbVertical); print("X: " + x); print("Z: " + z); newVel.x += x; newVel.z += z; velocity = Vector3.ClampMagnitude(newVel, maxSpeed); transform.Translate(velocity * Time.deltaTime); }
protected virtual void ReadInput() { DepressedButtons = 0; ScrollDelta = Vector2.zero; if (!nodeState.tracked) { return; } var leftClick = input.GetAxis(nodeState, InputAxis.LeftClick); if (leftClick > .9f) { DepressedButtons |= MouseButton.Left; } var middleClick = input.GetAxis(nodeState, InputAxis.MiddleClick); if (middleClick > .5f) { DepressedButtons |= MouseButton.Middle; } var rightClick = input.GetAxis(nodeState, InputAxis.RightClick); if (rightClick > .5f) { DepressedButtons |= MouseButton.Right; } var joyTypes = input.GetJoypadTypes(nodeState); if ((joyTypes & JoyPadType.Joystick) != 0) { ReadJoystick(); } if ((joyTypes & JoyPadType.TouchPad) != 0) { ReadTouchpad(); } }
static void Postfix(InputAction action, ref float __result) { __result += VRInput.GetAxis(action); }
void CheckKey() { float vert = VRInput.GetAxis(VRButton.RightThumbVertical); float horiz = VRInput.GetAxis(VRButton.RightThumbHorizontal); //if(Mathf.Abs(vert) >= Mathf.Abs(horiz)) //{ //float x = Mathf.Sin(rot[1] * Mathf.Deg2Rad); //float z = Mathf.Cos(rot[1] * Mathf.Deg2Rad); Vector3 velocity = Vector3.forward * vert; if (velocity.magnitude != 0) { anim.SetBool("Walk_Anim", true); } else { anim.SetBool("Walk_Anim", false); } transform.Translate(velocity * Time.deltaTime); //} else //{ //anim.SetBool("Walk_Anim", false); rot[1] += rotSpeed * Time.fixedDeltaTime * horiz; //} // Walk if (Input.GetKey(KeyCode.W)) { anim.SetBool("Walk_Anim", true); } else if (Input.GetKeyUp(KeyCode.W)) { anim.SetBool("Walk_Anim", false); } // Rotate Left if (Input.GetKey(KeyCode.A)) { rot[1] -= rotSpeed * Time.fixedDeltaTime; } // Rotate Right if (Input.GetKey(KeyCode.D)) { rot[1] += rotSpeed * Time.fixedDeltaTime; } // Roll if (Input.GetKeyDown(KeyCode.Space)) { if (anim.GetBool("Roll_Anim")) { anim.SetBool("Roll_Anim", false); } else { anim.SetBool("Roll_Anim", true); } } // Close if (Input.GetKeyDown(KeyCode.LeftControl)) { if (!anim.GetBool("Open_Anim")) { anim.SetBool("Open_Anim", true); } else { anim.SetBool("Open_Anim", false); } } }
private void AxisStateLabel(VRButton button) { UnityGUI.Label(button.ToString() + ": " + VRInput.GetAxis(button).ToString("0.000")); }