ControllerHintsExample.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //======= Copyright (c) Valve Corporation, All rights reserved. ===============
  2. //
  3. // Purpose: Demonstrates the use of the controller hint system
  4. //
  5. //=============================================================================
  6. using UnityEngine;
  7. using System.Collections;
  8. using Valve.VR;
  9. namespace Valve.VR.InteractionSystem
  10. {
  11. //-------------------------------------------------------------------------
  12. public class ControllerHintsExample : MonoBehaviour
  13. {
  14. private Coroutine buttonHintCoroutine;
  15. private Coroutine textHintCoroutine;
  16. //-------------------------------------------------
  17. public void ShowButtonHints( Hand hand )
  18. {
  19. if ( buttonHintCoroutine != null )
  20. {
  21. StopCoroutine( buttonHintCoroutine );
  22. }
  23. buttonHintCoroutine = StartCoroutine( TestButtonHints( hand ) );
  24. }
  25. //-------------------------------------------------
  26. public void ShowTextHints( Hand hand )
  27. {
  28. if ( textHintCoroutine != null )
  29. {
  30. StopCoroutine( textHintCoroutine );
  31. }
  32. textHintCoroutine = StartCoroutine( TestTextHints( hand ) );
  33. }
  34. //-------------------------------------------------
  35. public void DisableHints()
  36. {
  37. if ( buttonHintCoroutine != null )
  38. {
  39. StopCoroutine( buttonHintCoroutine );
  40. buttonHintCoroutine = null;
  41. }
  42. if ( textHintCoroutine != null )
  43. {
  44. StopCoroutine( textHintCoroutine );
  45. textHintCoroutine = null;
  46. }
  47. foreach ( Hand hand in Player.instance.hands )
  48. {
  49. ControllerButtonHints.HideAllButtonHints( hand );
  50. ControllerButtonHints.HideAllTextHints( hand );
  51. }
  52. }
  53. //-------------------------------------------------
  54. // Cycles through all the button hints on the controller
  55. //-------------------------------------------------
  56. private IEnumerator TestButtonHints( Hand hand )
  57. {
  58. ControllerButtonHints.HideAllButtonHints( hand );
  59. while ( true )
  60. {
  61. ControllerButtonHints.ShowButtonHint( hand, EVRButtonId.k_EButton_ApplicationMenu );
  62. yield return new WaitForSeconds( 1.0f );
  63. ControllerButtonHints.ShowButtonHint( hand, EVRButtonId.k_EButton_System );
  64. yield return new WaitForSeconds( 1.0f );
  65. ControllerButtonHints.ShowButtonHint( hand, EVRButtonId.k_EButton_Grip );
  66. yield return new WaitForSeconds( 1.0f );
  67. ControllerButtonHints.ShowButtonHint( hand, EVRButtonId.k_EButton_SteamVR_Trigger );
  68. yield return new WaitForSeconds( 1.0f );
  69. ControllerButtonHints.ShowButtonHint( hand, EVRButtonId.k_EButton_SteamVR_Touchpad );
  70. yield return new WaitForSeconds( 1.0f );
  71. ControllerButtonHints.HideAllButtonHints( hand );
  72. yield return new WaitForSeconds( 1.0f );
  73. }
  74. }
  75. //-------------------------------------------------
  76. // Cycles through all the text hints on the controller
  77. //-------------------------------------------------
  78. private IEnumerator TestTextHints( Hand hand )
  79. {
  80. ControllerButtonHints.HideAllTextHints( hand );
  81. while ( true )
  82. {
  83. ControllerButtonHints.ShowTextHint( hand, EVRButtonId.k_EButton_ApplicationMenu, "Application" );
  84. yield return new WaitForSeconds( 3.0f );
  85. ControllerButtonHints.ShowTextHint( hand, EVRButtonId.k_EButton_System, "System" );
  86. yield return new WaitForSeconds( 3.0f );
  87. ControllerButtonHints.ShowTextHint( hand, EVRButtonId.k_EButton_Grip, "Grip" );
  88. yield return new WaitForSeconds( 3.0f );
  89. ControllerButtonHints.ShowTextHint( hand, EVRButtonId.k_EButton_SteamVR_Trigger, "Trigger" );
  90. yield return new WaitForSeconds( 3.0f );
  91. ControllerButtonHints.ShowTextHint( hand, EVRButtonId.k_EButton_SteamVR_Touchpad, "Touchpad" );
  92. yield return new WaitForSeconds( 3.0f );
  93. ControllerButtonHints.HideAllTextHints( hand );
  94. yield return new WaitForSeconds( 3.0f );
  95. }
  96. }
  97. }
  98. }