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.

655 lines
30 KiB

  1. // Base Controller|SDK_Base|006
  2. namespace VRTK
  3. {
  4. using UnityEngine;
  5. using System.Collections.Generic;
  6. public struct VRTKSDKBaseControllerEventArgs
  7. {
  8. public VRTK_ControllerReference controllerReference;
  9. }
  10. public delegate void VRTKSDKBaseControllerEventHandler(object sender, VRTKSDKBaseControllerEventArgs e);
  11. /// <summary>
  12. /// The Base Controller SDK script provides a bridge to SDK methods that deal with the input devices.
  13. /// </summary>
  14. /// <remarks>
  15. /// This is an abstract class to implement the interface required by all implemented SDKs.
  16. /// </remarks>
  17. public abstract class SDK_BaseController : SDK_Base
  18. {
  19. /// <summary>
  20. /// Types of buttons on a controller
  21. /// </summary>
  22. public enum ButtonTypes
  23. {
  24. /// <summary>
  25. /// Button One on the controller.
  26. /// </summary>
  27. ButtonOne,
  28. /// <summary>
  29. /// Button Two on the controller.
  30. /// </summary>
  31. ButtonTwo,
  32. /// <summary>
  33. /// Grip on the controller.
  34. /// </summary>
  35. Grip,
  36. /// <summary>
  37. /// Grip Hairline on the controller.
  38. /// </summary>
  39. GripHairline,
  40. /// <summary>
  41. /// Start Menu on the controller.
  42. /// </summary>
  43. StartMenu,
  44. /// <summary>
  45. /// Trigger on the controller.
  46. /// </summary>
  47. Trigger,
  48. /// <summary>
  49. /// Trigger Hairline on the controller.
  50. /// </summary>
  51. TriggerHairline,
  52. /// <summary>
  53. /// Touchpad on the controller.
  54. /// </summary>
  55. Touchpad,
  56. /// <summary>
  57. /// Touchpad Two on the controller.
  58. /// </summary>
  59. TouchpadTwo,
  60. /// <summary>
  61. /// Middle Finger on the controller.
  62. /// </summary>
  63. MiddleFinger,
  64. /// <summary>
  65. /// Ring Finger on the controller.
  66. /// </summary>
  67. RingFinger,
  68. /// <summary>
  69. /// Pinky Finger on the controller.
  70. /// </summary>
  71. PinkyFinger
  72. }
  73. /// <summary>
  74. /// Concepts of controller button press
  75. /// </summary>
  76. public enum ButtonPressTypes
  77. {
  78. /// <summary>
  79. /// The button is currently being pressed.
  80. /// </summary>
  81. Press,
  82. /// <summary>
  83. /// The button has just been pressed down.
  84. /// </summary>
  85. PressDown,
  86. /// <summary>
  87. /// The button has just been released.
  88. /// </summary>
  89. PressUp,
  90. /// <summary>
  91. /// The button is currently being touched.
  92. /// </summary>
  93. Touch,
  94. /// <summary>
  95. /// The button has just been touched.
  96. /// </summary>
  97. TouchDown,
  98. /// <summary>
  99. /// The button is no longer being touched.
  100. /// </summary>
  101. TouchUp
  102. }
  103. /// <summary>
  104. /// The elements of a generic controller
  105. /// </summary>
  106. public enum ControllerElements
  107. {
  108. /// <summary>
  109. /// The default point on the controller to attach grabbed objects to.
  110. /// </summary>
  111. AttachPoint,
  112. /// <summary>
  113. /// The trigger button.
  114. /// </summary>
  115. Trigger,
  116. /// <summary>
  117. /// The left part of the grip button collection.
  118. /// </summary>
  119. GripLeft,
  120. /// <summary>
  121. /// The right part of the grip button collection.
  122. /// </summary>
  123. GripRight,
  124. /// <summary>
  125. /// The touch pad/stick.
  126. /// </summary>
  127. Touchpad,
  128. /// <summary>
  129. /// The first generic button.
  130. /// </summary>
  131. ButtonOne,
  132. /// <summary>
  133. /// The second generic button.
  134. /// </summary>
  135. ButtonTwo,
  136. /// <summary>
  137. /// The system menu button.
  138. /// </summary>
  139. SystemMenu,
  140. /// <summary>
  141. /// The encompassing mesh of the controller body.
  142. /// </summary>
  143. Body,
  144. /// <summary>
  145. /// The start menu button.
  146. /// </summary>
  147. StartMenu,
  148. /// <summary>
  149. /// The touch pad/stick two.
  150. /// </summary>
  151. TouchpadTwo
  152. }
  153. /// <summary>
  154. /// Controller hand reference.
  155. /// </summary>
  156. public enum ControllerHand
  157. {
  158. /// <summary>
  159. /// No hand is assigned.
  160. /// </summary>
  161. None,
  162. /// <summary>
  163. /// The left hand is assigned.
  164. /// </summary>
  165. Left,
  166. /// <summary>
  167. /// The right hand is assigned.
  168. /// </summary>
  169. Right
  170. }
  171. /// <summary>
  172. /// SDK Controller types.
  173. /// </summary>
  174. public enum ControllerType
  175. {
  176. /// <summary>
  177. /// No controller type.
  178. /// </summary>
  179. Undefined,
  180. /// <summary>
  181. /// A custom controller type.
  182. /// </summary>
  183. Custom,
  184. /// <summary>
  185. /// The Simulator default hand controller.
  186. /// </summary>
  187. Simulator_Hand,
  188. /// <summary>
  189. /// The HTC Vive wand controller for SteamVR.
  190. /// </summary>
  191. SteamVR_ViveWand,
  192. /// <summary>
  193. /// The Oculus Touch controller for SteamVR.
  194. /// </summary>
  195. SteamVR_OculusTouch,
  196. /// <summary>
  197. /// The Oculus Touch controller for Oculus Utilities.
  198. /// </summary>
  199. Oculus_OculusTouch,
  200. /// <summary>
  201. /// The Daydream controller for Google Daydream SDK.
  202. /// </summary>
  203. Daydream_Controller,
  204. /// <summary>
  205. /// The Flip controller for Ximmerse SDK.
  206. /// </summary>
  207. Ximmerse_Flip,
  208. /// <summary>
  209. /// The Valve Knuckles controller for SteamVR.
  210. /// </summary>
  211. SteamVR_ValveKnuckles,
  212. /// <summary>
  213. /// The Oculus Gamepad for Oculus Utilities.
  214. /// </summary>
  215. Oculus_OculusGamepad,
  216. /// <summary>
  217. /// The Oculus Remote for Oculus Utilities.
  218. /// </summary>
  219. Oculus_OculusRemote,
  220. /// <summary>
  221. /// The Oculus GearVR HMD controls for Oculus Utilities.
  222. /// </summary>
  223. Oculus_GearVRHMD,
  224. /// <summary>
  225. /// The Oculus GearVR controller for Oculus Utilities.
  226. /// </summary>
  227. Oculus_GearVRController,
  228. /// <summary>
  229. /// The Windows Mixed Reality Motion Controller for Windows Mixed Reality.
  230. /// </summary>
  231. WindowsMR_MotionController,
  232. /// <summary>
  233. /// The Windows Mixed Reality Motion Controller for SteamVR.
  234. /// </summary>
  235. SteamVR_WindowsMRController
  236. }
  237. public event VRTKSDKBaseControllerEventHandler LeftControllerReady;
  238. public event VRTKSDKBaseControllerEventHandler RightControllerReady;
  239. public event VRTKSDKBaseControllerEventHandler LeftControllerModelReady;
  240. public event VRTKSDKBaseControllerEventHandler RightControllerModelReady;
  241. protected Transform defaultSDKLeftControllerModel = null;
  242. protected Transform defaultSDKRightControllerModel = null;
  243. public virtual void OnControllerReady(ControllerHand hand)
  244. {
  245. VRTKSDKBaseControllerEventArgs e;
  246. e.controllerReference = VRTK_ControllerReference.GetControllerReference(hand);
  247. switch (hand)
  248. {
  249. case ControllerHand.Left:
  250. if (LeftControllerReady != null)
  251. {
  252. LeftControllerReady(this, e);
  253. }
  254. break;
  255. case ControllerHand.Right:
  256. if (RightControllerReady != null)
  257. {
  258. RightControllerReady(this, e);
  259. }
  260. break;
  261. }
  262. }
  263. /// <summary>
  264. /// The ProcessUpdate method enables an SDK to run logic for every Unity Update
  265. /// </summary>
  266. /// <param name="controllerReference">The reference for the controller.</param>
  267. /// <param name="options">A dictionary of generic options that can be used to within the update.</param>
  268. public abstract void ProcessUpdate(VRTK_ControllerReference controllerReference, Dictionary<string, object> options);
  269. /// <summary>
  270. /// The ProcessFixedUpdate method enables an SDK to run logic for every Unity FixedUpdate
  271. /// </summary>
  272. /// <param name="controllerReference">The reference for the controller.</param>
  273. /// <param name="options">A dictionary of generic options that can be used to within the fixed update.</param>
  274. public abstract void ProcessFixedUpdate(VRTK_ControllerReference controllerReference, Dictionary<string, object> options);
  275. /// <summary>
  276. /// The GetCurrentControllerType method returns the current used ControllerType based on the SDK and headset being used.
  277. /// </summary>
  278. /// <param name="controllerReference">The reference to the controller to get type of.</param>
  279. /// <returns>The ControllerType based on the SDK and headset being used.</returns>
  280. public abstract ControllerType GetCurrentControllerType(VRTK_ControllerReference controllerReference = null);
  281. /// <summary>
  282. /// The GetControllerDefaultColliderPath returns the path to the prefab that contains the collider objects for the default controller of this SDK.
  283. /// </summary>
  284. /// <param name="hand">The controller hand to check for</param>
  285. /// <returns>A path to the resource that contains the collider GameObject.</returns>
  286. public abstract string GetControllerDefaultColliderPath(ControllerHand hand);
  287. /// <summary>
  288. /// The GetControllerElementPath returns the path to the game object that the given controller element for the given hand resides in.
  289. /// </summary>
  290. /// <param name="element">The controller element to look up.</param>
  291. /// <param name="hand">The controller hand to look up.</param>
  292. /// <param name="fullPath">Whether to get the initial path or the full path to the element.</param>
  293. /// <returns>A string containing the path to the game object that the controller element resides in.</returns>
  294. public abstract string GetControllerElementPath(ControllerElements element, ControllerHand hand, bool fullPath = false);
  295. /// <summary>
  296. /// The GetControllerIndex method returns the index of the given controller.
  297. /// </summary>
  298. /// <param name="controller">The GameObject containing the controller.</param>
  299. /// <returns>The index of the given controller.</returns>
  300. public abstract uint GetControllerIndex(GameObject controller);
  301. /// <summary>
  302. /// The GetControllerByIndex method returns the GameObject of a controller with a specific index.
  303. /// </summary>
  304. /// <param name="index">The index of the controller to find.</param>
  305. /// <param name="actual">If true it will return the actual controller, if false it will return the script alias controller GameObject.</param>
  306. /// <returns>The GameObject of the controller</returns>
  307. public abstract GameObject GetControllerByIndex(uint index, bool actual = false);
  308. /// <summary>
  309. /// The GetControllerOrigin method returns the origin of the given controller.
  310. /// </summary>
  311. /// <param name="controllerReference">The reference to the controller to retrieve the origin from.</param>
  312. /// <returns>A Transform containing the origin of the controller.</returns>
  313. public abstract Transform GetControllerOrigin(VRTK_ControllerReference controllerReference);
  314. /// <summary>
  315. /// The GenerateControllerPointerOrigin method can create a custom pointer origin Transform to represent the pointer position and forward.
  316. /// </summary>
  317. /// <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>
  318. /// <returns>A generated Transform that contains the custom pointer origin.</returns>
  319. [System.Obsolete("GenerateControllerPointerOrigin has been deprecated and will be removed in a future version of VRTK.")]
  320. public abstract Transform GenerateControllerPointerOrigin(GameObject parent);
  321. /// <summary>
  322. /// The GetControllerLeftHand method returns the GameObject containing the representation of the left hand controller.
  323. /// </summary>
  324. /// <param name="actual">If true it will return the actual controller, if false it will return the script alias controller GameObject.</param>
  325. /// <returns>The GameObject containing the left hand controller.</returns>
  326. public abstract GameObject GetControllerLeftHand(bool actual = false);
  327. /// <summary>
  328. /// The GetControllerRightHand method returns the GameObject containing the representation of the right hand controller.
  329. /// </summary>
  330. /// <param name="actual">If true it will return the actual controller, if false it will return the script alias controller GameObject.</param>
  331. /// <returns>The GameObject containing the right hand controller.</returns>
  332. public abstract GameObject GetControllerRightHand(bool actual = false);
  333. /// <summary>
  334. /// The IsControllerLeftHand/1 method is used to check if the given controller is the the left hand controller.
  335. /// </summary>
  336. /// <param name="controller">The GameObject to check.</param>
  337. /// <returns>Returns true if the given controller is the left hand controller.</returns>
  338. public abstract bool IsControllerLeftHand(GameObject controller);
  339. /// <summary>
  340. /// The IsControllerRightHand/1 method is used to check if the given controller is the the right hand controller.
  341. /// </summary>
  342. /// <param name="controller">The GameObject to check.</param>
  343. /// <returns>Returns true if the given controller is the right hand controller.</returns>
  344. public abstract bool IsControllerRightHand(GameObject controller);
  345. /// <summary>
  346. /// The IsControllerLeftHand/2 method is used to check if the given controller is the the left hand controller.
  347. /// </summary>
  348. /// <param name="controller">The GameObject to check.</param>
  349. /// <param name="actual">If true it will check the actual controller, if false it will check the script alias controller.</param>
  350. /// <returns>Returns true if the given controller is the left hand controller.</returns>
  351. public abstract bool IsControllerLeftHand(GameObject controller, bool actual);
  352. /// <summary>
  353. /// The IsControllerRightHand/2 method is used to check if the given controller is the the right hand controller.
  354. /// </summary>
  355. /// <param name="controller">The GameObject to check.</param>
  356. /// <param name="actual">If true it will check the actual controller, if false it will check the script alias controller.</param>
  357. /// <returns>Returns true if the given controller is the right hand controller.</returns>
  358. public abstract bool IsControllerRightHand(GameObject controller, bool actual);
  359. /// <summary>
  360. /// The WaitForControllerModel method determines whether the controller model for the given hand requires waiting to load in on scene start.
  361. /// </summary>
  362. /// <param name="hand">The hand to determine if the controller model will be ready for.</param>
  363. /// <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>
  364. public abstract bool WaitForControllerModel(ControllerHand hand);
  365. /// <summary>
  366. /// The GetControllerModel method returns the model alias for the given GameObject.
  367. /// </summary>
  368. /// <param name="controller">The GameObject to get the model alias for.</param>
  369. /// <returns>The GameObject that has the model alias within it.</returns>
  370. public abstract GameObject GetControllerModel(GameObject controller);
  371. /// <summary>
  372. /// The GetControllerModel method returns the model alias for the given controller hand.
  373. /// </summary>
  374. /// <param name="hand">The hand enum of which controller model to retrieve.</param>
  375. /// <returns>The GameObject that has the model alias within it.</returns>
  376. public abstract GameObject GetControllerModel(ControllerHand hand);
  377. /// <summary>
  378. /// The GetControllerModelHand method returns the hand for the given controller model GameObject.
  379. /// </summary>
  380. /// <param name="controllerModel">The controller model GameObject to get the hand for.</param>
  381. /// <returns>The hand enum for which the given controller model is for.</returns>
  382. public virtual ControllerHand GetControllerModelHand(GameObject controllerModel)
  383. {
  384. VRTK_SDKManager sdkManager = VRTK_SDKManager.instance;
  385. if (sdkManager != null && sdkManager.loadedSetup != null)
  386. {
  387. if (controllerModel == sdkManager.loadedSetup.modelAliasLeftController)
  388. {
  389. return ControllerHand.Left;
  390. }
  391. else if (controllerModel == sdkManager.loadedSetup.modelAliasRightController)
  392. {
  393. return ControllerHand.Right;
  394. }
  395. }
  396. return ControllerHand.None;
  397. }
  398. /// <summary>
  399. /// The GetControllerRenderModel method gets the game object that contains the given controller's render model.
  400. /// </summary>
  401. /// <param name="controllerReference">The reference to the controller to check.</param>
  402. /// <returns>A GameObject containing the object that has a render model for the controller.</returns>
  403. public abstract GameObject GetControllerRenderModel(VRTK_ControllerReference controllerReference);
  404. /// <summary>
  405. /// The SetControllerRenderModelWheel method sets the state of the scroll wheel on the controller render model.
  406. /// </summary>
  407. /// <param name="renderModel">The GameObject containing the controller render model.</param>
  408. /// <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>
  409. public abstract void SetControllerRenderModelWheel(GameObject renderModel, bool state);
  410. /// <summary>
  411. /// The HapticPulse/2 method is used to initiate a simple haptic pulse on the tracked object of the given controller reference.
  412. /// </summary>
  413. /// <param name="controllerReference">The reference to the tracked object to initiate the haptic pulse on.</param>
  414. /// <param name="strength">The intensity of the rumble of the controller motor. `0` to `1`.</param>
  415. public abstract void HapticPulse(VRTK_ControllerReference controllerReference, float strength = 0.5f);
  416. /// <summary>
  417. /// 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.
  418. /// </summary>
  419. /// <param name="controllerReference">The reference to the tracked object to initiate the haptic pulse on.</param>
  420. /// <param name="clip">The audio clip to use for the haptic pattern.</param>
  421. public abstract bool HapticPulse(VRTK_ControllerReference controllerReference, AudioClip clip);
  422. /// <summary>
  423. /// The GetHapticModifiers method is used to return modifiers for the duration and interval if the SDK handles it slightly differently.
  424. /// </summary>
  425. /// <returns>An SDK_ControllerHapticModifiers object with a given `durationModifier` and an `intervalModifier`.</returns>
  426. public abstract SDK_ControllerHapticModifiers GetHapticModifiers();
  427. /// <summary>
  428. /// The GetVelocity method is used to determine the current velocity of the tracked object on the given controller reference.
  429. /// </summary>
  430. /// <param name="controllerReference">The reference to the tracked object to check for.</param>
  431. /// <returns>A Vector3 containing the current velocity of the tracked object.</returns>
  432. public abstract Vector3 GetVelocity(VRTK_ControllerReference controllerReference);
  433. /// <summary>
  434. /// The GetAngularVelocity method is used to determine the current angular velocity of the tracked object on the given controller reference.
  435. /// </summary>
  436. /// <param name="controllerReference">The reference to the tracked object to check for.</param>
  437. /// <returns>A Vector3 containing the current angular velocity of the tracked object.</returns>
  438. public abstract Vector3 GetAngularVelocity(VRTK_ControllerReference controllerReference);
  439. /// <summary>
  440. /// The IsTouchpadStatic method is used to determine if the touchpad is currently not being moved.
  441. /// </summary>
  442. /// <param name="currentAxisValues"></param>
  443. /// <param name="previousAxisValues"></param>
  444. /// <param name="compareFidelity"></param>
  445. /// <returns>Returns true if the touchpad is not currently being touched or moved.</returns>
  446. public abstract bool IsTouchpadStatic(bool isTouched, Vector2 currentAxisValues, Vector2 previousAxisValues, int compareFidelity);
  447. /// <summary>
  448. /// The GetButtonAxis method retrieves the current X/Y axis values for the given button type on the given controller reference.
  449. /// </summary>
  450. /// <param name="buttonType">The type of button to check for the axis on.</param>
  451. /// <param name="controllerReference">The reference to the controller to check the button axis on.</param>
  452. /// <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>
  453. public abstract Vector2 GetButtonAxis(ButtonTypes buttonType, VRTK_ControllerReference controllerReference);
  454. /// <summary>
  455. /// The GetButtonSenseAxis method retrieves the current sense axis value for the given button type on the given controller reference.
  456. /// </summary>
  457. /// <param name="buttonType">The type of button to check for the sense axis on.</param>
  458. /// <param name="controllerReference">The reference to the controller to check the sense axis on.</param>
  459. /// <returns>The current sense axis value.</returns>
  460. public abstract float GetButtonSenseAxis(ButtonTypes buttonType, VRTK_ControllerReference controllerReference);
  461. /// <summary>
  462. /// The GetButtonHairlineDelta method is used to get the difference between the current button press and the previous frame button press.
  463. /// </summary>
  464. /// <param name="buttonType">The type of button to get the hairline delta for.</param>
  465. /// <param name="controllerReference">The reference to the controller to get the hairline delta for.</param>
  466. /// <returns>The delta between the button presses.</returns>
  467. public abstract float GetButtonHairlineDelta(ButtonTypes buttonType, VRTK_ControllerReference controllerReference);
  468. /// <summary>
  469. /// 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.
  470. /// </summary>
  471. /// <param name="buttonType">The type of button to check for the state of.</param>
  472. /// <param name="pressType">The button state to check for.</param>
  473. /// <param name="controllerReference">The reference to the controller to check the button state on.</param>
  474. /// <returns>Returns true if the given button is in the state of the given press type on the given controller reference.</returns>
  475. public abstract bool GetControllerButtonState(ButtonTypes buttonType, ButtonPressTypes pressType, VRTK_ControllerReference controllerReference);
  476. protected virtual GameObject GetSDKManagerControllerLeftHand(bool actual = false)
  477. {
  478. VRTK_SDKManager sdkManager = VRTK_SDKManager.instance;
  479. if (sdkManager != null && sdkManager.loadedSetup != null)
  480. {
  481. return (actual ? sdkManager.loadedSetup.actualLeftController : sdkManager.scriptAliasLeftController);
  482. }
  483. return null;
  484. }
  485. protected virtual GameObject GetSDKManagerControllerRightHand(bool actual = false)
  486. {
  487. VRTK_SDKManager sdkManager = VRTK_SDKManager.instance;
  488. if (sdkManager != null && sdkManager.loadedSetup != null)
  489. {
  490. return (actual ? sdkManager.loadedSetup.actualRightController : sdkManager.scriptAliasRightController);
  491. }
  492. return null;
  493. }
  494. protected virtual bool CheckActualOrScriptAliasControllerIsLeftHand(GameObject controller)
  495. {
  496. return (IsControllerLeftHand(controller, true) || IsControllerLeftHand(controller, false));
  497. }
  498. protected virtual bool CheckActualOrScriptAliasControllerIsRightHand(GameObject controller)
  499. {
  500. return (IsControllerRightHand(controller, true) || IsControllerRightHand(controller, false));
  501. }
  502. protected virtual bool CheckControllerLeftHand(GameObject controller, bool actual)
  503. {
  504. VRTK_SDKManager sdkManager = VRTK_SDKManager.instance;
  505. if (sdkManager != null && sdkManager.loadedSetup != null && controller != null)
  506. {
  507. return (actual ? controller == sdkManager.loadedSetup.actualLeftController : controller == sdkManager.scriptAliasLeftController);
  508. }
  509. return false;
  510. }
  511. protected virtual bool CheckControllerRightHand(GameObject controller, bool actual)
  512. {
  513. VRTK_SDKManager sdkManager = VRTK_SDKManager.instance;
  514. if (sdkManager != null && sdkManager.loadedSetup != null && controller != null)
  515. {
  516. return (actual ? controller == sdkManager.loadedSetup.actualRightController : controller == sdkManager.scriptAliasRightController);
  517. }
  518. return false;
  519. }
  520. protected virtual GameObject GetControllerModelFromController(GameObject controller)
  521. {
  522. return GetControllerModel(VRTK_DeviceFinder.GetControllerHand(controller));
  523. }
  524. protected virtual GameObject GetSDKManagerControllerModelForHand(ControllerHand hand)
  525. {
  526. VRTK_SDKManager sdkManager = VRTK_SDKManager.instance;
  527. if (sdkManager != null && sdkManager.loadedSetup != null)
  528. {
  529. switch (hand)
  530. {
  531. case ControllerHand.Left:
  532. return sdkManager.loadedSetup.modelAliasLeftController;
  533. case ControllerHand.Right:
  534. return sdkManager.loadedSetup.modelAliasRightController;
  535. }
  536. }
  537. return null;
  538. }
  539. protected virtual GameObject GetActualController(GameObject controller)
  540. {
  541. GameObject returnController = null;
  542. VRTK_SDKManager sdkManager = VRTK_SDKManager.instance;
  543. if (sdkManager != null && sdkManager.loadedSetup != null)
  544. {
  545. if (IsControllerLeftHand(controller))
  546. {
  547. returnController = sdkManager.loadedSetup.actualLeftController;
  548. }
  549. else if (IsControllerRightHand(controller))
  550. {
  551. returnController = sdkManager.loadedSetup.actualRightController;
  552. }
  553. }
  554. return returnController;
  555. }
  556. protected virtual void OnControllerModelReady(ControllerHand hand, VRTK_ControllerReference controllerReference)
  557. {
  558. VRTKSDKBaseControllerEventArgs e;
  559. e.controllerReference = controllerReference;
  560. switch (hand)
  561. {
  562. case ControllerHand.Left:
  563. if (LeftControllerModelReady != null)
  564. {
  565. LeftControllerModelReady(this, e);
  566. }
  567. break;
  568. case ControllerHand.Right:
  569. if (RightControllerModelReady != null)
  570. {
  571. RightControllerModelReady(this, e);
  572. }
  573. break;
  574. }
  575. }
  576. protected virtual bool ShouldWaitForControllerModel(ControllerHand hand, bool ignoreChildCount)
  577. {
  578. //If the default model isn't set or the current controller model isn't the default controller model, then don't bother waiting for the model to stream in.
  579. switch (hand)
  580. {
  581. case ControllerHand.Left:
  582. return IsDefaultControllerModel(defaultSDKLeftControllerModel, GetControllerModel(ControllerHand.Left), ignoreChildCount);
  583. case ControllerHand.Right:
  584. return IsDefaultControllerModel(defaultSDKRightControllerModel, GetControllerModel(ControllerHand.Right), ignoreChildCount);
  585. }
  586. return false;
  587. }
  588. protected virtual bool IsDefaultControllerModel(Transform givenDefault, GameObject givenActual, bool ignoreChildCount)
  589. {
  590. return (givenDefault != null && givenActual == givenDefault.gameObject && givenActual != null && (ignoreChildCount || givenActual.transform.childCount == 0));
  591. }
  592. }
  593. public class SDK_ControllerHapticModifiers
  594. {
  595. public float durationModifier = 1f;
  596. public float intervalModifier = 1f;
  597. public ushort maxHapticVibration = 1;
  598. public int hapticsBufferSize = 8192;
  599. }
  600. }