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.

197 lines
8.0 KiB

  1. // Panel Menu Item|Prefabs|0140
  2. namespace VRTK
  3. {
  4. using UnityEngine;
  5. /// <summary>
  6. /// Event Payload
  7. /// </summary>
  8. /// <param name="interactableObject">The GameObject for the interactable object the PanelMenu is attached to.</param>
  9. public struct PanelMenuItemControllerEventArgs
  10. {
  11. public GameObject interactableObject;
  12. }
  13. /// <summary>
  14. /// Event Payload
  15. /// </summary>
  16. /// <param name="sender">this object</param>
  17. /// <param name="e"><see cref="PanelMenuItemControllerEventArgs"/></param>
  18. public delegate void PanelMenuItemControllerEventHandler(object sender, PanelMenuItemControllerEventArgs e);
  19. /// <summary>
  20. /// Intercepts the controller events sent from a `VRTK_PanelMenuController` and passes them onto additional custom event subscriber scripts, which then carry out the required custom UI actions.
  21. /// </summary>
  22. /// <remarks>
  23. /// > This script is not directly part of a prefab but is a helper associated to the `PanelMenu` prefab.
  24. ///
  25. /// * Place the `VRTK/Prefabs/PanelMenu/VRTK_PanelMenuItemController` script on the child GameObject of any Panel Item Container which is contained within the `PanelMenuController` prefab within the scene.
  26. /// * Pick up the VRTK_InteractableObject show/hide the panel menu by pressing the touchpad top/bottom/left/right you can open/close the child UI panel that has been assigned via the Unity Editor panel.
  27. /// </remarks>
  28. /// <example>
  29. /// `040_Controls_Panel_Menu` contains three basic interactive object examples of the PanelMenu in use.
  30. /// </example>
  31. public class VRTK_PanelMenuItemController : MonoBehaviour
  32. {
  33. /// <summary>
  34. /// Emitted when the panel menu item is showing.
  35. /// </summary>
  36. public event PanelMenuItemControllerEventHandler PanelMenuItemShowing;
  37. /// <summary>
  38. /// Emitted when the panel menu item is hiding.
  39. /// </summary>
  40. public event PanelMenuItemControllerEventHandler PanelMenuItemHiding;
  41. /// <summary>
  42. /// Emitted when the panel menu item is open and the user swipes left on the controller touchpad.
  43. /// </summary>
  44. public event PanelMenuItemControllerEventHandler PanelMenuItemSwipeLeft;
  45. /// <summary>
  46. /// Emitted when the panel menu item is open and the user swipes right on the controller touchpad.
  47. /// </summary>
  48. public event PanelMenuItemControllerEventHandler PanelMenuItemSwipeRight;
  49. /// <summary>
  50. /// Emitted when the panel menu item is open and the user swipes top on the controller touchpad.
  51. /// </summary>
  52. public event PanelMenuItemControllerEventHandler PanelMenuItemSwipeTop;
  53. /// <summary>
  54. /// Emitted when the panel menu item is open and the user swipes bottom on the controller touchpad.
  55. /// </summary>
  56. public event PanelMenuItemControllerEventHandler PanelMenuItemSwipeBottom;
  57. /// <summary>
  58. /// Emitted when the panel menu item is open and the user presses the trigger of the controller holding the interactable object.
  59. /// </summary>
  60. public event PanelMenuItemControllerEventHandler PanelMenuItemTriggerPressed;
  61. public virtual void OnPanelMenuItemShowing(PanelMenuItemControllerEventArgs e)
  62. {
  63. if (PanelMenuItemShowing != null)
  64. {
  65. PanelMenuItemShowing(this, e);
  66. }
  67. }
  68. public virtual void OnPanelMenuItemHiding(PanelMenuItemControllerEventArgs e)
  69. {
  70. if (PanelMenuItemHiding != null)
  71. {
  72. PanelMenuItemHiding(this, e);
  73. }
  74. }
  75. public virtual void OnPanelMenuItemSwipeLeft(PanelMenuItemControllerEventArgs e)
  76. {
  77. if (PanelMenuItemSwipeLeft != null)
  78. {
  79. PanelMenuItemSwipeLeft(this, e);
  80. }
  81. }
  82. public virtual void OnPanelMenuItemSwipeRight(PanelMenuItemControllerEventArgs e)
  83. {
  84. if (PanelMenuItemSwipeRight != null)
  85. {
  86. PanelMenuItemSwipeRight(this, e);
  87. }
  88. }
  89. public virtual void OnPanelMenuItemSwipeTop(PanelMenuItemControllerEventArgs e)
  90. {
  91. if (PanelMenuItemSwipeTop != null)
  92. {
  93. PanelMenuItemSwipeTop(this, e);
  94. }
  95. }
  96. public virtual void OnPanelMenuItemSwipeBottom(PanelMenuItemControllerEventArgs e)
  97. {
  98. if (PanelMenuItemSwipeBottom != null)
  99. {
  100. PanelMenuItemSwipeBottom(this, e);
  101. }
  102. }
  103. /// <summary>
  104. /// The SetPanelMenuItemEvent is used to build up the event payload.
  105. /// </summary>
  106. /// <param name="interactableObject">The object the menu is attached to.</param>
  107. /// <returns>The payload for the event.</returns>
  108. public virtual PanelMenuItemControllerEventArgs SetPanelMenuItemEvent(GameObject interactableObject)
  109. {
  110. PanelMenuItemControllerEventArgs e;
  111. e.interactableObject = interactableObject;
  112. return e;
  113. }
  114. /// <summary>
  115. /// The Show method is used to show the menu.
  116. /// </summary>
  117. /// <param name="interactableObject">The object the menu is attached to.</param>
  118. public virtual void Show(GameObject interactableObject)
  119. {
  120. gameObject.SetActive(true);
  121. OnPanelMenuItemShowing(SetPanelMenuItemEvent(interactableObject));
  122. }
  123. /// <summary>
  124. /// The Hide method is used to show the menu.
  125. /// </summary>
  126. /// <param name="interactableObject">The object the menu is attached to.</param>
  127. public virtual void Hide(GameObject interactableObject)
  128. {
  129. gameObject.SetActive(false);
  130. OnPanelMenuItemHiding(SetPanelMenuItemEvent(interactableObject));
  131. }
  132. /// <summary>
  133. /// The SwipeLeft method is used when the control is swiped left.
  134. /// </summary>
  135. /// <param name="interactableObject">The object the menu is attached to.</param>
  136. public virtual void SwipeLeft(GameObject interactableObject)
  137. {
  138. OnPanelMenuItemSwipeLeft(SetPanelMenuItemEvent(interactableObject));
  139. }
  140. /// <summary>
  141. /// The SwipeRight method is used when the control is swiped right.
  142. /// </summary>
  143. /// <param name="interactableObject">The object the menu is attached to.</param>
  144. public virtual void SwipeRight(GameObject interactableObject)
  145. {
  146. OnPanelMenuItemSwipeRight(SetPanelMenuItemEvent(interactableObject));
  147. }
  148. /// <summary>
  149. /// The SwipeTop method is used when the control is swiped up.
  150. /// </summary>
  151. /// <param name="interactableObject">The object the menu is attached to.</param>
  152. public virtual void SwipeTop(GameObject interactableObject)
  153. {
  154. OnPanelMenuItemSwipeTop(SetPanelMenuItemEvent(interactableObject));
  155. }
  156. /// <summary>
  157. /// The SwipeBottom method is used when the control is swiped down.
  158. /// </summary>
  159. /// <param name="interactableObject">The object the menu is attached to.</param>
  160. public virtual void SwipeBottom(GameObject interactableObject)
  161. {
  162. OnPanelMenuItemSwipeBottom(SetPanelMenuItemEvent(interactableObject));
  163. }
  164. /// <summary>
  165. /// The TriggerPressed method is used when the control action button is pressed.
  166. /// </summary>
  167. /// <param name="interactableObject">The object the menu is attached to.</param>
  168. public virtual void TriggerPressed(GameObject interactableObject)
  169. {
  170. OnPanelMenuItemTriggerPressed(SetPanelMenuItemEvent(interactableObject));
  171. }
  172. protected virtual void OnPanelMenuItemTriggerPressed(PanelMenuItemControllerEventArgs e)
  173. {
  174. if (PanelMenuItemTriggerPressed != null)
  175. {
  176. PanelMenuItemTriggerPressed(this, e);
  177. }
  178. }
  179. }
  180. }