暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. // ENABLE_VR is not defined on Game Core but the assembly is available with limited features when the XR module is enabled.
  2. // Docs generation is skipped because these are intended to be replaced with the com.unity.xr.oculus package.
  3. #if UNITY_INPUT_SYSTEM_ENABLE_XR && (ENABLE_VR || UNITY_GAMECORE) && !DISABLE_BUILTIN_INPUT_SYSTEM_OCULUS && !UNITY_FORCE_INPUTSYSTEM_XR_OFF && !PACKAGE_DOCS_GENERATION
  4. using UnityEngine.InputSystem;
  5. using UnityEngine.InputSystem.Controls;
  6. using UnityEngine.InputSystem.Layouts;
  7. using UnityEngine.InputSystem.XR;
  8. namespace Unity.XR.Oculus.Input
  9. {
  10. /// <summary>
  11. /// An Oculus VR headset (such as the Oculus Rift series of devices).
  12. /// </summary>
  13. [InputControlLayout(displayName = "Oculus Headset", hideInUI = true)]
  14. public class OculusHMD : XRHMD
  15. {
  16. [InputControl]
  17. [InputControl(name = "trackingState", layout = "Integer", aliases = new[] { "devicetrackingstate" })]
  18. [InputControl(name = "isTracked", layout = "Button", aliases = new[] { "deviceistracked" })]
  19. public ButtonControl userPresence { get; protected set; }
  20. [InputControl(noisy = true)]
  21. public Vector3Control deviceAngularVelocity { get; protected set; }
  22. [InputControl(noisy = true)]
  23. public Vector3Control deviceAcceleration { get; protected set; }
  24. [InputControl(noisy = true)]
  25. public Vector3Control deviceAngularAcceleration { get; protected set; }
  26. [InputControl(noisy = true)]
  27. public Vector3Control leftEyeAngularVelocity { get; protected set; }
  28. [InputControl(noisy = true)]
  29. public Vector3Control leftEyeAcceleration { get; protected set; }
  30. [InputControl(noisy = true)]
  31. public Vector3Control leftEyeAngularAcceleration { get; protected set; }
  32. [InputControl(noisy = true)]
  33. public Vector3Control rightEyeAngularVelocity { get; protected set; }
  34. [InputControl(noisy = true)]
  35. public Vector3Control rightEyeAcceleration { get; protected set; }
  36. [InputControl(noisy = true)]
  37. public Vector3Control rightEyeAngularAcceleration { get; protected set; }
  38. [InputControl(noisy = true)]
  39. public Vector3Control centerEyeAngularVelocity { get; protected set; }
  40. [InputControl(noisy = true)]
  41. public Vector3Control centerEyeAcceleration { get; protected set; }
  42. [InputControl(noisy = true)]
  43. public Vector3Control centerEyeAngularAcceleration { get; protected set; }
  44. protected override void FinishSetup()
  45. {
  46. base.FinishSetup();
  47. userPresence = GetChildControl<ButtonControl>("userPresence");
  48. deviceAngularVelocity = GetChildControl<Vector3Control>("deviceAngularVelocity");
  49. deviceAcceleration = GetChildControl<Vector3Control>("deviceAcceleration");
  50. deviceAngularAcceleration = GetChildControl<Vector3Control>("deviceAngularAcceleration");
  51. leftEyeAngularVelocity = GetChildControl<Vector3Control>("leftEyeAngularVelocity");
  52. leftEyeAcceleration = GetChildControl<Vector3Control>("leftEyeAcceleration");
  53. leftEyeAngularAcceleration = GetChildControl<Vector3Control>("leftEyeAngularAcceleration");
  54. rightEyeAngularVelocity = GetChildControl<Vector3Control>("rightEyeAngularVelocity");
  55. rightEyeAcceleration = GetChildControl<Vector3Control>("rightEyeAcceleration");
  56. rightEyeAngularAcceleration = GetChildControl<Vector3Control>("rightEyeAngularAcceleration");
  57. centerEyeAngularVelocity = GetChildControl<Vector3Control>("centerEyeAngularVelocity");
  58. centerEyeAcceleration = GetChildControl<Vector3Control>("centerEyeAcceleration");
  59. centerEyeAngularAcceleration = GetChildControl<Vector3Control>("centerEyeAngularAcceleration");
  60. }
  61. }
  62. /// <summary>
  63. /// An Oculus Touch controller.
  64. /// </summary>
  65. [InputControlLayout(displayName = "Oculus Touch Controller", commonUsages = new[] { "LeftHand", "RightHand" }, hideInUI = true)]
  66. public class OculusTouchController : XRControllerWithRumble
  67. {
  68. [InputControl(aliases = new[] { "Primary2DAxis", "Joystick" })]
  69. public Vector2Control thumbstick { get; protected set; }
  70. [InputControl]
  71. public AxisControl trigger { get; protected set; }
  72. [InputControl]
  73. public AxisControl grip { get; protected set; }
  74. [InputControl(aliases = new[] { "A", "X", "Alternate" })]
  75. public ButtonControl primaryButton { get; protected set; }
  76. [InputControl(aliases = new[] { "B", "Y", "Primary" })]
  77. public ButtonControl secondaryButton { get; protected set; }
  78. [InputControl(aliases = new[] { "GripButton" })]
  79. public ButtonControl gripPressed { get; protected set; }
  80. [InputControl]
  81. public ButtonControl start { get; protected set; }
  82. [InputControl(aliases = new[] { "JoystickOrPadPressed", "thumbstickClick" })]
  83. public ButtonControl thumbstickClicked { get; protected set; }
  84. [InputControl(aliases = new[] { "ATouched", "XTouched", "ATouch", "XTouch" })]
  85. public ButtonControl primaryTouched { get; protected set; }
  86. [InputControl(aliases = new[] { "BTouched", "YTouched", "BTouch", "YTouch" })]
  87. public ButtonControl secondaryTouched { get; protected set; }
  88. [InputControl(aliases = new[] { "indexTouch", "indexNearTouched" })]
  89. public AxisControl triggerTouched { get; protected set; }
  90. [InputControl(aliases = new[] { "indexButton", "indexTouched" })]
  91. public ButtonControl triggerPressed { get; protected set; }
  92. [InputControl(aliases = new[] { "JoystickOrPadTouched", "thumbstickTouch" })]
  93. [InputControl(name = "trackingState", layout = "Integer", aliases = new[] { "controllerTrackingState" })]
  94. [InputControl(name = "isTracked", layout = "Button", aliases = new[] { "ControllerIsTracked" })]
  95. [InputControl(name = "devicePosition", layout = "Vector3", aliases = new[] { "controllerPosition" })]
  96. [InputControl(name = "deviceRotation", layout = "Quaternion", aliases = new[] { "controllerRotation" })]
  97. public ButtonControl thumbstickTouched { get; protected set; }
  98. [InputControl(noisy = true, aliases = new[] { "controllerVelocity" })]
  99. public Vector3Control deviceVelocity { get; protected set; }
  100. [InputControl(noisy = true, aliases = new[] { "controllerAngularVelocity" })]
  101. public Vector3Control deviceAngularVelocity { get; protected set; }
  102. [InputControl(noisy = true, aliases = new[] { "controllerAcceleration" })]
  103. public Vector3Control deviceAcceleration { get; protected set; }
  104. [InputControl(noisy = true, aliases = new[] { "controllerAngularAcceleration" })]
  105. public Vector3Control deviceAngularAcceleration { get; protected set; }
  106. protected override void FinishSetup()
  107. {
  108. base.FinishSetup();
  109. thumbstick = GetChildControl<Vector2Control>("thumbstick");
  110. trigger = GetChildControl<AxisControl>("trigger");
  111. triggerTouched = GetChildControl<AxisControl>("triggerTouched");
  112. grip = GetChildControl<AxisControl>("grip");
  113. primaryButton = GetChildControl<ButtonControl>("primaryButton");
  114. secondaryButton = GetChildControl<ButtonControl>("secondaryButton");
  115. gripPressed = GetChildControl<ButtonControl>("gripPressed");
  116. start = GetChildControl<ButtonControl>("start");
  117. thumbstickClicked = GetChildControl<ButtonControl>("thumbstickClicked");
  118. primaryTouched = GetChildControl<ButtonControl>("primaryTouched");
  119. secondaryTouched = GetChildControl<ButtonControl>("secondaryTouched");
  120. thumbstickTouched = GetChildControl<ButtonControl>("thumbstickTouched");
  121. triggerPressed = GetChildControl<ButtonControl>("triggerPressed");
  122. deviceVelocity = GetChildControl<Vector3Control>("deviceVelocity");
  123. deviceAngularVelocity = GetChildControl<Vector3Control>("deviceAngularVelocity");
  124. deviceAcceleration = GetChildControl<Vector3Control>("deviceAcceleration");
  125. deviceAngularAcceleration = GetChildControl<Vector3Control>("deviceAngularAcceleration");
  126. }
  127. }
  128. public class OculusTrackingReference : TrackedDevice
  129. {
  130. [InputControl(aliases = new[] { "trackingReferenceTrackingState" })]
  131. public new IntegerControl trackingState { get; protected set; }
  132. [InputControl(aliases = new[] { "trackingReferenceIsTracked" })]
  133. public new ButtonControl isTracked { get; protected set; }
  134. protected override void FinishSetup()
  135. {
  136. base.FinishSetup();
  137. trackingState = GetChildControl<IntegerControl>("trackingState");
  138. isTracked = GetChildControl<ButtonControl>("isTracked");
  139. }
  140. }
  141. /// <summary>
  142. /// An Oculus Remote controller.
  143. /// </summary>
  144. [InputControlLayout(displayName = "Oculus Remote", hideInUI = true)]
  145. public class OculusRemote : InputDevice
  146. {
  147. [InputControl]
  148. public ButtonControl back { get; protected set; }
  149. [InputControl]
  150. public ButtonControl start { get; protected set; }
  151. [InputControl]
  152. public Vector2Control touchpad { get; protected set; }
  153. protected override void FinishSetup()
  154. {
  155. base.FinishSetup();
  156. back = GetChildControl<ButtonControl>("back");
  157. start = GetChildControl<ButtonControl>("start");
  158. touchpad = GetChildControl<Vector2Control>("touchpad");
  159. }
  160. }
  161. /// <summary>
  162. /// A Standalone VR headset that includes on-headset controls.
  163. /// </summary>
  164. [InputControlLayout(displayName = "Oculus Headset (w/ on-headset controls)", hideInUI = true)]
  165. public class OculusHMDExtended : OculusHMD
  166. {
  167. [InputControl]
  168. public ButtonControl back { get; protected set; }
  169. [InputControl]
  170. public Vector2Control touchpad { get; protected set; }
  171. protected override void FinishSetup()
  172. {
  173. base.FinishSetup();
  174. back = GetChildControl<ButtonControl>("back");
  175. touchpad = GetChildControl<Vector2Control>("touchpad");
  176. }
  177. }
  178. /// <summary>
  179. /// A Gear VR controller.
  180. /// </summary>
  181. [InputControlLayout(displayName = "GearVR Controller", commonUsages = new[] { "LeftHand", "RightHand" }, hideInUI = true)]
  182. public class GearVRTrackedController : XRController
  183. {
  184. [InputControl]
  185. public Vector2Control touchpad { get; protected set; }
  186. [InputControl]
  187. public AxisControl trigger { get; protected set; }
  188. [InputControl]
  189. public ButtonControl back { get; protected set; }
  190. [InputControl]
  191. public ButtonControl triggerPressed { get; protected set; }
  192. [InputControl]
  193. public ButtonControl touchpadClicked { get; protected set; }
  194. [InputControl]
  195. public ButtonControl touchpadTouched { get; protected set; }
  196. [InputControl(noisy = true)]
  197. public Vector3Control deviceAngularVelocity { get; protected set; }
  198. [InputControl(noisy = true)]
  199. public Vector3Control deviceAcceleration { get; protected set; }
  200. [InputControl(noisy = true)]
  201. public Vector3Control deviceAngularAcceleration { get; protected set; }
  202. protected override void FinishSetup()
  203. {
  204. base.FinishSetup();
  205. touchpad = GetChildControl<Vector2Control>("touchpad");
  206. trigger = GetChildControl<AxisControl>("trigger");
  207. back = GetChildControl<ButtonControl>("back");
  208. triggerPressed = GetChildControl<ButtonControl>("triggerPressed");
  209. touchpadClicked = GetChildControl<ButtonControl>("touchpadClicked");
  210. touchpadTouched = GetChildControl<ButtonControl>("touchpadTouched");
  211. deviceAngularVelocity = GetChildControl<Vector3Control>("deviceAngularVelocity");
  212. deviceAcceleration = GetChildControl<Vector3Control>("deviceAcceleration");
  213. deviceAngularAcceleration = GetChildControl<Vector3Control>("deviceAngularAcceleration");
  214. }
  215. }
  216. }
  217. #endif