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