OpenVR.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. #if UNITY_INPUT_SYSTEM_ENABLE_XR && !DISABLE_BUILTIN_INPUT_SYSTEM_OPENVR && !PACKAGE_DOCS_GENERATION
  2. using UnityEngine.InputSystem;
  3. using UnityEngine.InputSystem.Controls;
  4. using UnityEngine.InputSystem.Layouts;
  5. using UnityEngine.InputSystem.XR;
  6. using UnityEngine.Scripting;
  7. namespace Unity.XR.OpenVR
  8. {
  9. [InputControlLayout(displayName = "OpenVR Headset")]
  10. [Preserve]
  11. public class OpenVRHMD : XRHMD
  12. {
  13. [InputControl(noisy = true)]
  14. [Preserve]
  15. public Vector3Control deviceVelocity { get; private set; }
  16. [InputControl(noisy = true)]
  17. [Preserve]
  18. public Vector3Control deviceAngularVelocity { get; private set; }
  19. [InputControl(noisy = true)]
  20. [Preserve]
  21. public Vector3Control leftEyeVelocity { get; private set; }
  22. [InputControl(noisy = true)]
  23. [Preserve]
  24. public Vector3Control leftEyeAngularVelocity { get; private set; }
  25. [InputControl(noisy = true)]
  26. [Preserve]
  27. public Vector3Control rightEyeVelocity { get; private set; }
  28. [InputControl(noisy = true)]
  29. [Preserve]
  30. public Vector3Control rightEyeAngularVelocity { get; private set; }
  31. [InputControl(noisy = true)]
  32. [Preserve]
  33. public Vector3Control centerEyeVelocity { get; private set; }
  34. [InputControl(noisy = true)]
  35. [Preserve]
  36. public Vector3Control centerEyeAngularVelocity { get; private set; }
  37. protected override void FinishSetup()
  38. {
  39. base.FinishSetup();
  40. deviceVelocity = GetChildControl<Vector3Control>("deviceVelocity");
  41. deviceAngularVelocity = GetChildControl<Vector3Control>("deviceAngularVelocity");
  42. leftEyeVelocity = GetChildControl<Vector3Control>("leftEyeVelocity");
  43. leftEyeAngularVelocity = GetChildControl<Vector3Control>("leftEyeAngularVelocity");
  44. rightEyeVelocity = GetChildControl<Vector3Control>("rightEyeVelocity");
  45. rightEyeAngularVelocity = GetChildControl<Vector3Control>("rightEyeAngularVelocity");
  46. centerEyeVelocity = GetChildControl<Vector3Control>("centerEyeVelocity");
  47. centerEyeAngularVelocity = GetChildControl<Vector3Control>("centerEyeAngularVelocity");
  48. }
  49. }
  50. [InputControlLayout(displayName = "Windows MR Controller (OpenVR)", commonUsages = new[] { "LeftHand", "RightHand" })]
  51. [Preserve]
  52. public class OpenVRControllerWMR : XRController
  53. {
  54. [InputControl(noisy = true)]
  55. [Preserve]
  56. public Vector3Control deviceVelocity { get; private set; }
  57. [InputControl(noisy = true)]
  58. [Preserve]
  59. public Vector3Control deviceAngularVelocity { get; private set; }
  60. [InputControl(aliases = new[] { "primary2DAxisClick", "joystickOrPadPressed" })]
  61. [Preserve]
  62. public ButtonControl touchpadClick { get; private set; }
  63. [InputControl(aliases = new[] { "primary2DAxisTouch", "joystickOrPadTouched" })]
  64. [Preserve]
  65. public ButtonControl touchpadTouch { get; private set; }
  66. [InputControl]
  67. [Preserve]
  68. public ButtonControl gripPressed { get; private set; }
  69. [InputControl]
  70. public ButtonControl triggerPressed { get; private set; }
  71. [InputControl(aliases = new[] { "primary" })]
  72. [Preserve]
  73. public ButtonControl menu { get; private set; }
  74. [InputControl]
  75. [Preserve]
  76. public AxisControl trigger { get; private set; }
  77. [InputControl]
  78. [Preserve]
  79. public AxisControl grip { get; private set; }
  80. [InputControl(aliases = new[] { "secondary2DAxis" })]
  81. [Preserve]
  82. public Vector2Control touchpad { get; private set; }
  83. [InputControl(aliases = new[] { "primary2DAxis" })]
  84. [Preserve]
  85. public Vector2Control joystick { get; private set; }
  86. protected override void FinishSetup()
  87. {
  88. base.FinishSetup();
  89. deviceVelocity = GetChildControl<Vector3Control>("deviceVelocity");
  90. deviceAngularVelocity = GetChildControl<Vector3Control>("deviceAngularVelocity");
  91. touchpadClick = GetChildControl<ButtonControl>("touchpadClick");
  92. touchpadTouch = GetChildControl<ButtonControl>("touchpadTouch");
  93. gripPressed = GetChildControl<ButtonControl>("gripPressed");
  94. triggerPressed = GetChildControl<ButtonControl>("triggerPressed");
  95. menu = GetChildControl<ButtonControl>("menu");
  96. trigger = GetChildControl<AxisControl>("trigger");
  97. grip = GetChildControl<AxisControl>("grip");
  98. touchpad = GetChildControl<Vector2Control>("touchpad");
  99. joystick = GetChildControl<Vector2Control>("joystick");
  100. }
  101. }
  102. /// <summary>
  103. /// An HTC Vive Wand controller.
  104. /// </summary>
  105. [InputControlLayout(displayName = "Vive Wand", commonUsages = new[] { "LeftHand", "RightHand" })]
  106. [Preserve]
  107. public class ViveWand : XRControllerWithRumble
  108. {
  109. [InputControl]
  110. [Preserve]
  111. public AxisControl grip { get; private set; }
  112. [InputControl]
  113. [Preserve]
  114. public ButtonControl gripPressed { get; private set; }
  115. [InputControl]
  116. [Preserve]
  117. public ButtonControl primary { get; private set; }
  118. [InputControl(aliases = new[] { "primary2DAxisClick", "joystickOrPadPressed" })]
  119. [Preserve]
  120. public ButtonControl trackpadPressed { get; private set; }
  121. [InputControl(aliases = new[] { "primary2DAxisTouch", "joystickOrPadTouched" })]
  122. [Preserve]
  123. public ButtonControl trackpadTouched { get; private set; }
  124. [InputControl(aliases = new[] { "Primary2DAxis" })]
  125. [Preserve]
  126. public Vector2Control trackpad { get; private set; }
  127. [InputControl]
  128. [Preserve]
  129. public AxisControl trigger { get; private set; }
  130. [InputControl]
  131. [Preserve]
  132. public ButtonControl triggerPressed { get; private set; }
  133. [InputControl(noisy = true)]
  134. [Preserve]
  135. public Vector3Control deviceVelocity { get; private set; }
  136. [InputControl(noisy = true)]
  137. [Preserve]
  138. public Vector3Control deviceAngularVelocity { get; private set; }
  139. protected override void FinishSetup()
  140. {
  141. base.FinishSetup();
  142. grip = GetChildControl<AxisControl>("grip");
  143. primary = GetChildControl<ButtonControl>("primary");
  144. gripPressed = GetChildControl<ButtonControl>("gripPressed");
  145. trackpadPressed = GetChildControl<ButtonControl>("trackpadPressed");
  146. trackpadTouched = GetChildControl<ButtonControl>("trackpadTouched");
  147. trackpad = GetChildControl<Vector2Control>("trackpad");
  148. trigger = GetChildControl<AxisControl>("trigger");
  149. triggerPressed = GetChildControl<ButtonControl>("triggerPressed");
  150. deviceVelocity = GetChildControl<Vector3Control>("deviceVelocity");
  151. deviceAngularVelocity = GetChildControl<Vector3Control>("deviceAngularVelocity");
  152. }
  153. }
  154. /// <summary>
  155. /// An HTC Vive lighthouse.
  156. /// </summary>
  157. [InputControlLayout(displayName = "Vive Lighthouse")]
  158. [Preserve]
  159. public class ViveLighthouse : TrackedDevice
  160. {
  161. }
  162. /// <summary>
  163. /// An HTC Vive tracker.
  164. /// </summary>
  165. [InputControlLayout(displayName = "Vive Tracker")]
  166. [Preserve]
  167. public class ViveTracker : TrackedDevice
  168. {
  169. [InputControl(noisy = true)]
  170. [Preserve]
  171. public Vector3Control deviceVelocity { get; private set; }
  172. [InputControl(noisy = true)]
  173. [Preserve]
  174. public Vector3Control deviceAngularVelocity { get; private set; }
  175. protected override void FinishSetup()
  176. {
  177. base.FinishSetup();
  178. deviceVelocity = GetChildControl<Vector3Control>("deviceVelocity");
  179. deviceAngularVelocity = GetChildControl<Vector3Control>("deviceAngularVelocity");
  180. }
  181. }
  182. [InputControlLayout(displayName = "Handed Vive Tracker", commonUsages = new[] { "LeftHand", "RightHand" })]
  183. [Preserve]
  184. public class HandedViveTracker : ViveTracker
  185. {
  186. [InputControl]
  187. [Preserve]
  188. public AxisControl grip { get; private set; }
  189. [InputControl]
  190. [Preserve]
  191. public ButtonControl gripPressed { get; private set; }
  192. [InputControl]
  193. [Preserve]
  194. public ButtonControl primary { get; private set; }
  195. [InputControl(aliases = new[] { "JoystickOrPadPressed" })]
  196. [Preserve]
  197. public ButtonControl trackpadPressed { get; private set; }
  198. [InputControl]
  199. [Preserve]
  200. public ButtonControl triggerPressed { get; private set; }
  201. protected override void FinishSetup()
  202. {
  203. grip = GetChildControl<AxisControl>("grip");
  204. primary = GetChildControl<ButtonControl>("primary");
  205. gripPressed = GetChildControl<ButtonControl>("gripPressed");
  206. trackpadPressed = GetChildControl<ButtonControl>("trackpadPressed");
  207. triggerPressed = GetChildControl<ButtonControl>("triggerPressed");
  208. base.FinishSetup();
  209. }
  210. }
  211. /// <summary>
  212. /// An Oculus Touch controller.
  213. /// </summary>
  214. [InputControlLayout(displayName = "Oculus Touch Controller (OpenVR)", commonUsages = new[] { "LeftHand", "RightHand" })]
  215. [Preserve]
  216. public class OpenVROculusTouchController : XRControllerWithRumble
  217. {
  218. [InputControl]
  219. [Preserve]
  220. public Vector2Control thumbstick { get; private set; }
  221. [InputControl]
  222. [Preserve]
  223. public AxisControl trigger { get; private set; }
  224. [InputControl]
  225. [Preserve]
  226. public AxisControl grip { get; private set; }
  227. // Primary & Secondary are switched in order to retain consistency with the Oculus SDK
  228. [InputControl(aliases = new[] { "Alternate" })]
  229. [Preserve]
  230. public ButtonControl primaryButton { get; private set; }
  231. [InputControl(aliases = new[] { "Primary" })]
  232. [Preserve]
  233. public ButtonControl secondaryButton { get; private set; }
  234. [InputControl]
  235. [Preserve]
  236. public ButtonControl gripPressed { get; private set; }
  237. [InputControl()]
  238. [Preserve]
  239. public ButtonControl triggerPressed { get; private set; }
  240. [InputControl(aliases = new[] { "primary2DAxisClicked" })]
  241. [Preserve]
  242. public ButtonControl thumbstickClicked { get; private set; }
  243. [InputControl(aliases = new[] { "primary2DAxisTouch" })]
  244. [Preserve]
  245. public ButtonControl thumbstickTouched { get; private set; }
  246. [InputControl(noisy = true)]
  247. [Preserve]
  248. public Vector3Control deviceVelocity { get; private set; }
  249. [InputControl(noisy = true)]
  250. [Preserve]
  251. public Vector3Control deviceAngularVelocity { get; private set; }
  252. protected override void FinishSetup()
  253. {
  254. base.FinishSetup();
  255. thumbstick = GetChildControl<Vector2Control>("thumbstick");
  256. trigger = GetChildControl<AxisControl>("trigger");
  257. grip = GetChildControl<AxisControl>("grip");
  258. primaryButton = GetChildControl<ButtonControl>("primaryButton");
  259. secondaryButton = GetChildControl<ButtonControl>("secondaryButton");
  260. gripPressed = GetChildControl<ButtonControl>("gripPressed");
  261. thumbstickClicked = GetChildControl<ButtonControl>("thumbstickClicked");
  262. thumbstickTouched = GetChildControl<ButtonControl>("thumbstickTouched");
  263. triggerPressed = GetChildControl<ButtonControl>("triggerPressed");
  264. deviceVelocity = GetChildControl<Vector3Control>("deviceVelocity");
  265. deviceAngularVelocity = GetChildControl<Vector3Control>("deviceAngularVelocity");
  266. }
  267. }
  268. }
  269. #endif