@@ -86,6 +86,8 @@ public Vector3 ManipulationHandPosition
8686 // we want for manipulation
8787 private GestureRecognizer manipulationRecognizer ;
8888
89+ private bool hasRecognitionStarted = false ;
90+
8991 private bool HandPressed { get { return pressedHands . Count > 0 ; } }
9092 private HashSet < uint > pressedHands = new HashSet < uint > ( ) ;
9193
@@ -107,6 +109,11 @@ void Start()
107109
108110 gestureRecognizer . TappedEvent += GestureRecognizer_TappedEvent ;
109111
112+ // We need to send pressed and released events to UI so they can provide visual feedback
113+ // of the current state of the UI based on user input.
114+ gestureRecognizer . RecognitionStartedEvent += GestureRecognizer_RecognitionStartedEvent ;
115+ gestureRecognizer . RecognitionEndedEvent += GestureRecogniser_RecognitionEndedEvent ;
116+
110117 manipulationRecognizer . ManipulationStartedEvent += ManipulationRecognizer_ManipulationStartedEvent ;
111118 manipulationRecognizer . ManipulationUpdatedEvent += ManipulationRecognizer_ManipulationUpdatedEvent ;
112119 manipulationRecognizer . ManipulationCompletedEvent += ManipulationRecognizer_ManipulationCompletedEvent ;
@@ -116,7 +123,7 @@ void Start()
116123 gestureRecognizer . StartCapturingGestures ( ) ;
117124 manipulationRecognizer . StartCapturingGestures ( ) ;
118125 }
119-
126+
120127 private void InteractionManager_SourcePressed ( InteractionSourceState state )
121128 {
122129 if ( ! HandPressed )
@@ -150,6 +157,16 @@ private void GestureRecognizer_TappedEvent(InteractionSourceKind source, int tap
150157 OnTap ( ) ;
151158 }
152159
160+ private void GestureRecognizer_RecognitionStartedEvent ( InteractionSourceKind source , Ray headRay )
161+ {
162+ OnRecognitionStarted ( ) ;
163+ }
164+
165+ private void GestureRecogniser_RecognitionEndedEvent ( InteractionSourceKind source , Ray headRay )
166+ {
167+ OnRecognitionEndeded ( ) ;
168+ }
169+
153170 private void OnTap ( )
154171 {
155172 if ( FocusedObject != null )
@@ -158,6 +175,25 @@ private void OnTap()
158175 }
159176 }
160177
178+ private void OnRecognitionStarted ( )
179+ {
180+ if ( FocusedObject != null )
181+ {
182+ hasRecognitionStarted = true ;
183+ FocusedObject . SendMessage ( "OnPressed" , SendMessageOptions . DontRequireReceiver ) ;
184+ }
185+ }
186+
187+ private void OnRecognitionEndeded ( )
188+ {
189+ if ( FocusedObject != null && hasRecognitionStarted )
190+ {
191+ FocusedObject . SendMessage ( "OnReleased" , SendMessageOptions . DontRequireReceiver ) ;
192+ }
193+
194+ hasRecognitionStarted = false ;
195+ }
196+
161197 private void ManipulationRecognizer_ManipulationStartedEvent ( InteractionSourceKind source , Vector3 cumulativeDelta , Ray headRay )
162198 {
163199 // Don't start another manipulation gesture if one is already underway
@@ -202,6 +238,8 @@ private void OnManipulation(bool inProgress, Vector3 offset)
202238
203239 void LateUpdate ( )
204240 {
241+ // set the next focus object to see if focus has changed, but don't replace the current focused object
242+ // until all the inputs are handled, like Unity Editor input for OnTap().
205243 GameObject newFocusedObject ;
206244
207245 if ( GazeManager . Instance . Hit &&
@@ -218,27 +256,36 @@ void LateUpdate()
218256 newFocusedObject = OverrideFocusedObject ;
219257 }
220258
221- if ( FocusedObject != newFocusedObject )
222- {
223- // If the currently focused object doesn't match the old focused object, cancel the current gesture.
224- // Start looking for new gestures. This is to prevent applying gestures from one hologram to another.
225- gestureRecognizer . CancelGestures ( ) ;
226- FocusedObject = newFocusedObject ;
227- gestureRecognizer . StartCapturingGestures ( ) ;
228- }
259+ bool focusedChanged = FocusedObject != newFocusedObject ;
229260
230261#if UNITY_EDITOR
231262 if ( Input . GetMouseButtonDown ( 1 ) || Input . GetKeyDown ( EditorSelectKey ) )
232263 {
233264 OnTap ( ) ;
265+ OnRecognitionStarted ( ) ;
266+ }
267+
268+ if ( Input . GetMouseButtonUp ( 1 ) || Input . GetKeyUp ( EditorSelectKey ) || focusedChanged )
269+ {
270+ OnRecognitionEndeded ( ) ;
234271 }
235272#endif
273+ if ( focusedChanged )
274+ {
275+ // If the currently focused object doesn't match the new focused object, cancel the current gesture.
276+ // Start looking for new gestures. This is to prevent applying gestures from one hologram to another.
277+ gestureRecognizer . CancelGestures ( ) ;
278+ FocusedObject = newFocusedObject ;
279+ gestureRecognizer . StartCapturingGestures ( ) ;
280+ }
236281 }
237282
238283 void OnDestroy ( )
239284 {
240285 gestureRecognizer . StopCapturingGestures ( ) ;
241286 gestureRecognizer . TappedEvent -= GestureRecognizer_TappedEvent ;
287+ gestureRecognizer . RecognitionStartedEvent -= GestureRecognizer_RecognitionStartedEvent ;
288+ gestureRecognizer . RecognitionEndedEvent -= GestureRecogniser_RecognitionEndedEvent ;
242289
243290 manipulationRecognizer . StopCapturingGestures ( ) ;
244291 manipulationRecognizer . ManipulationStartedEvent -= ManipulationRecognizer_ManipulationStartedEvent ;
0 commit comments