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