@@ -1529,6 +1529,65 @@ public IEnumerator UI_CanDriveUIFromMultiplePointers(UIPointerBehavior pointerBe
1529
1529
. Matches ( ( UICallbackReceiver . Event e ) => e . pointerData . position == secondPosition ) ) ;
1530
1530
}
1531
1531
1532
+ [ UnityTest ]
1533
+ [ Category ( "UI" ) ]
1534
+ [ Description ( "Tests that disabling the UI module during a Button click event works correctly with touch pointers." +
1535
+ "ISXB-687" ) ]
1536
+ public IEnumerator UI_DisablingEventSystemOnClickEventWorksWithTouchPointersWorks ( )
1537
+ {
1538
+ var touch = InputSystem . AddDevice < Touchscreen > ( ) ;
1539
+ var scene = CreateTestUI ( ) ;
1540
+
1541
+ var actions = ScriptableObject . CreateInstance < InputActionAsset > ( ) ;
1542
+ var uiActions = actions . AddActionMap ( "UI" ) ;
1543
+ var pointAction = uiActions . AddAction ( "point" , type : InputActionType . PassThrough ) ;
1544
+ var clickAction = uiActions . AddAction ( "click" , type : InputActionType . PassThrough ) ;
1545
+
1546
+ pointAction . AddBinding ( "<Touchscreen>/touch*/position" ) ;
1547
+ clickAction . AddBinding ( "<Touchscreen>/touch*/press" ) ;
1548
+
1549
+ pointAction . Enable ( ) ;
1550
+ clickAction . Enable ( ) ;
1551
+
1552
+ scene . uiModule . point = InputActionReference . Create ( pointAction ) ;
1553
+ scene . uiModule . pointerBehavior = UIPointerBehavior . SingleMouseOrPenButMultiTouchAndTrack ;
1554
+ scene . uiModule . leftClick = InputActionReference . Create ( clickAction ) ;
1555
+
1556
+ // Turn left object into a button.
1557
+ var button = scene . leftGameObject . AddComponent < MyButton > ( ) ;
1558
+ var clicked = false ;
1559
+
1560
+ // Add a listener to the button to disable the UI module when clicked.
1561
+ // This calls InputSystemUIInputModule.OnDisable() which will reset the pointer data during
1562
+ // InputSystemUIInputModule.Process() and ProcessPointer(). It will allow us to test that removing
1563
+ // a pointer once the UI module is disabled (all pointers are removed) works correctly.
1564
+ button . onClick . AddListener ( ( ) =>
1565
+ {
1566
+ clicked = true ;
1567
+ scene . uiModule . enabled = false ; // Disable the UI module to test pointer reset.
1568
+ } ) ;
1569
+
1570
+ yield return null ;
1571
+
1572
+ var firstPosition = scene . From640x480ToScreen ( 100 , 100 ) ;
1573
+
1574
+ // This will allocate a pointer for the touch and set the first touch position and press
1575
+ BeginTouch ( 1 , firstPosition , screen : touch ) ;
1576
+ yield return null ;
1577
+
1578
+ Assert . That ( clicked , Is . False , "Button was clicked when it should not have been yet." ) ;
1579
+ Assert . That ( scene . uiModule . m_PointerStates . length , Is . EqualTo ( 1 ) ,
1580
+ "A pointer states was not allocated for the touch pointer." ) ;
1581
+
1582
+ // Release the touch to make sure we have a Click event that calls the button listener.
1583
+ EndTouch ( 1 , firstPosition , screen : touch ) ;
1584
+ yield return null ;
1585
+
1586
+ Assert . That ( clicked , Is . True , "Button was not clicked when it should have been." ) ;
1587
+ Assert . That ( scene . uiModule . m_PointerStates . length , Is . EqualTo ( 0 ) ,
1588
+ "Pointer states were not cleared when the UI module was disabled after a click event." ) ;
1589
+ }
1590
+
1532
1591
[ UnityTest ]
1533
1592
[ Category ( "UI" ) ]
1534
1593
public IEnumerator UI_CanDriveUIFromMultipleTouches ( )
0 commit comments