@@ -126,7 +126,7 @@ private T CreateTouchable<T>(Vector3 cubeDimensions) where T : BaseNearInteracti
126126 }
127127
128128
129- private TouchEventCatcher CreateEventCatcher ( BaseNearInteractionTouchable touchable )
129+ private TouchEventCatcher CreateTouchEventCatcher ( BaseNearInteractionTouchable touchable )
130130 {
131131 var catcher = TouchEventCatcher . Create ( touchable . gameObject ) ;
132132
@@ -142,6 +142,80 @@ private TouchEventCatcher CreateEventCatcher(BaseNearInteractionTouchable toucha
142142 return catcher ;
143143 }
144144
145+
146+ private PointerEventCatcher CreatePointerEventCatcher ( BaseNearInteractionTouchable touchable )
147+ {
148+ var catcher = PointerEventCatcher . Create ( touchable . gameObject ) ;
149+ catcher . OnPointerDownEvent . AddListener ( ( ) =>
150+ {
151+ touchable . GetComponent < Renderer > ( ) . material = pokeMaterial ;
152+ } ) ;
153+ catcher . OnPointerUpEvent . AddListener ( ( ) =>
154+ {
155+ touchable . GetComponent < Renderer > ( ) . material = idleMaterial ;
156+ } ) ;
157+
158+ return catcher ;
159+ }
160+
161+ /// <summary>
162+ /// Test that NearInteractionTouchable can raise pointer events
163+ /// </summary>
164+ /// <returns></returns>
165+ [ UnityTest ]
166+ public IEnumerator NearInteractionTouchablePointerEvents ( )
167+ {
168+ var touchable = CreateTouchable < NearInteractionTouchable > ( objectScale ) ;
169+ touchable . SetLocalForward ( touchNormal ) ;
170+ touchable . SetBounds ( new Vector2 ( 0.5f , 0.5f ) ) ;
171+ touchable . EventsToReceive = TouchableEventType . Pointer ;
172+
173+ yield return new WaitForFixedUpdate ( ) ;
174+ yield return null ;
175+
176+ yield return PlayModeTestUtilities . ShowHand ( Handedness . Right , inputSim ) ;
177+
178+ using ( var catcher = CreatePointerEventCatcher ( touchable ) )
179+ {
180+ // Touch started and completed when entering and exiting
181+ yield return PlayModeTestUtilities . MoveHandFromTo ( initialHandPosition , objectPosition , numSteps , ArticulatedHandPose . GestureId . Open , Handedness . Right , inputSim ) ;
182+ Assert . AreEqual ( 1 , catcher . EventsStarted ) ;
183+ Assert . AreEqual ( 0 , catcher . EventsCompleted ) ;
184+ yield return PlayModeTestUtilities . MoveHandFromTo ( objectPosition , rightPosition , numSteps , ArticulatedHandPose . GestureId . Pinch , Handedness . Right , inputSim ) ;
185+ Assert . AreEqual ( 1 , catcher . EventsStarted ) ;
186+ Assert . AreEqual ( 1 , catcher . EventsCompleted ) ;
187+ Assert . Greater ( catcher . DragEventCount , 0 ) ;
188+
189+ // Touch started and completed when entering and exiting behind the plane
190+ yield return PlayModeTestUtilities . MoveHandFromTo ( initialHandPosition , objectPosition , numSteps , ArticulatedHandPose . GestureId . Open , Handedness . Right , inputSim ) ;
191+ Assert . AreEqual ( 2 , catcher . EventsStarted ) ;
192+ Assert . AreEqual ( 1 , catcher . EventsCompleted ) ;
193+ yield return PlayModeTestUtilities . MoveHandFromTo ( objectPosition , backPosition , numSteps , ArticulatedHandPose . GestureId . Pinch , Handedness . Right , inputSim ) ;
194+ Assert . AreEqual ( 2 , catcher . EventsStarted ) ;
195+ Assert . AreEqual ( 2 , catcher . EventsCompleted ) ;
196+ Assert . Greater ( catcher . DragEventCount , 1 ) ;
197+ int dragEventCount = catcher . DragEventCount ;
198+
199+ // No touch when moving at behind the plane
200+ yield return PlayModeTestUtilities . MoveHandFromTo ( backPosition , rightPosition , numSteps , ArticulatedHandPose . GestureId . Pinch , Handedness . Right , inputSim ) ;
201+ Assert . AreEqual ( 2 , catcher . EventsStarted ) ;
202+ Assert . AreEqual ( 2 , catcher . EventsCompleted ) ;
203+ Assert . AreEqual ( dragEventCount , catcher . DragEventCount , "No drag events should fire when poke pointer moving behind plane" ) ;
204+
205+
206+ // No touch when moving outside the bounds
207+ yield return PlayModeTestUtilities . MoveHandFromTo ( initialHandPosition + outOfBoundsOffset , objectPosition + outOfBoundsOffset , numSteps , ArticulatedHandPose . GestureId . Open , Handedness . Right , inputSim ) ;
208+ yield return PlayModeTestUtilities . MoveHandFromTo ( objectPosition + outOfBoundsOffset , rightPosition , numSteps , ArticulatedHandPose . GestureId . Open , Handedness . Right , inputSim ) ;
209+ Assert . AreEqual ( 2 , catcher . EventsStarted ) ;
210+ Assert . AreEqual ( 2 , catcher . EventsCompleted ) ;
211+ Assert . AreEqual ( dragEventCount , catcher . DragEventCount , "No drag events should fire when poke pointer moving outside bounds" ) ;
212+ }
213+
214+ yield return PlayModeTestUtilities . HideHand ( Handedness . Right , inputSim ) ;
215+
216+ UnityEngine . Object . Destroy ( touchable . gameObject ) ;
217+ }
218+
145219 /// <summary>
146220 /// Test creates an object with NearInteractionTouchable
147221 /// </summary>
@@ -157,7 +231,7 @@ public IEnumerator NearInteractionTouchableVariant()
157231
158232 yield return PlayModeTestUtilities . ShowHand ( Handedness . Right , inputSim ) ;
159233
160- using ( var catcher = CreateEventCatcher ( touchable ) )
234+ using ( var catcher = CreateTouchEventCatcher ( touchable ) )
161235 {
162236 // Touch started and completed when entering and exiting
163237 yield return PlayModeTestUtilities . MoveHand ( initialHandPosition , objectPosition , ArticulatedHandPose . GestureId . Open , Handedness . Right , inputSim ) ;
@@ -205,7 +279,7 @@ public IEnumerator NearInteractionTouchableVolumeVariant()
205279
206280 yield return PlayModeTestUtilities . ShowHand ( Handedness . Right , inputSim ) ;
207281
208- using ( var catcher = CreateEventCatcher ( touchable ) )
282+ using ( var catcher = CreateTouchEventCatcher ( touchable ) )
209283 {
210284 // Touch started when entering collider
211285 yield return PlayModeTestUtilities . MoveHand ( initialHandPosition , objectPosition , ArticulatedHandPose . GestureId . Open , Handedness . Right , inputSim ) ;
@@ -365,7 +439,7 @@ public IEnumerator NearInteractionTouchableOverlapQuerySaturation()
365439 touchables [ i ] . SetBounds ( new Vector2 ( 0.5f , 0.5f ) ) ;
366440 touchables [ i ] . transform . position = objectPosition + r * radiusStart ;
367441
368- catchers [ i ] = CreateEventCatcher ( touchables [ i ] ) ;
442+ catchers [ i ] = CreateTouchEventCatcher ( touchables [ i ] ) ;
369443 }
370444
371445 yield return new WaitForFixedUpdate ( ) ;
@@ -491,10 +565,10 @@ public IEnumerator NearInteractionTouchableDistance()
491565 var touchableRect = CreateTouchable < NearInteractionTouchable > ( 0.15f ) ;
492566 touchableRect . SetLocalForward ( touchNormal ) ;
493567 touchableRect . SetBounds ( new Vector2 ( 0.5f , 0.5f ) ) ;
494- var catcherRect = CreateEventCatcher ( touchableRect ) ;
568+ var catcherRect = CreateTouchEventCatcher ( touchableRect ) ;
495569
496570 var touchableVolume = CreateTouchable < NearInteractionTouchableVolume > ( 0.15f ) ;
497- var catcherVolume = CreateEventCatcher ( touchableVolume ) ;
571+ var catcherVolume = CreateTouchEventCatcher ( touchableVolume ) ;
498572
499573 var canvas = UnityUiUtilities . CreateCanvas ( 0.002f ) ;
500574 var touchableUI = canvas . GetComponent < NearInteractionTouchableUnityUI > ( ) ;
@@ -634,7 +708,7 @@ public IEnumerator NearInteractionTouchableSetTouchableCollider()
634708 BoxCollider newBoxCollider = cube2 . GetComponent < BoxCollider > ( ) ;
635709 newBoxCollider . size = new Vector3 ( 4 , 2 , 1.2f ) ;
636710
637- using ( var catcher = CreateEventCatcher ( nearIT ) )
711+ using ( var catcher = CreateTouchEventCatcher ( nearIT ) )
638712 {
639713 // Touch started and completed when entering and exiting the collider
640714 yield return rightHand . Move ( new Vector3 ( 0 , 0 , 0.4f ) ) ;
0 commit comments