-
Notifications
You must be signed in to change notification settings - Fork 0
/
HandsManager.cs
154 lines (120 loc) · 4.65 KB
/
HandsManager.cs
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
using UnityEngine.VR.WSA.Input;
using UnityEngine;
using HoloToolkit.Unity.InputModule;
using System;
using HoloToolkit.Unity;
/// <summary>
/// HandsManager keeps track of when a hand is detected.
/// </summary>
public class HandsManager : Singleton<HandsManager>, ISourceStateHandler
{
[Tooltip("Audio clip to play when Finger Pressed.")]
public AudioClip FingerPressedSound;
private AudioSource audioSource;
/// <summary>
/// Tracks the hand detected state.
/// </summary>
public bool HandDetected
{
get;
private set;
}
// Keeps track of the GameObject that the hand is interacting with.
public GameObject FocusedGameObject { get; private set; }
void Awake()
{
base.Awake();
EnableAudioHapticFeedback();
//TODO: Presently, this uses gaze. In the future, do I want to just try to use hands?
InteractionManager.SourceDetected += InteractionManager_SourceDetected;
InteractionManager.SourceLost += InteractionManager_SourceLost;
// 2.a: Register for SourceManager.SourcePressed event.
InteractionManager.SourcePressed += InteractionManager_SourcePressed;
// 2.a: Register for SourceManager.SourceReleased event.
InteractionManager.SourceReleased += InteractionManager_SourceReleased;
// 2.a: Initialize FocusedGameObject as null.
FocusedGameObject = null;
}
private void Start()
{
Debug.Log(InputManager.Instance);
InputManager.Instance.PushModalInputHandler(gameObject);
}
private void EnableAudioHapticFeedback()
{
// If this hologram has an audio clip, add an AudioSource with this clip.
if (FingerPressedSound != null)
{
audioSource = GetComponent<AudioSource>();
if (audioSource == null)
{
audioSource = gameObject.AddComponent<AudioSource>();
}
audioSource.clip = FingerPressedSound;
audioSource.playOnAwake = false;
audioSource.spatialBlend = 1;
audioSource.dopplerLevel = 0;
}
}
private void InteractionManager_SourceDetected(InteractionSourceState hand)
{
HandDetected = true;
}
private void InteractionManager_SourceLost(InteractionSourceState hand)
{
HandDetected = false;
// 2.a: Reset FocusedGameObject.
ResetFocusedGameObject();
}
private void InteractionManager_SourcePressed(InteractionSourceState hand)
{
/*
if (InteractibleManager.Instance.FocusedGameObject != null)
{
// Play a select sound if we have an audio source and are not targeting an asset with a select sound.
if (audioSource != null && !audioSource.isPlaying &&
(InteractibleManager.Instance.FocusedGameObject.GetComponent<Interactible>() != null &&
InteractibleManager.Instance.FocusedGameObject.GetComponent<Interactible>().TargetFeedbackSound == null))
{
audioSource.Play();
}
// 2.a: Cache InteractibleManager's FocusedGameObject in FocusedGameObject.
FocusedGameObject = InteractibleManager.Instance.FocusedGameObject;
}
*/
}
private void InteractionManager_SourceReleased(InteractionSourceState hand)
{
// 2.a: Reset FocusedGameObject.
ResetFocusedGameObject();
}
private void ResetFocusedGameObject()
{
// 2.a: Set FocusedGameObject to be null.
FocusedGameObject = null;
// 2.a: On GestureManager call ResetGestureRecognizers
// to complete any currently active gestures.
//GestureManager.Instance.ResetGestureRecognizers();
}
void OnDestroy()
{
InteractionManager.SourceDetected -= InteractionManager_SourceDetected;
InteractionManager.SourceLost -= InteractionManager_SourceLost;
// 2.a: Unregister the SourceManager.SourceReleased event.
InteractionManager.SourceReleased -= InteractionManager_SourceReleased;
// 2.a: Unregister for SourceManager.SourcePressed event.
InteractionManager.SourcePressed -= InteractionManager_SourcePressed;
}
public void OnSourceDetected(SourceStateEventData eventData)
{
Debug.Log(eventData.InputSource.GetSupportedInputInfo(eventData.SourceId));
Debug.Log("Type is " + eventData.InputSource.GetType());
Debug.Log("module is " + eventData.currentInputModule);
HandDetected = true;
}
public void OnSourceLost(SourceStateEventData eventData)
{
HandDetected = false;
// Debug.Log(eventData.InputSource.GetType());
}
}