ControllerHints.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* ControllerHints.cs
  2. * author: Ayumi Bischoff
  3. * modified: Jingyi
  4. */
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using UnityEngine;
  8. using Valve.VR;
  9. using Valve.VR.InteractionSystem;
  10. // Class that manages activation/ deactivation of controller hints.
  11. // Attached to GameObject ButtonHints (Scene: Simulation)
  12. public class ControllerHints : MonoBehaviour
  13. {
  14. public SteamVR_ActionSet hints;
  15. public SteamVR_Action_Boolean hintsOnOff;
  16. public SteamVR_Action_Boolean moveUp;
  17. public SteamVR_Action_Boolean moveDown;
  18. public SteamVR_Action_Boolean turnLeft;
  19. public SteamVR_Action_Boolean turnRight;
  20. public SteamVR_Action_Boolean teleport;
  21. public SteamVR_Action_Boolean menu;
  22. public SteamVR_Action_Vector2 robotDirection;
  23. public SteamVR_Action_Single moveRobot;
  24. SteamVR_Action_Boolean unlock = SteamVR_Input.GetBooleanAction("Lock");
  25. SteamVR_Action_Boolean scrollUp = SteamVR_Input.GetBooleanAction("TouchUp");
  26. SteamVR_Action_Boolean scrollDown = SteamVR_Input.GetBooleanAction("TouchDown");
  27. SteamVR_Action_Boolean interactUI = SteamVR_Input.GetBooleanAction("InteractUI");
  28. SteamVR_Action_Boolean grab = SteamVR_Input.GetBooleanAction("GrabGrip");
  29. public Hand leftHand;
  30. public Hand rightHand;
  31. VRInput input;
  32. private bool isShowingHints;
  33. // Start is called before the first frame update.
  34. // Add hint button event and menu button event.
  35. void Start()
  36. {
  37. input = GameObject.Find("Input").GetComponent<VRInput>();
  38. hintsOnOff.onStateDown += HintsOnOff_onStateDown;
  39. menu.onStateDown += Menu_onStateDown;
  40. hints.Activate();
  41. isShowingHints = false;
  42. }
  43. // State change of beeing in the menu or not triggers the hint button hint.
  44. private void Menu_onStateDown(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource)
  45. {
  46. ControllerButtonHints.ShowTextHint(leftHand, hintsOnOff, "Hints");
  47. isShowingHints = false;
  48. }
  49. // If the hint button is pressed the hints for the environment are shown or there is no hint except for the hint button hint.
  50. // Environtments are: the player is in the menu or the menu is closed.
  51. private void HintsOnOff_onStateDown(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource)
  52. {
  53. if (!isShowingHints)
  54. {
  55. if (InteractionManagement.Instance.Menu_Opened)
  56. {
  57. isShowingHints = ShowMenuHints();
  58. }
  59. else
  60. {
  61. isShowingHints = ShowSimHints();
  62. }
  63. }
  64. else
  65. {
  66. ControllerButtonHints.HideAllTextHints(leftHand);
  67. ControllerButtonHints.HideAllTextHints(rightHand);
  68. isShowingHints = false;
  69. }
  70. }
  71. // Update is called once per frame.
  72. // Clears current hints if the player changes environments.
  73. void Update()
  74. {
  75. if (InteractionManagement.Instance.Menu_Opened)
  76. {
  77. DeactivateSimHints();
  78. }
  79. else
  80. {
  81. DeactivateMenuHints();
  82. }
  83. if (!ControllerButtonHints.IsButtonHintActive(leftHand, hintsOnOff) && !isShowingHints)
  84. {
  85. ControllerButtonHints.ShowTextHint(leftHand, hintsOnOff, "Hints");
  86. }
  87. }
  88. public void setIsShowingHints(bool isShowing)
  89. {
  90. isShowingHints = isShowing;
  91. }
  92. // Shows all hints that advice the user how to control the player and robot.
  93. private bool ShowSimHints()
  94. {
  95. ControllerButtonHints.HideTextHint(leftHand, hintsOnOff);
  96. ControllerButtonHints.ShowButtonHint(leftHand, moveDown);
  97. ControllerButtonHints.ShowButtonHint(leftHand, turnLeft);
  98. ControllerButtonHints.ShowButtonHint(leftHand, turnRight);
  99. ControllerButtonHints.ShowTextHint(leftHand, teleport, "Teleport");
  100. ControllerButtonHints.ShowTextHint(leftHand, menu, "Menu");
  101. if(input.CurrentMode.name == "Handle"){
  102. ControllerButtonHints.ShowTextHint(leftHand, moveUp, "Up/Down/Left/Right");
  103. ControllerButtonHints.ShowTextHint(rightHand, robotDirection, "Robot Direction");
  104. ControllerButtonHints.ShowTextHint(rightHand, moveRobot, "Move Robot");
  105. ControllerButtonHints.ShowTextHint(rightHand, unlock, "(Un-)Lock Robot");
  106. }
  107. if(input.CurrentMode.name == "Lab"){
  108. ControllerButtonHints.ShowTextHint(rightHand, grab, "Pick up things");
  109. ControllerButtonHints.ShowTextHint(leftHand, grab, "Pick up things");
  110. }
  111. if(input.CurrentMode.name == "Remote"){
  112. ControllerButtonHints.ShowTextHint(leftHand, moveUp, "Up/Down/Left/Right");
  113. ControllerButtonHints.ShowTextHint(rightHand, interactUI, "Set Destination");
  114. ControllerButtonHints.ShowTextHint(rightHand, unlock, "(Un-)Lock Robot");
  115. ControllerButtonHints.ShowTextHint(leftHand, menu, "Menu");
  116. }
  117. if(input.CurrentMode.name == "UI"){
  118. ControllerButtonHints.ShowTextHint(leftHand, moveUp, "Up/Down/Left/Right");
  119. ControllerButtonHints.ShowTextHint(rightHand, interactUI, "Select");
  120. }
  121. return true;
  122. }
  123. // Deactivates simulation hints.
  124. private void DeactivateSimHints()
  125. {
  126. ControllerButtonHints.HideTextHint(leftHand, moveUp);
  127. ControllerButtonHints.HideButtonHint(leftHand, moveDown);
  128. ControllerButtonHints.HideButtonHint(leftHand, turnLeft);
  129. ControllerButtonHints.HideButtonHint(leftHand, turnRight);
  130. ControllerButtonHints.HideTextHint(leftHand, teleport);
  131. if (!isShowingHints) ControllerButtonHints.HideTextHint(leftHand, menu);
  132. ControllerButtonHints.HideTextHint(rightHand, unlock);
  133. ControllerButtonHints.HideTextHint(rightHand, robotDirection);
  134. ControllerButtonHints.HideTextHint(rightHand, moveRobot);
  135. }
  136. // Shows all hints that advice the player to use the menu.
  137. private bool ShowMenuHints()
  138. {
  139. ControllerButtonHints.ShowTextHint(rightHand, interactUI, "Select");
  140. ControllerButtonHints.ShowTextHint(rightHand, scrollUp, "Scroll");
  141. ControllerButtonHints.ShowTextHint(leftHand, menu, "Close menu");
  142. ControllerButtonHints.ShowButtonHint(rightHand, scrollDown);
  143. ControllerButtonHints.HideTextHint(leftHand, hintsOnOff);
  144. return true;
  145. }
  146. // Deactivates menu hints.
  147. private void DeactivateMenuHints()
  148. {
  149. ControllerButtonHints.HideTextHint(rightHand, interactUI);
  150. ControllerButtonHints.HideTextHint(rightHand, scrollUp);
  151. if (!isShowingHints) ControllerButtonHints.HideTextHint(leftHand, menu);
  152. ControllerButtonHints.HideButtonHint(rightHand, scrollDown);
  153. }
  154. }