OVRTouchpad.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using UnityEngine;
  3. namespace OvrLip
  4. {
  5. internal static class OVRTouchpad
  6. {
  7. public static void Create()
  8. {
  9. }
  10. public static void Update()
  11. {
  12. if (NInput.GetMouseButtonDown(0))
  13. {
  14. OVRTouchpad.moveAmountMouse = Input.mousePosition;
  15. }
  16. else if (NInput.GetMouseButtonUp(0))
  17. {
  18. OVRTouchpad.moveAmountMouse -= Input.mousePosition;
  19. OVRTouchpad.HandleInputMouse(ref OVRTouchpad.moveAmountMouse);
  20. }
  21. }
  22. public static void OnDisable()
  23. {
  24. }
  25. private static void HandleInputMouse(ref Vector3 move)
  26. {
  27. if (move.magnitude < OVRTouchpad.minMovMagnitudeMouse)
  28. {
  29. OVRMessenger.Broadcast<OVRTouchpad.TouchEvent>("Touchpad", OVRTouchpad.TouchEvent.SingleTap);
  30. }
  31. else
  32. {
  33. move.Normalize();
  34. if (Mathf.Abs(move.x) > Mathf.Abs(move.y))
  35. {
  36. if (move.x > 0f)
  37. {
  38. OVRMessenger.Broadcast<OVRTouchpad.TouchEvent>("Touchpad", OVRTouchpad.TouchEvent.Left);
  39. }
  40. else
  41. {
  42. OVRMessenger.Broadcast<OVRTouchpad.TouchEvent>("Touchpad", OVRTouchpad.TouchEvent.Right);
  43. }
  44. }
  45. else if (move.y > 0f)
  46. {
  47. OVRMessenger.Broadcast<OVRTouchpad.TouchEvent>("Touchpad", OVRTouchpad.TouchEvent.Down);
  48. }
  49. else
  50. {
  51. OVRMessenger.Broadcast<OVRTouchpad.TouchEvent>("Touchpad", OVRTouchpad.TouchEvent.Up);
  52. }
  53. }
  54. }
  55. private static Vector3 moveAmountMouse;
  56. private static float minMovMagnitudeMouse = 25f;
  57. private static OVRTouchpadHelper touchpadHelper = new GameObject("OVRTouchpadHelper").AddComponent<OVRTouchpadHelper>();
  58. public enum TouchEvent
  59. {
  60. SingleTap,
  61. DoubleTap,
  62. Left,
  63. Right,
  64. Up,
  65. Down
  66. }
  67. }
  68. }