@@ -127,7 +127,7 @@ private T CreateTouchable<T>(Vector3 cubeDimensions) where T : BaseNearInteracti
127127 }
128128
129129
130- private TouchEventCatcher CreateEventCatcher ( BaseNearInteractionTouchable touchable )
130+ private TouchEventCatcher CreateTouchEventCatcher ( BaseNearInteractionTouchable touchable )
131131 {
132132 var catcher = TouchEventCatcher . Create ( touchable . gameObject ) ;
133133
@@ -143,6 +143,80 @@ private TouchEventCatcher CreateEventCatcher(BaseNearInteractionTouchable toucha
143143 return catcher ;
144144 }
145145
146+
147+ private PointerEventCatcher CreatePointerEventCatcher ( BaseNearInteractionTouchable touchable )
148+ {
149+ var catcher = PointerEventCatcher . Create ( touchable . gameObject ) ;
150+ catcher . OnPointerDownEvent . AddListener ( ( ) =>
151+ {
152+ touchable . GetComponent < Renderer > ( ) . material = pokeMaterial ;
153+ } ) ;
154+ catcher . OnPointerUpEvent . AddListener ( ( ) =>
155+ {
156+ touchable . GetComponent < Renderer > ( ) . material = idleMaterial ;
157+ } ) ;
158+
159+ return catcher ;
160+ }
161+
162+ /// <summary>
163+ /// Test that NearInteractionTouchable can raise pointer events
164+ /// </summary>
165+ /// <returns></returns>
166+ [ UnityTest ]
167+ public IEnumerator NearInteractionTouchablePointerEvents ( )
168+ {
169+ var touchable = CreateTouchable < NearInteractionTouchable > ( objectScale ) ;
170+ touchable . SetLocalForward ( touchNormal ) ;
171+ touchable . SetBounds ( new Vector2 ( 0.5f , 0.5f ) ) ;
172+ touchable . EventsToReceive = TouchableEventType . Pointer ;
173+
174+ yield return new WaitForFixedUpdate ( ) ;
175+ yield return null ;
176+
177+ yield return PlayModeTestUtilities . ShowHand ( Handedness . Right , inputSim ) ;
178+
179+ using ( var catcher = CreatePointerEventCatcher ( touchable ) )
180+ {
181+ // Touch started and completed when entering and exiting
182+ yield return PlayModeTestUtilities . MoveHandFromTo ( initialHandPosition , objectPosition , numSteps , ArticulatedHandPose . GestureId . Open , Handedness . Right , inputSim ) ;
183+ Assert . AreEqual ( 1 , catcher . EventsStarted ) ;
184+ Assert . AreEqual ( 0 , catcher . EventsCompleted ) ;
185+ yield return PlayModeTestUtilities . MoveHandFromTo ( objectPosition , rightPosition , numSteps , ArticulatedHandPose . GestureId . Pinch , Handedness . Right , inputSim ) ;
186+ Assert . AreEqual ( 1 , catcher . EventsStarted ) ;
187+ Assert . AreEqual ( 1 , catcher . EventsCompleted ) ;
188+ Assert . Greater ( catcher . DragEventCount , 0 ) ;
189+
190+ // Touch started and completed when entering and exiting behind the plane
191+ yield return PlayModeTestUtilities . MoveHandFromTo ( initialHandPosition , objectPosition , numSteps , ArticulatedHandPose . GestureId . Open , Handedness . Right , inputSim ) ;
192+ Assert . AreEqual ( 2 , catcher . EventsStarted ) ;
193+ Assert . AreEqual ( 1 , catcher . EventsCompleted ) ;
194+ yield return PlayModeTestUtilities . MoveHandFromTo ( objectPosition , backPosition , numSteps , ArticulatedHandPose . GestureId . Pinch , Handedness . Right , inputSim ) ;
195+ Assert . AreEqual ( 2 , catcher . EventsStarted ) ;
196+ Assert . AreEqual ( 2 , catcher . EventsCompleted ) ;
197+ Assert . Greater ( catcher . DragEventCount , 1 ) ;
198+ int dragEventCount = catcher . DragEventCount ;
199+
200+ // No touch when moving at behind the plane
201+ yield return PlayModeTestUtilities . MoveHandFromTo ( backPosition , rightPosition , numSteps , ArticulatedHandPose . GestureId . Pinch , Handedness . Right , inputSim ) ;
202+ Assert . AreEqual ( 2 , catcher . EventsStarted ) ;
203+ Assert . AreEqual ( 2 , catcher . EventsCompleted ) ;
204+ Assert . AreEqual ( dragEventCount , catcher . DragEventCount , "No drag events should fire when poke pointer moving behind plane" ) ;
205+
206+
207+ // No touch when moving outside the bounds
208+ yield return PlayModeTestUtilities . MoveHandFromTo ( initialHandPosition + outOfBoundsOffset , objectPosition + outOfBoundsOffset , numSteps , ArticulatedHandPose . GestureId . Open , Handedness . Right , inputSim ) ;
209+ yield return PlayModeTestUtilities . MoveHandFromTo ( objectPosition + outOfBoundsOffset , rightPosition , numSteps , ArticulatedHandPose . GestureId . Open , Handedness . Right , inputSim ) ;
210+ Assert . AreEqual ( 2 , catcher . EventsStarted ) ;
211+ Assert . AreEqual ( 2 , catcher . EventsCompleted ) ;
212+ Assert . AreEqual ( dragEventCount , catcher . DragEventCount , "No drag events should fire when poke pointer moving outside bounds" ) ;
213+ }
214+
215+ yield return PlayModeTestUtilities . HideHand ( Handedness . Right , inputSim ) ;
216+
217+ UnityEngine . Object . Destroy ( touchable . gameObject ) ;
218+ }
219+
146220 /// <summary>
147221 /// Test creates an object with NearInteractionTouchable
148222 /// </summary>
@@ -158,7 +232,7 @@ public IEnumerator NearInteractionTouchableVariant()
158232
159233 yield return PlayModeTestUtilities . ShowHand ( Handedness . Right , inputSim ) ;
160234
161- using ( var catcher = CreateEventCatcher ( touchable ) )
235+ using ( var catcher = CreateTouchEventCatcher ( touchable ) )
162236 {
163237 // Touch started and completed when entering and exiting
164238 yield return PlayModeTestUtilities . MoveHandFromTo ( initialHandPosition , objectPosition , numSteps , ArticulatedHandPose . GestureId . Open , Handedness . Right , inputSim ) ;
@@ -206,7 +280,7 @@ public IEnumerator NearInteractionTouchableVolumeVariant()
206280
207281 yield return PlayModeTestUtilities . ShowHand ( Handedness . Right , inputSim ) ;
208282
209- using ( var catcher = CreateEventCatcher ( touchable ) )
283+ using ( var catcher = CreateTouchEventCatcher ( touchable ) )
210284 {
211285 // Touch started when entering collider
212286 yield return PlayModeTestUtilities . MoveHandFromTo ( initialHandPosition , objectPosition , numSteps , ArticulatedHandPose . GestureId . Open , Handedness . Right , inputSim ) ;
@@ -366,7 +440,7 @@ public IEnumerator NearInteractionTouchableOverlapQuerySaturation()
366440 touchables [ i ] . SetBounds ( new Vector2 ( 0.5f , 0.5f ) ) ;
367441 touchables [ i ] . transform . position = objectPosition + r * radiusStart ;
368442
369- catchers [ i ] = CreateEventCatcher ( touchables [ i ] ) ;
443+ catchers [ i ] = CreateTouchEventCatcher ( touchables [ i ] ) ;
370444 }
371445
372446 yield return new WaitForFixedUpdate ( ) ;
@@ -492,10 +566,10 @@ public IEnumerator NearInteractionTouchableDistance()
492566 var touchableRect = CreateTouchable < NearInteractionTouchable > ( 0.15f ) ;
493567 touchableRect . SetLocalForward ( touchNormal ) ;
494568 touchableRect . SetBounds ( new Vector2 ( 0.5f , 0.5f ) ) ;
495- var catcherRect = CreateEventCatcher ( touchableRect ) ;
569+ var catcherRect = CreateTouchEventCatcher ( touchableRect ) ;
496570
497571 var touchableVolume = CreateTouchable < NearInteractionTouchableVolume > ( 0.15f ) ;
498- var catcherVolume = CreateEventCatcher ( touchableVolume ) ;
572+ var catcherVolume = CreateTouchEventCatcher ( touchableVolume ) ;
499573
500574 var canvas = UnityUiUtilities . CreateCanvas ( 0.002f ) ;
501575 var touchableUI = canvas . GetComponent < NearInteractionTouchableUnityUI > ( ) ;
@@ -635,7 +709,7 @@ public IEnumerator NearInteractionTouchableSetTouchableCollider()
635709 BoxCollider newBoxCollider = cube2 . GetComponent < BoxCollider > ( ) ;
636710 newBoxCollider . size = new Vector3 ( 4 , 2 , 1.2f ) ;
637711
638- using ( var catcher = CreateEventCatcher ( nearIT ) )
712+ using ( var catcher = CreateTouchEventCatcher ( nearIT ) )
639713 {
640714 // Touch started and completed when entering and exiting the collider
641715 yield return rightHand . Move ( new Vector3 ( 0 , 0 , 0.4f ) ) ;
0 commit comments