@@ -51,19 +51,7 @@ protected override void Awake()
5151
5252 private void Start ( )
5353 {
54- if ( gazeManagerPointingData == null )
55- {
56- if ( GazeManager . IsInitialized )
57- {
58- gazeManagerPointingData = new PointerData ( GazeManager . Instance ) ;
59- }
60- }
61- else
62- {
63- Debug . Assert ( ReferenceEquals ( gazeManagerPointingData . PointingSource , GazeManager . Instance ) ) ;
64- }
65-
66- if ( ( pointers . Count == 0 ) && autoRegisterGazePointerIfNoPointersRegistered && GazeManager . IsInitialized )
54+ if ( pointers . Count == 0 && autoRegisterGazePointerIfNoPointersRegistered && GazeManager . IsInitialized )
6755 {
6856 RegisterPointer ( GazeManager . Instance ) ;
6957 }
@@ -261,27 +249,33 @@ public Camera UIRaycastCamera
261249
262250 public void RegisterPointer ( IPointingSource pointingSource )
263251 {
264- Debug . Assert ( pointingSource != null ) ;
252+ Debug . Assert ( pointingSource != null , "Can't register a pointer if you give us one." ) ;
253+
254+ int pointerIndex ;
255+ PointerData pointer ;
265256
266- if ( TryGetPointerIndex ( pointingSource ) != null )
257+ if ( TryGetPointerIndex ( pointingSource , out pointerIndex ) )
267258 {
268259 // This pointing source is already registered and active.
269260 return ;
270261 }
271262
272- PointerData pointer ;
273-
274263 if ( pointingSource is GazeManager )
275264 {
276265 if ( gazeManagerPointingData == null )
277266 {
278- gazeManagerPointingData = new PointerData ( pointingSource ) ;
267+ if ( GazeManager . IsInitialized )
268+ {
269+ gazeManagerPointingData = new PointerData ( GazeManager . Instance ) ;
270+ }
279271 }
280272 else
281273 {
274+ Debug . Assert ( ReferenceEquals ( gazeManagerPointingData . PointingSource , GazeManager . Instance ) ) ;
282275 gazeManagerPointingData . ResetFocusedObjects ( ) ;
283276 }
284277
278+ Debug . Assert ( gazeManagerPointingData != null ) ;
285279 pointer = gazeManagerPointingData ;
286280 }
287281 else
@@ -294,14 +288,17 @@ public void RegisterPointer(IPointingSource pointingSource)
294288
295289 public void UnregisterPointer ( IPointingSource pointingSource )
296290 {
297- Debug . Assert ( pointingSource != null ) ;
291+ Debug . Assert ( pointingSource != null , "Can't unregister a pointer if you give us one." ) ;
298292
299- int ? iPointer = TryGetPointerIndex ( pointingSource ) ;
300- Debug . Assert ( iPointer != null ) ;
293+ int pointerIndex ;
294+ TryGetPointerIndex ( pointingSource , out pointerIndex ) ;
295+
296+ PointerData pointer ;
297+ GetPointer ( pointingSource , out pointer ) ;
301298
302- PointerData pointer = pointers [ iPointer . Value ] ;
299+ // Should we be protecting against unregistering the GazeManager?
303300
304- pointers . RemoveAt ( iPointer . Value ) ;
301+ pointers . RemoveAt ( pointerIndex ) ;
305302
306303 // Raise focus events if needed:
307304
@@ -331,13 +328,11 @@ public void UnregisterPointer(IPointingSource pointingSource)
331328
332329 public FocusDetails ? TryGetFocusDetails ( BaseEventData eventData )
333330 {
334- for ( int iPointer = 0 ; iPointer < pointers . Count ; iPointer ++ )
331+ for ( int i = 0 ; i < pointers . Count ; i ++ )
335332 {
336- PointerData pointer = pointers [ iPointer ] ;
337-
338- if ( pointer . PointingSource . OwnsInput ( eventData ) )
333+ if ( pointers [ i ] . PointingSource . OwnsInput ( eventData ) )
339334 {
340- return pointer . End ;
335+ return pointers [ i ] . End ;
341336 }
342337 }
343338
@@ -356,20 +351,20 @@ public GameObject TryGetFocusedObject(BaseEventData eventData)
356351 IPointingSource pointingSource ;
357352 TryGetPointingSource ( eventData , out pointingSource ) ;
358353 PointerInputEventData pointerInputEventData = GetSpecificPointerEventData ( pointingSource ) ;
354+
355+ Debug . Assert ( pointerInputEventData != null ) ;
359356 pointerInputEventData . selectedObject = details . Value . Object ;
360357
361358 return details . Value . Object ;
362359 }
363360
364361 public bool TryGetPointingSource ( BaseEventData eventData , out IPointingSource pointingSource )
365362 {
366- for ( int iPointer = 0 ; iPointer < pointers . Count ; iPointer ++ )
363+ for ( int i = 0 ; i < pointers . Count ; i ++ )
367364 {
368- PointerData pointer = pointers [ iPointer ] ;
369-
370- if ( pointer . PointingSource . OwnsInput ( eventData ) )
365+ if ( pointers [ i ] . PointingSource . OwnsInput ( eventData ) )
371366 {
372- pointingSource = pointer . PointingSource ;
367+ pointingSource = pointers [ i ] . PointingSource ;
373368 return true ;
374369 }
375370 }
@@ -380,12 +375,28 @@ public bool TryGetPointingSource(BaseEventData eventData, out IPointingSource po
380375
381376 public FocusDetails GetFocusDetails ( IPointingSource pointingSource )
382377 {
383- return GetPointer ( pointingSource ) . End ;
378+ PointerData pointerData ;
379+ FocusDetails details = default ( FocusDetails ) ;
380+
381+ if ( GetPointer ( pointingSource , out pointerData ) )
382+ {
383+ details = pointerData . End ;
384+ }
385+
386+ return details ;
384387 }
385388
386389 public GameObject GetFocusedObject ( IPointingSource pointingSource )
387390 {
388- return GetPointer ( pointingSource ) . End . Object ;
391+ PointerData pointerData ;
392+ GameObject focusedObject = null ;
393+
394+ if ( GetPointer ( pointingSource , out pointerData ) )
395+ {
396+ focusedObject = pointerData . End . Object ;
397+ }
398+
399+ return focusedObject ;
389400 }
390401
391402 /// <summary>
@@ -426,12 +437,19 @@ public PointerInputEventData GetGazePointerEventData()
426437
427438 public PointerInputEventData GetSpecificPointerEventData ( IPointingSource pointer )
428439 {
429- return GetPointer ( pointer ) . UnityUIPointerData ;
440+ PointerData pointerEventData ;
441+ return GetPointer ( pointer , out pointerEventData ) ? pointerEventData . UnityUIPointerData : null ;
430442 }
431443
432444 public float GetPointingExtent ( IPointingSource pointingSource )
433445 {
434- return GetPointingExtent ( GetPointer ( pointingSource ) ) ;
446+ PointerData pointerData ;
447+ return GetPointer ( pointingSource , out pointerData ) ? GetPointingExtent ( pointerData ) : pointingExtent ;
448+ }
449+
450+ private float GetPointingExtent ( PointerData pointer )
451+ {
452+ return pointer . PointingSource . ExtentOverride ?? pointingExtent ;
435453 }
436454
437455 #endregion
@@ -777,32 +795,33 @@ private void RaisePointerSpecificFocusChangedEvents(IPointingSource pointer, Gam
777795 }
778796 }
779797
780- private PointerData GetPointer ( IPointingSource pointingSource )
798+ private bool GetPointer ( IPointingSource pointingSource , out PointerData pointerData )
781799 {
782- Debug . Assert ( pointers . Count > 0 , "No Pointers registered!" ) ;
783- int ? iPointer = TryGetPointerIndex ( pointingSource ) ;
784- return iPointer != null ? pointers [ iPointer . Value ] : pointers [ 0 ] ;
800+ int pointerIndex ;
801+
802+ if ( TryGetPointerIndex ( pointingSource , out pointerIndex ) )
803+ {
804+ pointerData = pointers [ pointerIndex ] ;
805+ return true ;
806+ }
807+
808+ pointerData = null ;
809+ return false ;
785810 }
786811
787- private int ? TryGetPointerIndex ( IPointingSource pointingSource )
812+ private bool TryGetPointerIndex ( IPointingSource pointingSource , out int pointerIndex )
788813 {
789- int ? found = null ;
790-
791814 for ( int i = 0 ; i < pointers . Count ; i ++ )
792815 {
793- if ( pointers [ i ] . PointingSource == pointingSource )
816+ if ( pointingSource == pointers [ i ] . PointingSource )
794817 {
795- found = i ;
796- break ;
818+ pointerIndex = i ;
819+ return true ;
797820 }
798821 }
799822
800- return found ;
801- }
802-
803- private float GetPointingExtent ( PointerData pointer )
804- {
805- return ( pointer . PointingSource . ExtentOverride ?? pointingExtent ) ;
823+ pointerIndex = - 1 ;
824+ return false ;
806825 }
807826
808827 private RaycastHit ? PrioritizeHits ( RaycastHit [ ] hits , LayerMask [ ] layerMasks )
0 commit comments