11// Copyright (c) Microsoft Corporation. All rights reserved.
22// Licensed under the MIT License. See LICENSE in the project root for license information.
33
4- using Microsoft . MixedReality . Toolkit ;
54using Microsoft . MixedReality . Toolkit . Input ;
65using UnityEngine ;
76
8- public class GestureTester : MonoBehaviour , IMixedRealityGestureHandler < Vector3 >
7+ namespace Microsoft . MixedReality . Toolkit . Examples
98{
10- public GameObject HoldIndicator = null ;
11- public GameObject ManipulationIndicator = null ;
12- public GameObject NavigationIndicator = null ;
13-
14- public Material DefaultMaterial = null ;
15- public Material HoldMaterial = null ;
16- public Material ManipulationMaterial = null ;
17- public Material NavigationMaterial = null ;
18-
19- public GameObject RailsAxisX = null ;
20- public GameObject RailsAxisY = null ;
21- public GameObject RailsAxisZ = null ;
22-
23- void OnEnable ( )
9+ public class GestureTester : MonoBehaviour , IMixedRealityGestureHandler < Vector3 >
2410 {
25- HideRails ( ) ;
26- }
11+ public GameObject HoldIndicator = null ;
12+ public GameObject ManipulationIndicator = null ;
13+ public GameObject NavigationIndicator = null ;
2714
28- public void OnGestureStarted ( InputEventData eventData )
29- {
30- Debug . Log ( $ "OnGestureStarted [{ Time . frameCount } ]: { eventData . MixedRealityInputAction . Description } ") ;
15+ public Material DefaultMaterial = null ;
16+ public Material HoldMaterial = null ;
17+ public Material ManipulationMaterial = null ;
18+ public Material NavigationMaterial = null ;
3119
32- var action = eventData . MixedRealityInputAction . Description ;
33- if ( action == "Hold Action" )
34- {
35- SetIndicator ( HoldIndicator , "Hold: started" , HoldMaterial ) ;
36- }
37- else if ( action == "Manipulate Action" )
20+ public GameObject RailsAxisX = null ;
21+ public GameObject RailsAxisY = null ;
22+ public GameObject RailsAxisZ = null ;
23+
24+ void OnEnable ( )
3825 {
39- SetIndicator ( ManipulationIndicator , $ "Manipulation: started { Vector3 . zero } " , ManipulationMaterial , Vector3 . zero ) ;
26+ HideRails ( ) ;
4027 }
41- else if ( action == "Navigation Action" )
28+
29+ public void OnGestureStarted ( InputEventData eventData )
4230 {
43- SetIndicator ( NavigationIndicator , $ "Navigation: started { Vector3 . zero } ", NavigationMaterial , Vector3 . zero ) ;
44- ShowRails ( Vector3 . zero ) ;
45- }
46- }
31+ Debug . Log ( $ "OnGestureStarted [{ Time . frameCount } ]: { eventData . MixedRealityInputAction . Description } ") ;
4732
48- public void OnGestureUpdated ( InputEventData eventData )
49- {
50- Debug . Log ( $ "OnGestureUpdated [{ Time . frameCount } ]: { eventData . MixedRealityInputAction . Description } ") ;
33+ var action = eventData . MixedRealityInputAction . Description ;
34+ if ( action == "Hold Action" )
35+ {
36+ SetIndicator ( HoldIndicator , "Hold: started" , HoldMaterial ) ;
37+ }
38+ else if ( action == "Manipulate Action" )
39+ {
40+ SetIndicator ( ManipulationIndicator , $ "Manipulation: started { Vector3 . zero } ", ManipulationMaterial , Vector3 . zero ) ;
41+ }
42+ else if ( action == "Navigation Action" )
43+ {
44+ SetIndicator ( NavigationIndicator , $ "Navigation: started { Vector3 . zero } ", NavigationMaterial , Vector3 . zero ) ;
45+ ShowRails ( Vector3 . zero ) ;
46+ }
47+ }
5148
52- var action = eventData . MixedRealityInputAction . Description ;
53- if ( action == "Hold Action" )
49+ public void OnGestureUpdated ( InputEventData eventData )
5450 {
55- SetIndicator ( HoldIndicator , "Hold: updated" , DefaultMaterial ) ;
51+ Debug . Log ( $ "OnGestureUpdated [{ Time . frameCount } ]: { eventData . MixedRealityInputAction . Description } ") ;
52+
53+ var action = eventData . MixedRealityInputAction . Description ;
54+ if ( action == "Hold Action" )
55+ {
56+ SetIndicator ( HoldIndicator , "Hold: updated" , DefaultMaterial ) ;
57+ }
5658 }
57- }
5859
5960 public void OnGestureUpdated ( InputEventData < Vector3 > eventData )
6061 {
@@ -72,16 +73,16 @@ public void OnGestureUpdated(InputEventData<Vector3> eventData)
7273 }
7374 }
7475
75- public void OnGestureCompleted ( InputEventData eventData )
76- {
77- Debug . Log ( $ "OnGestureCompleted [{ Time . frameCount } ]: { eventData . MixedRealityInputAction . Description } ") ;
78-
79- var action = eventData . MixedRealityInputAction . Description ;
80- if ( action == "Hold Action" )
76+ public void OnGestureCompleted ( InputEventData eventData )
8177 {
82- SetIndicator ( HoldIndicator , "Hold: completed" , DefaultMaterial ) ;
78+ Debug . Log ( $ "OnGestureCompleted [{ Time . frameCount } ]: { eventData . MixedRealityInputAction . Description } ") ;
79+
80+ var action = eventData . MixedRealityInputAction . Description ;
81+ if ( action == "Hold Action" )
82+ {
83+ SetIndicator ( HoldIndicator , "Hold: completed" , DefaultMaterial ) ;
84+ }
8385 }
84- }
8586
8687 public void OnGestureCompleted ( InputEventData < Vector3 > eventData )
8788 {
@@ -99,84 +100,85 @@ public void OnGestureCompleted(InputEventData<Vector3> eventData)
99100 }
100101 }
101102
102- public void OnGestureCanceled ( InputEventData eventData )
103- {
104- Debug . Log ( $ "OnGestureCanceled [{ Time . frameCount } ]: { eventData . MixedRealityInputAction . Description } ") ;
105-
106- var action = eventData . MixedRealityInputAction . Description ;
107- if ( action == "Hold Action" )
108- {
109- SetIndicator ( HoldIndicator , "Hold: canceled" , DefaultMaterial ) ;
110- }
111- else if ( action == "Manipulate Action" )
103+ public void OnGestureCanceled ( InputEventData eventData )
112104 {
113- SetIndicator ( ManipulationIndicator , "Manipulation: canceled" , DefaultMaterial ) ;
114- }
115- else if ( action == "Navigation Action" )
116- {
117- SetIndicator ( NavigationIndicator , "Navigation: canceled" , DefaultMaterial ) ;
118- HideRails ( ) ;
119- }
120- }
105+ Debug . Log ( $ "OnGestureCanceled [{ Time . frameCount } ]: { eventData . MixedRealityInputAction . Description } ") ;
121106
122- private void SetIndicator ( GameObject indicator , string label , Material material )
123- {
124- if ( indicator )
125- {
126- var renderer = indicator . GetComponentInChildren < Renderer > ( ) ;
127- if ( material && renderer )
107+ var action = eventData . MixedRealityInputAction . Description ;
108+ if ( action == "Hold Action" )
128109 {
129- renderer . material = material ;
110+ SetIndicator ( HoldIndicator , "Hold: canceled" , DefaultMaterial ) ;
130111 }
131- var text = indicator . GetComponentInChildren < TextMesh > ( ) ;
132- if ( text )
112+ else if ( action == "Manipulate Action" )
133113 {
134- text . text = label ;
114+ SetIndicator ( ManipulationIndicator , "Manipulation: canceled" , DefaultMaterial ) ;
115+ }
116+ else if ( action == "Navigation Action" )
117+ {
118+ SetIndicator ( NavigationIndicator , "Navigation: canceled" , DefaultMaterial ) ;
119+ HideRails ( ) ;
135120 }
136121 }
137- }
138122
139- private void SetIndicator ( GameObject indicator , string label , Material material , Vector3 position )
140- {
141- SetIndicator ( indicator , label , material ) ;
142- if ( indicator )
123+ private void SetIndicator ( GameObject indicator , string label , Material material )
143124 {
144- indicator . transform . localPosition = position ;
125+ if ( indicator )
126+ {
127+ var renderer = indicator . GetComponentInChildren < Renderer > ( ) ;
128+ if ( material && renderer )
129+ {
130+ renderer . material = material ;
131+ }
132+ var text = indicator . GetComponentInChildren < TextMesh > ( ) ;
133+ if ( text )
134+ {
135+ text . text = label ;
136+ }
137+ }
145138 }
146- }
147-
148- private void ShowRails ( Vector3 position )
149- {
150- var gestureProfile = MixedRealityToolkit . Instance . ActiveProfile . InputSystemProfile . GesturesProfile ;
151- var useRails = gestureProfile . UseRailsNavigation ;
152139
153- if ( RailsAxisX )
154- {
155- RailsAxisX . SetActive ( ! useRails || position . x != 0.0f ) ;
156- }
157- if ( RailsAxisY )
158- {
159- RailsAxisY . SetActive ( ! useRails || position . y != 0.0f ) ;
160- }
161- if ( RailsAxisZ )
140+ private void SetIndicator ( GameObject indicator , string label , Material material , Vector3 position )
162141 {
163- RailsAxisZ . SetActive ( ! useRails || position . z != 0.0f ) ;
142+ SetIndicator ( indicator , label , material ) ;
143+ if ( indicator )
144+ {
145+ indicator . transform . localPosition = position ;
146+ }
164147 }
165- }
166148
167- private void HideRails ( )
168- {
169- if ( RailsAxisX )
170- {
171- RailsAxisX . SetActive ( false ) ;
172- }
173- if ( RailsAxisY )
149+ private void ShowRails ( Vector3 position )
174150 {
175- RailsAxisY . SetActive ( false ) ;
151+ var gestureProfile = MixedRealityToolkit . Instance . ActiveProfile . InputSystemProfile . GesturesProfile ;
152+ var useRails = gestureProfile . UseRailsNavigation ;
153+
154+ if ( RailsAxisX )
155+ {
156+ RailsAxisX . SetActive ( ! useRails || position . x != 0.0f ) ;
157+ }
158+ if ( RailsAxisY )
159+ {
160+ RailsAxisY . SetActive ( ! useRails || position . y != 0.0f ) ;
161+ }
162+ if ( RailsAxisZ )
163+ {
164+ RailsAxisZ . SetActive ( ! useRails || position . z != 0.0f ) ;
165+ }
176166 }
177- if ( RailsAxisZ )
167+
168+ private void HideRails ( )
178169 {
179- RailsAxisZ . SetActive ( false ) ;
170+ if ( RailsAxisX )
171+ {
172+ RailsAxisX . SetActive ( false ) ;
173+ }
174+ if ( RailsAxisY )
175+ {
176+ RailsAxisY . SetActive ( false ) ;
177+ }
178+ if ( RailsAxisZ )
179+ {
180+ RailsAxisZ . SetActive ( false ) ;
181+ }
180182 }
181183 }
182- }
184+ }
0 commit comments