@@ -1460,33 +1460,73 @@ public IEnumerator UI_CanDriveUIFromMultiplePointers(UIPointerBehavior pointerBe
1460
1460
scene . leftChildReceiver . events . Clear ( ) ;
1461
1461
scene . rightChildReceiver . events . Clear ( ) ;
1462
1462
1463
- // Test if creating Pointer events from different devices at the same time results in only one event
1464
- BeginTouch ( 0 , firstPosition , screen : touch1 , queueEventOnly : true ) ;
1463
+ // End previous touches that started so that we can do a cleanup from the last test.
1464
+ EndTouch ( 1 , secondPosition , screen : touch1 ) ;
1465
+ yield return null ;
1466
+ EndTouch ( 1 , firstPosition , screen : touch2 ) ;
1467
+ yield return null ;
1468
+ // Set a mouse position without any clicks to "emulate" a real movement before a button press.
1469
+ Set ( mouse1 . position , secondPosition + new Vector2 ( - 10 , 0 ) ) ;
1470
+ yield return null ;
1471
+
1472
+ scene . leftChildReceiver . events . Clear ( ) ;
1473
+ scene . rightChildReceiver . events . Clear ( ) ;
1474
+
1475
+ // Test a press and release from both a Mouse and Touchscreen at the same time
1476
+ // This is to simulate some platforms that always send Mouse/Pen and Touches (e.g. Android).
1477
+ // Also, this mostly assets the expected behavior for the options SingleMouseOrPenButMultiTouchAndTrack.
1478
+ var touchId = 2 ;
1479
+ BeginTouch ( touchId , secondPosition , screen : touch1 , queueEventOnly : true ) ;
1480
+ Set ( mouse1 . position , secondPosition , queueEventOnly : true ) ;
1465
1481
Press ( mouse1 . leftButton ) ;
1482
+
1466
1483
yield return null ;
1467
- EndTouch ( 0 , firstPosition , screen : touch1 , queueEventOnly : true ) ;
1484
+
1485
+ EndTouch ( touchId , secondPosition , screen : touch1 , queueEventOnly : true ) ;
1468
1486
Release ( mouse1 . leftButton ) ;
1469
1487
yield return null ;
1470
1488
1489
+ Func < UICallbackReceiver . Event , bool > eventDeviceCondition = null ;
1490
+ var expectedCount = 0 ;
1471
1491
switch ( pointerBehavior )
1472
1492
{
1493
+ case UIPointerBehavior . SingleMouseOrPenButMultiTouchAndTrack :
1494
+ // Expects only mouse events for PointerClick, PointerDown, and PointerUp
1495
+ eventDeviceCondition = ( e ) => e . pointerData . device == mouse1 ;
1496
+ expectedCount = 1 ;
1497
+ // Make sure that the touch does not generate a UI events.
1498
+ Assert . That ( scene . rightChildReceiver . events , Has . None . Matches ( ( UICallbackReceiver . Event e ) =>
1499
+ e . pointerData != null && e . pointerData . device == touch1 ) ) ;
1500
+ break ;
1501
+
1473
1502
case UIPointerBehavior . SingleUnifiedPointer :
1474
- //// Getting "Drop" event even if using only one type of input device for Press/Release.
1475
- //// E.g. the following test would also produce only a Drop event:
1476
- //// Press(mouse1.leftButton);
1477
- //// yield return null;
1478
- //// Release(mouse1.leftButton);
1479
- //// yield return null;
1503
+ // Expects only single UI events with touch source since they are the first events in the queue
1504
+ eventDeviceCondition = ( e ) => e . pointerData . device == touch1 ;
1505
+ expectedCount = 1 ;
1480
1506
break ;
1481
- case UIPointerBehavior . SingleMouseOrPenButMultiTouchAndTrack :
1507
+
1482
1508
case UIPointerBehavior . AllPointersAsIs :
1483
- // Single pointer click on the left object
1484
- Assert . That ( scene . leftChildReceiver . events ,
1485
- Has . Exactly ( 1 ) . With . Property ( "type" ) . EqualTo ( EventType . PointerClick ) . And
1486
- . Matches ( ( UICallbackReceiver . Event e ) => e . pointerData . device == mouse1 ) . And
1487
- . Matches ( ( UICallbackReceiver . Event e ) => e . pointerData . position == firstPosition ) ) ;
1509
+ // Expects both pointer devices to generate PointerClick, PointerDown, and PointerUp events
1510
+ eventDeviceCondition = ( e ) => e . pointerData . device == mouse1 || e . pointerData . device == touch1 ;
1511
+ expectedCount = 2 ;
1488
1512
break ;
1513
+
1514
+ default :
1515
+ throw new ArgumentOutOfRangeException ( nameof ( pointerBehavior ) , pointerBehavior , null ) ;
1489
1516
}
1517
+
1518
+ Assert . That ( scene . rightChildReceiver . events ,
1519
+ Has . Exactly ( expectedCount ) . With . Property ( "type" ) . EqualTo ( EventType . PointerClick ) . And
1520
+ . Matches ( ( UICallbackReceiver . Event e ) => eventDeviceCondition ( e ) ) . And
1521
+ . Matches ( ( UICallbackReceiver . Event e ) => e . pointerData . position == secondPosition ) ) ;
1522
+ Assert . That ( scene . rightChildReceiver . events ,
1523
+ Has . Exactly ( expectedCount ) . With . Property ( "type" ) . EqualTo ( EventType . PointerDown ) . And
1524
+ . Matches ( ( UICallbackReceiver . Event e ) => eventDeviceCondition ( e ) ) . And
1525
+ . Matches ( ( UICallbackReceiver . Event e ) => e . pointerData . position == secondPosition ) ) ;
1526
+ Assert . That ( scene . rightChildReceiver . events ,
1527
+ Has . Exactly ( expectedCount ) . With . Property ( "type" ) . EqualTo ( EventType . PointerUp ) . And
1528
+ . Matches ( ( UICallbackReceiver . Event e ) => eventDeviceCondition ( e ) ) . And
1529
+ . Matches ( ( UICallbackReceiver . Event e ) => e . pointerData . position == secondPosition ) ) ;
1490
1530
}
1491
1531
1492
1532
[ UnityTest ]
0 commit comments