@@ -68,7 +68,7 @@ public IEnumerator ProximityDetectorTest()
6868 }
6969
7070 /// <summary>
71- /// Tests the basic Interaction detector. The controller should enter one mode during hover, another during select, and fall back to the default mode during neither
71+ /// Tests the basic Interaction detector. The controller should enter one mode during hover, another during select, and fall back to the default mode during neither.
7272 /// </summary>
7373 [ UnityTest ]
7474 public IEnumerator InteractionDetectorTest ( )
@@ -89,28 +89,40 @@ public IEnumerator InteractionDetectorTest()
8989 yield return rightHand . AimAt ( cube . transform . position ) ;
9090 yield return RuntimeTestUtilities . WaitForUpdates ( ) ;
9191
92- InteractionMode currentMode = rightHandController . GetComponentInChildren < MRTKRayInteractor > ( ) . GetComponent < InteractionDetector > ( ) . ModeOnHover ;
93- Assert . AreEqual ( currentMode , rightHandController . GetComponentInChildren < MRTKRayInteractor > ( ) . GetComponent < InteractionDetector > ( ) . ModeOnDetection ) ;
94- ValidateInteractionModeActive ( rightHandController , currentMode ) ;
92+ InteractionDetector interactionDetector = rightHandController . GetComponentInChildren < MRTKRayInteractor > ( ) . GetComponent < InteractionDetector > ( ) ;
93+
94+ InteractionMode expectedMode = interactionDetector . ModeOnHover ;
95+ Assert . AreEqual ( expectedMode , interactionDetector . ModeOnDetection ) ;
96+ ValidateInteractionModeActive ( rightHandController , expectedMode ) ;
9597
98+ // Select the cube and check that we're in the correct mode
9699 yield return rightHand . SetHandshape ( HandshapeTypes . HandshapeId . Grab ) ;
97100 yield return RuntimeTestUtilities . WaitForUpdates ( ) ;
98- currentMode = rightHandController . GetComponentInChildren < MRTKRayInteractor > ( ) . GetComponent < InteractionDetector > ( ) . ModeOnSelect ;
99- Assert . AreEqual ( currentMode , rightHandController . GetComponentInChildren < MRTKRayInteractor > ( ) . GetComponent < InteractionDetector > ( ) . ModeOnDetection ) ;
100- ValidateInteractionModeActive ( rightHandController , currentMode ) ;
101+ expectedMode = interactionDetector . ModeOnSelect ;
102+ Assert . AreEqual ( expectedMode , interactionDetector . ModeOnDetection ) ;
103+ ValidateInteractionModeActive ( rightHandController , expectedMode ) ;
101104
102- // move the hand far away and validate that we are in the default mode
105+ // Release the selection and move the hand far away and validate that we are in the default mode
103106 yield return rightHand . SetHandshape ( HandshapeTypes . HandshapeId . Open ) ;
104107 yield return RuntimeTestUtilities . WaitForUpdates ( ) ;
105- yield return rightHand . MoveTo ( cube . transform . position + new Vector3 ( 3.0f , 0 , 0 ) ) ;
108+ yield return rightHand . MoveTo ( cube . transform . position + new Vector3 ( 3.0f , 0 , 0 ) ) ;
106109 yield return RuntimeTestUtilities . WaitForUpdates ( ) ;
110+ expectedMode = InteractionModeManager . Instance . DefaultMode ;
111+ ValidateInteractionModeActive ( rightHandController , expectedMode ) ;
107112
108- currentMode = InteractionModeManager . Instance . DefaultMode ;
109- ValidateInteractionModeActive ( rightHandController , currentMode ) ;
113+ // Put the hand into a grab state and validate that we are in the default mode, since we're not selecting an object
114+ yield return rightHand . SetHandshape ( HandshapeTypes . HandshapeId . Grab ) ;
115+ yield return RuntimeTestUtilities . WaitForUpdates ( ) ;
116+ ValidateInteractionModeActive ( rightHandController , expectedMode ) ;
117+
118+ // Release the grab state and validate that we are in the default mode
119+ yield return rightHand . SetHandshape ( HandshapeTypes . HandshapeId . Open ) ;
120+ yield return RuntimeTestUtilities . WaitForUpdates ( ) ;
121+ ValidateInteractionModeActive ( rightHandController , expectedMode ) ;
110122 }
111123
112124 /// <summary>
113- /// Tests that mode mediation works properly.
125+ /// Tests that mode mediation works properly.
114126 /// </summary>
115127 /// <remarks>
116128 /// The interaction mode with the higher priority should be the valid one which affects the controller.
@@ -136,12 +148,14 @@ public IEnumerator ModeMediationTest()
136148 InputTestUtilities . SetHandAnchorPoint ( Handedness . Right , ControllerAnchorPoint . Grab ) ;
137149 yield return RuntimeTestUtilities . WaitForUpdates ( ) ;
138150
139- // Moving the hand to a position where it's far ray is hovering over the cube
151+ InteractionDetector rayInteractionDetector = rightHandController . GetComponentInChildren < MRTKRayInteractor > ( ) . GetComponent < InteractionDetector > ( ) ;
152+
153+ // Moving the hand to a position where its far ray is hovering over the cube
140154 yield return rightHand . AimAt ( cube . transform . position ) ;
141155 yield return RuntimeTestUtilities . WaitForUpdates ( ) ;
142- InteractionMode farRayMode = rightHandController . GetComponentInChildren < MRTKRayInteractor > ( ) . GetComponent < InteractionDetector > ( ) . ModeOnHover ;
156+ InteractionMode farRayMode = rayInteractionDetector . ModeOnHover ;
143157 yield return RuntimeTestUtilities . WaitForUpdates ( ) ;
144- Assert . AreEqual ( farRayMode , rightHandController . GetComponentInChildren < MRTKRayInteractor > ( ) . GetComponent < InteractionDetector > ( ) . ModeOnDetection ) ;
158+ Assert . AreEqual ( farRayMode , rayInteractionDetector . ModeOnDetection ) ;
145159 ValidateInteractionModeActive ( rightHandController , farRayMode ) ;
146160
147161 // Now move the hand in range for the proximity detector
@@ -159,8 +173,10 @@ public IEnumerator ModeMediationTest()
159173 yield return rightHand . SetHandshape ( HandshapeTypes . HandshapeId . Grab ) ;
160174 yield return RuntimeTestUtilities . WaitForUpdates ( ) ;
161175
162- InteractionMode grabMode = rightHandController . GetComponentInChildren < GrabInteractor > ( ) . GetComponent < InteractionDetector > ( ) . ModeOnSelect ;
163- Assert . AreEqual ( grabMode , rightHandController . GetComponentInChildren < GrabInteractor > ( ) . GetComponent < InteractionDetector > ( ) . ModeOnDetection ) ;
176+ InteractionDetector grabInteractionDetector = rightHandController . GetComponentInChildren < GrabInteractor > ( ) . GetComponent < InteractionDetector > ( ) ;
177+
178+ InteractionMode grabMode = grabInteractionDetector . ModeOnSelect ;
179+ Assert . AreEqual ( grabMode , grabInteractionDetector . ModeOnDetection ) ;
164180 yield return RuntimeTestUtilities . WaitForUpdates ( ) ;
165181 ValidateInteractionModeActive ( rightHandController , grabMode ) ;
166182 Assert . IsTrue ( grabMode . Priority > nearMode . Priority ) ;
@@ -176,7 +192,7 @@ public IEnumerator ModeMediationTest()
176192
177193 // Moving the hand to a position where it's far ray is hovering over the cube
178194 yield return rightHand . MoveTo ( cube . transform . position + new Vector3 ( 0.02f , - 0.1f , - 0.8f ) ) ;
179- yield return RuntimeTestUtilities . WaitForUpdates ( frameCount : 120 ) ;
195+ yield return RuntimeTestUtilities . WaitForUpdates ( frameCount : 120 ) ;
180196
181197 ValidateInteractionModeActive ( rightHandController , farRayMode ) ;
182198 }
@@ -189,15 +205,14 @@ public IEnumerator ModeMediationTest()
189205 private void ValidateInteractionModeActive ( XRBaseController controller , InteractionMode currentMode )
190206 {
191207 // We construct the list of managed interactor types manually because we don't want to expose the internal controller mapping implementation to even internal use, since
192- // we don't want any other class to be able to modify those collections without going through the Mode Manager or it's in-editor inspector.
193- HashSet < System . Type > managedInteractorTypes = new HashSet < System . Type > ( InteractionModeManager . Instance . PrioritizedInteractionModes . SelectMany ( x => x . AssociatedTypes ) ) ;
194- HashSet < System . Type > activeInteractorTypes = InteractionModeManager . Instance . PrioritizedInteractionModes . Find ( x => x . ModeName == currentMode . Name ) . AssociatedTypes ;
208+ // we don't want any other class to be able to modify those collections without going through the Mode Manager or its in-editor inspector.
209+ HashSet < Type > managedInteractorTypes = new HashSet < System . Type > ( InteractionModeManager . Instance . PrioritizedInteractionModes . SelectMany ( x => x . AssociatedTypes ) ) ;
210+ HashSet < Type > activeInteractorTypes = InteractionModeManager . Instance . PrioritizedInteractionModes . Find ( x => x . ModeName == currentMode . Name ) . AssociatedTypes ;
195211
196212 // Ensure the prox detector has actually had the desired effect of enabling/disabling interactors.
197- foreach ( System . Type interactorType in managedInteractorTypes )
213+ foreach ( Type interactorType in managedInteractorTypes )
198214 {
199- XRBaseInteractor interactor = controller . GetComponentInChildren ( interactorType ) as XRBaseInputInteractor ;
200- if ( interactor != null )
215+ if ( controller . GetComponentInChildren ( interactorType ) is XRBaseInputInteractor interactor && interactor != null )
201216 {
202217 Assert . AreEqual ( activeInteractorTypes . Contains ( interactorType ) , interactor . enabled ) ;
203218 }
0 commit comments