NxrControllerModel.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using UnityEngine;
  2. namespace Nxr.Internal
  3. {
  4. public class NxrControllerModel : MonoBehaviour
  5. {
  6. NxrTrackedDevice trackedDevice;
  7. Transform touchpad;
  8. Transform menu;
  9. Transform system;
  10. Transform grip_left;
  11. Transform grip_right;
  12. Transform trigger;
  13. // Use this for initialization
  14. void OnEnable()
  15. {
  16. trackedDevice = GetComponentInParent<NxrTrackedDevice>();
  17. touchpad = transform.Find("buttons/button_touchpad");
  18. menu = transform.Find("buttons/button_menu");
  19. system = transform.Find("buttons/button_system");
  20. grip_left = transform.Find("buttons/button_grip_left");
  21. grip_right = transform.Find("buttons/button_grip_right");
  22. trigger = transform.Find("buttons/button_trigger");
  23. }
  24. // Update is called once per frame
  25. void Update()
  26. {
  27. if (trackedDevice == null) return;
  28. if (trackedDevice.GetButtonPressed(NxrTrackedDevice.ButtonID.TouchPad))
  29. {
  30. TouchPad_Down();
  31. }
  32. else
  33. {
  34. TouchPad_Up();
  35. }
  36. if (trackedDevice.GetButtonPressed(NxrTrackedDevice.ButtonID.Menu))
  37. {
  38. Menu_Down();
  39. }
  40. else
  41. {
  42. Menu_Up();
  43. }
  44. if (trackedDevice.GetButtonPressed(NxrTrackedDevice.ButtonID.System))
  45. {
  46. System_Down();
  47. }
  48. else
  49. {
  50. System_Up();
  51. }
  52. if (trackedDevice.GetButtonPressed(NxrTrackedDevice.ButtonID.Grip))
  53. {
  54. Grip_Down();
  55. }
  56. else
  57. {
  58. Grip_Up();
  59. }
  60. if (trackedDevice.GetButtonPressed(NxrTrackedDevice.ButtonID.Trigger))
  61. {
  62. Trigger_Down();
  63. }
  64. else
  65. {
  66. Trigger_Up();
  67. }
  68. }
  69. //touchpad
  70. void TouchPad_Down()
  71. {
  72. if(touchpad != null) touchpad.transform.localPosition = new Vector3(0, -1, 0);
  73. }
  74. void TouchPad_Up()
  75. {
  76. if (touchpad != null) touchpad.transform.localPosition = Vector3.zero;
  77. }
  78. //menu
  79. void Menu_Down()
  80. {
  81. if (menu != null) menu.transform.localPosition = new Vector3(0, -1, 0);
  82. }
  83. void Menu_Up()
  84. {
  85. if (menu != null) menu.transform.localPosition = Vector3.zero;
  86. }
  87. //system
  88. void System_Down()
  89. {
  90. if (system != null) system.transform.localPosition = new Vector3(0, -1, 0);
  91. }
  92. void System_Up()
  93. {
  94. if (system != null) system.transform.localPosition = Vector3.zero;
  95. }
  96. //trigger
  97. void Trigger_Down()
  98. {
  99. if (trigger != null) trigger.transform.localPosition = new Vector3(0, 12, -5);
  100. if (trigger != null) trigger.transform.localRotation = Quaternion.Euler(-20, 0, 0);
  101. }
  102. void Trigger_Up()
  103. {
  104. if (trigger != null) trigger.transform.localPosition = Vector3.zero;
  105. if (trigger != null) trigger.transform.localRotation = Quaternion.identity;
  106. }
  107. //grip
  108. void Grip_Down()
  109. {
  110. if (grip_left != null) grip_left.transform.localPosition = new Vector3(1, 0, 0);
  111. if (grip_right != null) grip_right.transform.localPosition = new Vector3(-1, 0, 0);
  112. }
  113. void Grip_Up()
  114. {
  115. if (grip_left != null) grip_left.transform.localPosition = Vector3.zero;
  116. if (grip_right != null) grip_right.transform.localPosition = Vector3.zero;
  117. }
  118. }
  119. }