Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

613 lines
28 KiB

  1. // HyperealVR Controller|SDK_HyperealVR|004
  2. namespace VRTK
  3. {
  4. #if VRTK_DEFINE_SDK_HYPEREALVR
  5. using UnityEngine;
  6. using System.Collections.Generic;
  7. using Hypereal;
  8. using System;
  9. #endif
  10. /// <summary>
  11. /// The HyperealVR Controller SDK script provides a bridge to SDK methods that deal with the input devices.
  12. /// </summary>
  13. [SDK_Description(typeof(SDK_HyperealVRSystem))]
  14. public class SDK_HyperealVRController
  15. #if VRTK_DEFINE_SDK_HYPEREALVR
  16. : SDK_BaseController
  17. #else
  18. : SDK_FallbackController
  19. #endif
  20. {
  21. #if VRTK_DEFINE_SDK_HYPEREALVR
  22. private VRTK_TrackedController cachedLeftController;
  23. private VRTK_TrackedController cachedRightController;
  24. private VRTK_TrackedController cachedLeftTrackedObject;
  25. private VRTK_TrackedController cachedRightTrackedObject;
  26. /// <summary>
  27. /// The ProcessUpdate method enables an SDK to run logic for every Unity Update
  28. /// </summary>
  29. /// <param name="controllerReference">The reference for the controller.</param>
  30. /// <param name="options">A dictionary of generic options that can be used to within the update.</param>
  31. public override void ProcessUpdate(VRTK_ControllerReference controllerReference, Dictionary<string, object> options)
  32. {
  33. }
  34. /// <summary>
  35. /// The ProcessFixedUpdate method enables an SDK to run logic for every Unity FixedUpdate
  36. /// </summary>
  37. /// <param name="controllerReference">The reference for the controller.</param>
  38. /// <param name="options">A dictionary of generic options that can be used to within the fixed update.</param>
  39. public override void ProcessFixedUpdate(VRTK_ControllerReference controllerReference, Dictionary<string, object> options)
  40. {
  41. }
  42. /// <summary>
  43. /// The GetCurrentControllerType method returns the current used ControllerType based on the SDK and headset being used.
  44. /// </summary>
  45. /// <param name="controllerReference">The reference to the controller to get type of.</param>
  46. /// <returns>The ControllerType based on the SDK and headset being used.</returns>
  47. public override ControllerType GetCurrentControllerType(VRTK_ControllerReference controllerReference = null)
  48. {
  49. return ControllerType.Custom;
  50. }
  51. /// <summary>
  52. /// The GetControllerDefaultColliderPath returns the path to the prefab that contains the collider objects for the default controller of this SDK.
  53. /// </summary>
  54. /// <param name="hand">The controller hand to check for</param>
  55. /// <returns>A path to the resource that contains the collider GameObject.</returns>
  56. public override string GetControllerDefaultColliderPath(ControllerHand hand)
  57. {
  58. return "ControllerColliders/HyperealSens";
  59. }
  60. /// <summary>
  61. /// The GetControllerElementPath returns the path to the game object that the given controller element for the given hand resides in.
  62. /// </summary>
  63. /// <param name="element">The controller element to look up.</param>
  64. /// <param name="hand">The controller hand to look up.</param>
  65. /// <param name="fullPath">Whether to get the initial path or the full path to the element.</param>
  66. /// <returns>A string containing the path to the game object that the controller element resides in.</returns>
  67. public override string GetControllerElementPath(ControllerElements element, ControllerHand hand, bool fullPath = false)
  68. {
  69. switch (element)
  70. {
  71. case ControllerElements.AttachPoint:
  72. return "Base";
  73. case ControllerElements.Body:
  74. return "Base/SM_Prop_HyFeel" + (hand == ControllerHand.Left ? "L" : "R") + "_02";
  75. }
  76. return "";
  77. }
  78. /// <summary>
  79. /// The GetControllerIndex method returns the index of the given controller.
  80. /// </summary>
  81. /// <param name="controller">The GameObject containing the controller.</param>
  82. /// <returns>The index of the given controller.</returns>
  83. public override uint GetControllerIndex(GameObject controller)
  84. {
  85. VRTK_TrackedController trackedObject = GetTrackedObject(controller);
  86. return (trackedObject ? (uint)trackedObject.index : uint.MaxValue);
  87. }
  88. /// <summary>
  89. /// The GetControllerByIndex method returns the GameObject of a controller with a specific index.
  90. /// </summary>
  91. /// <param name="index">The index of the controller to find.</param>
  92. /// <param name="actual">If true it will return the actual controller, if false it will return the script alias controller GameObject.</param>
  93. /// <returns>The GameObject of the controller</returns>
  94. public override GameObject GetControllerByIndex(uint index, bool actual = false)
  95. {
  96. SetTrackedControllerCaches();
  97. VRTK_SDKManager sdkManager = VRTK_SDKManager.instance;
  98. if (sdkManager != null)
  99. {
  100. if (cachedLeftController != null && cachedLeftController.index == index)
  101. {
  102. return (actual ? sdkManager.loadedSetup.actualLeftController : sdkManager.scriptAliasLeftController);
  103. }
  104. if (cachedRightController != null && cachedRightController.index == index)
  105. {
  106. return (actual ? sdkManager.loadedSetup.actualRightController : sdkManager.scriptAliasRightController);
  107. }
  108. }
  109. return null;
  110. }
  111. /// <summary>
  112. /// The GetControllerOrigin method returns the origin of the given controller.
  113. /// </summary>
  114. /// <param name="controllerReference">The controller to retrieve the origin from.</param>
  115. /// <returns>A Transform containing the origin of the controller.</returns>
  116. public override Transform GetControllerOrigin(VRTK_ControllerReference controllerReference)
  117. {
  118. return controllerReference.actual.transform;
  119. }
  120. /// <summary>
  121. /// The GenerateControllerPointerOrigin method can create a custom pointer origin Transform to represent the pointer position and forward.
  122. /// </summary>
  123. /// <param name="parent">The GameObject that the origin will become parent of. If it is a controller then it will also be used to determine the hand if required.</param>
  124. /// <returns>A generated Transform that contains the custom pointer origin.</returns>
  125. [System.Obsolete("GenerateControllerPointerOrigin has been deprecated and will be removed in a future version of VRTK.")]
  126. public override Transform GenerateControllerPointerOrigin(GameObject parent)
  127. {
  128. return null;
  129. }
  130. /// <summary>
  131. /// The GetControllerLeftHand method returns the GameObject containing the representation of the left hand controller.
  132. /// </summary>
  133. /// <param name="actual">If true it will return the actual controller, if false it will return the script alias controller GameObject.</param>
  134. /// <returns>The GameObject containing the left hand controller.</returns>
  135. public override GameObject GetControllerLeftHand(bool actual = false)
  136. {
  137. if (actual)
  138. {
  139. HyTrackObjRig trackedObjRig = VRTK_SharedMethods.FindEvenInactiveComponent<HyTrackObjRig>(true);
  140. if (trackedObjRig)
  141. {
  142. return trackedObjRig.leftController;
  143. }
  144. }
  145. else
  146. {
  147. VRTK_SDKManager sdkManager = VRTK_SDKManager.instance;
  148. if (sdkManager != null)
  149. {
  150. return sdkManager.scriptAliasLeftController;
  151. }
  152. }
  153. return null;
  154. }
  155. /// <summary>
  156. /// The GetControllerRightHand method returns the GameObject containing the representation of the right hand controller.
  157. /// </summary>
  158. /// <param name="actual">If true it will return the actual controller, if false it will return the script alias controller GameObject.</param>
  159. /// <returns>The GameObject containing the right hand controller.</returns>
  160. public override GameObject GetControllerRightHand(bool actual = false)
  161. {
  162. if (actual)
  163. {
  164. HyTrackObjRig trackedObjRig = VRTK_SharedMethods.FindEvenInactiveComponent<HyTrackObjRig>(true);
  165. if (trackedObjRig)
  166. {
  167. return trackedObjRig.rightController;
  168. }
  169. }
  170. else
  171. {
  172. VRTK_SDKManager sdkManager = VRTK_SDKManager.instance;
  173. if (sdkManager != null)
  174. {
  175. return sdkManager.scriptAliasRightController;
  176. }
  177. }
  178. return null;
  179. }
  180. /// <summary>
  181. /// The IsControllerLeftHand/1 method is used to check if the given controller is the the left hand controller.
  182. /// </summary>
  183. /// <param name="controller">The GameObject to check.</param>
  184. /// <returns>Returns true if the given controller is the left hand controller.</returns>
  185. public override bool IsControllerLeftHand(GameObject controller)
  186. {
  187. return CheckActualOrScriptAliasControllerIsLeftHand(controller);
  188. }
  189. /// <summary>
  190. /// The IsControllerRightHand/1 method is used to check if the given controller is the the right hand controller.
  191. /// </summary>
  192. /// <param name="controller">The GameObject to check.</param>
  193. /// <returns>Returns true if the given controller is the right hand controller.</returns>
  194. public override bool IsControllerRightHand(GameObject controller)
  195. {
  196. return CheckActualOrScriptAliasControllerIsRightHand(controller);
  197. }
  198. /// <summary>
  199. /// The IsControllerLeftHand/2 method is used to check if the given controller is the the left hand controller.
  200. /// </summary>
  201. /// <param name="controller">The GameObject to check.</param>
  202. /// <param name="actual">If true it will check the actual controller, if false it will check the script alias controller.</param>
  203. /// <returns>Returns true if the given controller is the left hand controller.</returns>
  204. public override bool IsControllerLeftHand(GameObject controller, bool actual)
  205. {
  206. return CheckControllerLeftHand(controller, actual);
  207. }
  208. /// <summary>
  209. /// The IsControllerRightHand/2 method is used to check if the given controller is the the right hand controller.
  210. /// </summary>
  211. /// <param name="controller">The GameObject to check.</param>
  212. /// <param name="actual">If true it will check the actual controller, if false it will check the script alias controller.</param>
  213. /// <returns>Returns true if the given controller is the right hand controller.</returns>
  214. public override bool IsControllerRightHand(GameObject controller, bool actual)
  215. {
  216. return CheckControllerRightHand(controller, actual);
  217. }
  218. /// <summary>
  219. /// The WaitForControllerModel method determines whether the controller model for the given hand requires waiting to load in on scene start.
  220. /// </summary>
  221. /// <param name="hand">The hand to determine if the controller model will be ready for.</param>
  222. /// <returns>Returns true if the controller model requires loading in at runtime and therefore needs waiting for. Returns false if the controller model will be available at start.</returns>
  223. public override bool WaitForControllerModel(ControllerHand hand)
  224. {
  225. return false;
  226. }
  227. /// <summary>
  228. /// The GetControllerModel method returns the model alias for the given GameObject.
  229. /// </summary>
  230. /// <param name="controller">The GameObject to get the model alias for.</param>
  231. /// <returns>The GameObject that has the model alias within it.</returns>
  232. public override GameObject GetControllerModel(GameObject controller)
  233. {
  234. return GetControllerModelFromController(controller);
  235. }
  236. /// <summary>
  237. /// The GetControllerModel method returns the model alias for the given controller hand.
  238. /// </summary>
  239. /// <param name="hand">The hand enum of which controller model to retrieve.</param>
  240. /// <returns>The GameObject that has the model alias within it.</returns>
  241. public override GameObject GetControllerModel(ControllerHand hand)
  242. {
  243. GameObject modelGO = GetSDKManagerControllerModelForHand(hand);
  244. if (!modelGO)
  245. {
  246. GameObject controller = null;
  247. switch (hand)
  248. {
  249. case ControllerHand.Left:
  250. controller = GetControllerLeftHand(true);
  251. break;
  252. case ControllerHand.Right:
  253. controller = GetControllerRightHand(true);
  254. break;
  255. }
  256. if (controller != null)
  257. {
  258. Transform model = controller.transform.Find("Model");
  259. modelGO = (model != null ? model.gameObject : null);
  260. }
  261. }
  262. return modelGO;
  263. }
  264. /// <summary>
  265. /// The GetControllerRenderModel method gets the game object that contains the given controller's render model.
  266. /// </summary>
  267. /// <param name="controllerReference">The GameObject to check.</param>
  268. /// <returns>A GameObject containing the object that has a render model for the controller.</returns>
  269. public override GameObject GetControllerRenderModel(VRTK_ControllerReference controllerReference)
  270. {
  271. return controllerReference.actual.GetComponentInChildren<MeshRenderer>().gameObject;
  272. }
  273. /// <summary>
  274. /// The SetControllerRenderModelWheel method sets the state of the scroll wheel on the controller render model.
  275. /// </summary>
  276. /// <param name="renderModel">The GameObject containing the controller render model.</param>
  277. /// <param name="state">If true and the render model has a scroll wheen then it will be displayed, if false then the scroll wheel will be hidden.</param>
  278. public override void SetControllerRenderModelWheel(GameObject renderModel, bool state)
  279. {
  280. }
  281. /// <summary>
  282. /// The HapticPulse/2 method is used to initiate a simple haptic pulse on the tracked object of the given controller reference.
  283. /// </summary>
  284. /// <param name="controllerReference">The reference to the tracked object to initiate the haptic pulse on.</param>
  285. /// <param name="strength">The intensity of the rumble of the controller motor. `0` to `1`.</param>
  286. public override void HapticPulse(VRTK_ControllerReference controllerReference, float strength = 0.5f)
  287. {
  288. uint index = VRTK_ControllerReference.GetRealIndex(controllerReference);
  289. HyDevice ctrlDevice = MappingIndex2HyDevice(index);
  290. if (ctrlDevice == HyDevice.Device_Unknown)
  291. {
  292. return;
  293. }
  294. HyperealVR.Instance.SetHapticFeedback(ctrlDevice, 0.5f, strength);
  295. }
  296. /// <summary>
  297. /// The HapticPulse/2 method is used to initiate a haptic pulse based on an audio clip on the tracked object of the given controller reference.
  298. /// </summary>
  299. /// <param name="controllerReference">The reference to the tracked object to initiate the haptic pulse on.</param>
  300. /// <param name="clip">The audio clip to use for the haptic pattern.</param>
  301. public override bool HapticPulse(VRTK_ControllerReference controllerReference, AudioClip clip)
  302. {
  303. //TODO;
  304. return false;
  305. }
  306. /// <summary>
  307. /// The GetHapticModifiers method is used to return modifiers for the duration and interval if the SDK handles it slightly differently.
  308. /// </summary>
  309. /// <returns>An SDK_ControllerHapticModifiers object with a given `durationModifier` and an `intervalModifier`.</returns>
  310. public override SDK_ControllerHapticModifiers GetHapticModifiers()
  311. {
  312. return new SDK_ControllerHapticModifiers();
  313. }
  314. /// <summary>
  315. /// The GetVelocity method is used to determine the current velocity of the tracked object on the given controller reference.
  316. /// </summary>
  317. /// <param name="controllerReference">The reference to the tracked object to check for.</param>
  318. /// <returns>A Vector3 containing the current velocity of the tracked object.</returns>
  319. public override Vector3 GetVelocity(VRTK_ControllerReference controllerReference)
  320. {
  321. uint index = VRTK_ControllerReference.GetRealIndex(controllerReference);
  322. SetTrackedControllerCaches();
  323. VRTK_SDKManager sdkManager = VRTK_SDKManager.instance;
  324. if (sdkManager != null)
  325. {
  326. if (cachedLeftController != null && cachedLeftController.index == index)
  327. {
  328. HyTrackingState controllerState = HyperealVR.Instance.GetTrackingState(HyDevice.Device_Controller0);
  329. return controllerState.velocity;
  330. }
  331. if (cachedRightController != null && cachedRightController.index == index)
  332. {
  333. HyTrackingState controllerState = HyperealVR.Instance.GetTrackingState(HyDevice.Device_Controller1);
  334. return controllerState.velocity;
  335. }
  336. }
  337. return Vector3.zero;
  338. }
  339. /// <summary>
  340. /// The GetAngularVelocity method is used to determine the current angular velocity of the tracked object on the given controller reference.
  341. /// </summary>
  342. /// <param name="controllerReference">The reference to the tracked object to check for.</param>
  343. /// <returns>A Vector3 containing the current angular velocity of the tracked object.</returns>
  344. public override Vector3 GetAngularVelocity(VRTK_ControllerReference controllerReference)
  345. {
  346. uint index = VRTK_ControllerReference.GetRealIndex(controllerReference);
  347. SetTrackedControllerCaches();
  348. VRTK_SDKManager sdkManager = VRTK_SDKManager.instance;
  349. if (sdkManager != null)
  350. {
  351. if (cachedLeftController != null && cachedLeftController.index == index)
  352. {
  353. HyTrackingState controllerState = HyperealVR.Instance.GetTrackingState(HyDevice.Device_Controller0);
  354. return controllerState.angularVelocity;
  355. }
  356. if (cachedRightController != null && cachedRightController.index == index)
  357. {
  358. HyTrackingState controllerState = HyperealVR.Instance.GetTrackingState(HyDevice.Device_Controller1);
  359. return controllerState.angularVelocity;
  360. }
  361. }
  362. return Vector3.zero;
  363. }
  364. /// <summary>
  365. /// The IsTouchpadStatic method is used to determine if the touchpad is currently not being moved.
  366. /// </summary>
  367. /// <param name="currentAxisValues"></param>
  368. /// <param name="previousAxisValues"></param>
  369. /// <param name="compareFidelity"></param>
  370. /// <returns>Returns true if the touchpad is not currently being touched or moved.</returns>
  371. public override bool IsTouchpadStatic(bool isTouched, Vector2 currentAxisValues, Vector2 previousAxisValues, int compareFidelity)
  372. {
  373. return (!isTouched || VRTK_SharedMethods.Vector2ShallowCompare(currentAxisValues, previousAxisValues, compareFidelity));
  374. }
  375. /// <summary>
  376. /// The GetButtonAxis method retrieves the current X/Y axis values for the given button type on the given controller reference.
  377. /// </summary>
  378. /// <param name="buttonType">The type of button to check for the axis on.</param>
  379. /// <param name="controllerReference">The reference to the controller to check the button axis on.</param>
  380. /// <returns>A Vector2 of the X/Y values of the button axis. If no axis values exist for the given button, then a Vector2.Zero is returned.</returns>
  381. public override Vector2 GetButtonAxis(ButtonTypes buttonType, VRTK_ControllerReference controllerReference)
  382. {
  383. uint index = VRTK_ControllerReference.GetRealIndex(controllerReference);
  384. HyDevice ctrlDevice = MappingIndex2HyDevice(index);
  385. if (ctrlDevice == HyDevice.Device_Unknown)
  386. {
  387. return Vector2.zero;
  388. }
  389. HyInput input = HyInputManager.Instance.GetInputDevice(ctrlDevice);
  390. switch (buttonType)
  391. {
  392. case ButtonTypes.Touchpad:
  393. return input.GetTouchpadAxis();
  394. case ButtonTypes.Trigger:
  395. return new Vector2(input.GetTriggerAxis(HyInputKey.IndexTrigger), 0f);
  396. case ButtonTypes.Grip:
  397. return new Vector2(input.GetTriggerAxis(HyInputKey.SideTrigger), 0f);
  398. }
  399. return Vector2.zero;
  400. }
  401. /// <summary>
  402. /// The GetButtonSenseAxis method retrieves the current sense axis value for the given button type on the given controller reference.
  403. /// </summary>
  404. /// <param name="buttonType">The type of button to check for the sense axis on.</param>
  405. /// <param name="controllerReference">The reference to the controller to check the sense axis on.</param>
  406. /// <returns>The current sense axis value.</returns>
  407. public override float GetButtonSenseAxis(ButtonTypes buttonType, VRTK_ControllerReference controllerReference)
  408. {
  409. return 0f;
  410. }
  411. /// <summary>
  412. /// The GetButtonHairlineDelta method is used to get the difference between the current button press and the previous frame button press.
  413. /// </summary>
  414. /// <param name="buttonType">The type of button to get the hairline delta for.</param>
  415. /// <param name="controllerReference">The reference to the controller to get the hairline delta for.</param>
  416. /// <returns>The delta between the button presses.</returns>
  417. public override float GetButtonHairlineDelta(ButtonTypes buttonType, VRTK_ControllerReference controllerReference)
  418. {
  419. uint index = VRTK_ControllerReference.GetRealIndex(controllerReference);
  420. HyDevice ctrlDevice = MappingIndex2HyDevice(index);
  421. if (ctrlDevice == HyDevice.Device_Unknown)
  422. {
  423. return 0f;
  424. }
  425. return (buttonType == ButtonTypes.Trigger ? 0.1f : 0f);
  426. }
  427. /// <summary>
  428. /// The GetControllerButtonState method is used to determine if the given controller button for the given press type on the given controller reference is currently taking place.
  429. /// </summary>
  430. /// <param name="buttonType">The type of button to check for the state of.</param>
  431. /// <param name="pressType">The button state to check for.</param>
  432. /// <param name="controllerReference">The reference to the controller to check the button state on.</param>
  433. /// <returns>Returns true if the given button is in the state of the given press type on the given controller reference.</returns>
  434. public override bool GetControllerButtonState(ButtonTypes buttonType, ButtonPressTypes pressType, VRTK_ControllerReference controllerReference)
  435. {
  436. uint index = VRTK_ControllerReference.GetRealIndex(controllerReference);
  437. HyDevice ctrlDevice = MappingIndex2HyDevice(index);
  438. if (ctrlDevice == HyDevice.Device_Unknown)
  439. {
  440. return false;
  441. }
  442. switch (buttonType)
  443. {
  444. case ButtonTypes.ButtonOne:
  445. return false;
  446. case ButtonTypes.ButtonTwo:
  447. if (ctrlDevice == HyDevice.Device_Controller0)
  448. {
  449. return IsButtonPressed(ctrlDevice, pressType, HyInputKey.Menu);
  450. }
  451. else
  452. {
  453. return false;
  454. }
  455. case ButtonTypes.Grip:
  456. return IsButtonPressed(ctrlDevice, pressType, HyInputKey.SideTrigger);
  457. case ButtonTypes.GripHairline:
  458. return false;
  459. case ButtonTypes.StartMenu:
  460. if (ctrlDevice == HyDevice.Device_Controller0)
  461. {
  462. return false;
  463. }
  464. else
  465. {
  466. return IsButtonPressed(ctrlDevice, pressType, HyInputKey.Menu);
  467. }
  468. case ButtonTypes.Trigger:
  469. return IsButtonPressed(ctrlDevice, pressType, HyInputKey.IndexTrigger);
  470. case ButtonTypes.TriggerHairline:
  471. return false;
  472. case ButtonTypes.Touchpad:
  473. return IsButtonPressed(ctrlDevice, pressType, HyInputKey.Touchpad);
  474. }
  475. return false;
  476. }
  477. private void OnTrackedDeviceRoleChanged<T>(T ignoredArgument)
  478. {
  479. SetTrackedControllerCaches(true);
  480. }
  481. private void SetTrackedControllerCaches(bool forceRefresh = false)
  482. {
  483. if (forceRefresh)
  484. {
  485. cachedLeftTrackedObject = null;
  486. cachedRightTrackedObject = null;
  487. }
  488. VRTK_SDKManager sdkManager = VRTK_SDKManager.instance;
  489. if (sdkManager != null)
  490. {
  491. if (cachedLeftTrackedObject == null && sdkManager.loadedSetup.actualLeftController)
  492. {
  493. cachedLeftController = sdkManager.loadedSetup.actualLeftController.GetComponent<VRTK_TrackedController>();
  494. if (cachedLeftController != null)
  495. {
  496. cachedLeftController.index = 0;
  497. }
  498. }
  499. if (cachedRightTrackedObject == null && sdkManager.loadedSetup.actualRightController)
  500. {
  501. cachedRightController = sdkManager.loadedSetup.actualRightController.GetComponent<VRTK_TrackedController>();
  502. if (cachedRightController != null)
  503. {
  504. cachedRightController.index = 1;
  505. }
  506. }
  507. }
  508. }
  509. private VRTK_TrackedController GetTrackedObject(GameObject controller)
  510. {
  511. SetTrackedControllerCaches();
  512. VRTK_TrackedController trackedObject = null;
  513. if (IsControllerLeftHand(controller))
  514. {
  515. trackedObject = cachedLeftController;
  516. }
  517. else if (IsControllerRightHand(controller))
  518. {
  519. trackedObject = cachedRightController;
  520. }
  521. return trackedObject;
  522. }
  523. private HyDevice MappingIndex2HyDevice(uint index)
  524. {
  525. switch (index)
  526. {
  527. case 0:
  528. return HyDevice.Device_Controller0;
  529. case 1:
  530. return HyDevice.Device_Controller1;
  531. default:
  532. break;
  533. }
  534. return HyDevice.Device_Unknown;
  535. }
  536. private bool IsButtonPressed(HyDevice index, ButtonPressTypes type, HyInputKey button)
  537. {
  538. //todo use index to input type
  539. HyInput device = HyInputManager.Instance.GetInputDevice(index);
  540. switch (type)
  541. {
  542. case ButtonPressTypes.Press:
  543. return device.GetPress(button);
  544. case ButtonPressTypes.PressDown:
  545. return device.GetPressDown(button);
  546. case ButtonPressTypes.PressUp:
  547. return device.GetPressUp(button);
  548. case ButtonPressTypes.Touch:
  549. return device.GetTouch(button);
  550. case ButtonPressTypes.TouchDown:
  551. return device.GetTouchDown(button);
  552. case ButtonPressTypes.TouchUp:
  553. return device.GetTouchUp(button);
  554. }
  555. return false;
  556. }
  557. protected virtual void Awake()
  558. {
  559. SetTrackedControllerCaches(true);
  560. }
  561. #endif
  562. }
  563. }