77using Microsoft . MixedReality . Toolkit . Internal . Interfaces . InputSystem ;
88using Microsoft . MixedReality . Toolkit . Internal . Managers ;
99using Microsoft . MixedReality . Toolkit . Internal . Utilities ;
10+ using Microsoft . MixedReality . Toolkit . Internal . Utilities . Physics ;
1011using System ;
1112using System . Collections . Generic ;
1213using UnityEngine ;
@@ -530,6 +531,8 @@ private void UpdatePointers()
530531
531532 if ( debugDrawPointingRays )
532533 {
534+ MixedRealityRaycaster . DebugEnabled = debugDrawPointingRays ;
535+
533536 Color rayColor ;
534537
535538 if ( ( debugDrawPointingRayColors != null ) && ( debugDrawPointingRayColors . Length > 0 ) )
@@ -581,7 +584,7 @@ private void UpdatePointer(PointerData pointer)
581584 }
582585
583586 // Set the pointer's result last
584- pointer . Pointer . Result = pointer as IPointerResult ;
587+ pointer . Pointer . Result = pointer ;
585588 }
586589 }
587590
@@ -591,12 +594,14 @@ private void UpdatePointer(PointerData pointer)
591594 pointer . Pointer . OnPostRaycast ( ) ;
592595 }
593596
597+ #region Physics Raycasting
598+
594599 /// <summary>
595600 /// Perform a Unity physics Raycast to determine which scene objects with a collider is currently being gazed at, if any.
596601 /// </summary>
597602 /// <param name="pointer"></param>
598603 /// <param name="prioritizedLayerMasks"></param>
599- private void RaycastPhysics ( PointerData pointer , LayerMask [ ] prioritizedLayerMasks )
604+ private static void RaycastPhysics ( PointerData pointer , LayerMask [ ] prioritizedLayerMasks )
600605 {
601606 bool isHit = false ;
602607 int rayStepIndex = 0 ;
@@ -609,15 +614,34 @@ private void RaycastPhysics(PointerData pointer, LayerMask[] prioritizedLayerMas
609614 // Check raycast for each step in the pointing source
610615 for ( int i = 0 ; i < pointer . Pointer . Rays . Length ; i ++ )
611616 {
612- if ( RaycastPhysicsStep ( pointer . Pointer . Rays [ i ] , prioritizedLayerMasks , out physicsHit ) )
617+ switch ( pointer . Pointer . RaycastMode )
613618 {
614- // Set the pointer source's origin ray to this step
615- isHit = true ;
616- rayStep = pointer . Pointer . Rays [ i ] ;
617- rayStepIndex = i ;
618- // No need to continue once we've hit something
619- break ;
619+ case RaycastModeType . Simple :
620+ if ( MixedRealityRaycaster . RaycastSimplePhysicsStep ( pointer . Pointer . Rays [ i ] , prioritizedLayerMasks , out physicsHit ) )
621+ {
622+ // Set the pointer source's origin ray to this step
623+ isHit = true ;
624+ rayStep = pointer . Pointer . Rays [ i ] ;
625+ rayStepIndex = i ;
626+ }
627+ break ;
628+ case RaycastModeType . Box :
629+ Debug . LogWarning ( "Box Raycasting Mode not supported for pointers." ) ;
630+ break ;
631+ case RaycastModeType . Sphere :
632+ if ( MixedRealityRaycaster . RaycastSpherePhysicsStep ( pointer . Pointer . Rays [ i ] , pointer . Pointer . SphereCastRadius , prioritizedLayerMasks , out physicsHit ) )
633+ {
634+ // Set the pointer source's origin ray to this step
635+ isHit = true ;
636+ rayStep = pointer . Pointer . Rays [ i ] ;
637+ rayStepIndex = i ;
638+ }
639+ break ;
640+ default :
641+ throw new ArgumentOutOfRangeException ( ) ;
620642 }
643+
644+ if ( isHit ) { break ; }
621645 }
622646
623647 if ( isHit )
@@ -630,62 +654,9 @@ private void RaycastPhysics(PointerData pointer, LayerMask[] prioritizedLayerMas
630654 }
631655 }
632656
633- /// <summary>
634- /// Raycasts each physics <see cref="RayStep"/>
635- /// </summary>
636- /// <param name="step"></param>
637- /// <param name="prioritizedLayerMasks"></param>
638- /// <param name="physicsHit"></param>
639- /// <returns></returns>
640- private bool RaycastPhysicsStep ( RayStep step , LayerMask [ ] prioritizedLayerMasks , out RaycastHit physicsHit )
641- {
642- return prioritizedLayerMasks . Length == 1
643- // If there is only one priority, don't prioritize
644- ? Physics . Raycast ( step . Origin , step . Direction , out physicsHit , step . Length , prioritizedLayerMasks [ 0 ] )
645- // Raycast across all layers and prioritize
646- : TryGetPrioritizedHit ( Physics . RaycastAll ( step . Origin , step . Direction , step . Length , Physics . AllLayers ) , prioritizedLayerMasks , out physicsHit ) ;
647- }
648-
649- /// <summary>
650- /// Tries to ge the prioritized raycast hit based on the prioritized layer masks.
651- /// <para><remarks>Sorts all hit objects first by layerMask, then by distance.</remarks></para>
652- /// </summary>
653- /// <param name="hits"></param>
654- /// <param name="priorityLayers"></param>
655- /// <param name="raycastHit"></param>
656- /// <returns>The minimum distance hit within the first layer that has hits</returns>
657- private static bool TryGetPrioritizedHit ( RaycastHit [ ] hits , LayerMask [ ] priorityLayers , out RaycastHit raycastHit )
658- {
659- raycastHit = default ( RaycastHit ) ;
660-
661- if ( hits . Length == 0 )
662- {
663- return false ;
664- }
665-
666- for ( int layerMaskIdx = 0 ; layerMaskIdx < priorityLayers . Length ; layerMaskIdx ++ )
667- {
668- RaycastHit ? minHit = null ;
669-
670- for ( int hitIdx = 0 ; hitIdx < hits . Length ; hitIdx ++ )
671- {
672- RaycastHit hit = hits [ hitIdx ] ;
673- if ( hit . transform . gameObject . layer . IsInLayerMask ( priorityLayers [ layerMaskIdx ] ) &&
674- ( minHit == null || hit . distance < minHit . Value . distance ) )
675- {
676- minHit = hit ;
677- }
678- }
679-
680- if ( minHit != null )
681- {
682- raycastHit = minHit . Value ;
683- return true ;
684- }
685- }
657+ #endregion Physics Raycasting
686658
687- return false ;
688- }
659+ #region uGUI Graphics Raycasting
689660
690661 /// <summary>
691662 /// Perform a Unity Graphics Raycast to determine which uGUI element is currently being gazed at, if any.
@@ -736,6 +707,15 @@ private void RaycastGraphics(PointerData pointer, LayerMask[] prioritizedLayerMa
736707 }
737708 }
738709
710+ /// <summary>
711+ /// Raycasts each graphic <see cref="RayStep"/>
712+ /// </summary>
713+ /// <param name="pointer"></param>
714+ /// <param name="step"></param>
715+ /// <param name="prioritizedLayerMasks"></param>
716+ /// <param name="overridePhysicsRaycast"></param>
717+ /// <param name="uiRaycastResult"></param>
718+ /// <returns></returns>
739719 private bool RaycastGraphicsStep ( PointerData pointer , RayStep step , LayerMask [ ] prioritizedLayerMasks , out bool overridePhysicsRaycast , out RaycastResult uiRaycastResult )
740720 {
741721 // Move the uiRaycast camera to the current pointer's position.
@@ -790,6 +770,8 @@ private bool RaycastGraphicsStep(PointerData pointer, RayStep step, LayerMask[]
790770 return false ;
791771 }
792772
773+ #endregion uGUI Graphics Raycasting
774+
793775 /// <summary>
794776 /// Raises the Focus Events to the Input Manger if needed.
795777 /// </summary>
0 commit comments