@@ -1216,14 +1216,6 @@ public void Events_CanPreventEventsFromBeingProcessed()
12161216 Assert . That ( device . rightTrigger . ReadValue ( ) , Is . EqualTo ( 0.0 ) . Within ( 0.00001 ) ) ;
12171217 }
12181218
1219- class SuppressedActionEventData
1220- {
1221- public bool markNextEventHandled ;
1222- public int startedCount ;
1223- public int performedCount ;
1224- public int canceledCount ;
1225- }
1226-
12271219 [ Test ]
12281220 [ Category ( "Events" ) ]
12291221 public void EventHandledPolicy_ShouldReflectUserSetting ( )
@@ -1245,14 +1237,40 @@ public void EventHandledPolicy_ShouldReflectUserSetting()
12451237 Assert . That ( InputSystem . s_Manager . inputEventHandledPolicy , Is . EqualTo ( InputEventHandledPolicy . SuppressStateUpdates ) ) ;
12461238 }
12471239
1240+ class SuppressedActionEventData
1241+ {
1242+ public bool MarkNextEventHandled ;
1243+ public int StartedCount ;
1244+ public int PerformedCount ;
1245+ public int CanceledCount ;
1246+ }
1247+
1248+ // Note that each element in the expected value arrays correspond to accumulated count per test step.
1249+ [ TestCase ( InputEventHandledPolicy . SuppressStateUpdates , // policy
1250+ null , // interactions
1251+ new int [ ] { 0 , 0 , 1 , 1 , 2 } , // started
1252+ new int [ ] { 0 , 0 , 1 , 1 , 2 } , // performed
1253+ new int [ ] { 0 , 0 , 0 , 1 , 1 } ) ] // cancelled
1254+ [ TestCase ( InputEventHandledPolicy . SuppressActionUpdates ,
1255+ null ,
1256+ new int [ ] { 0 , 0 , 0 , 0 , 1 } ,
1257+ new int [ ] { 0 , 0 , 0 , 0 , 1 } ,
1258+ new int [ ] { 0 , 0 , 0 , 0 , 0 } ) ]
12481259 [ TestCase ( InputEventHandledPolicy . SuppressStateUpdates ,
1249- new int [ ] { 0 , 0 , 1 , 1 } , new int [ ] { 0 , 0 , 0 , 1 } ) ]
1260+ "press" ,
1261+ new int [ ] { 0 , 0 , 1 , 1 , 2 } ,
1262+ new int [ ] { 0 , 0 , 1 , 1 , 2 } ,
1263+ new int [ ] { 0 , 0 , 0 , 1 , 1 } ) ]
12501264 [ TestCase ( InputEventHandledPolicy . SuppressActionUpdates ,
1251- new int [ ] { 0 , 0 , 0 , 0 } , new int [ ] { 0 , 0 , 0 , 0 } ) ]
1265+ "press" ,
1266+ new int [ ] { 0 , 0 , 0 , 0 , 1 } ,
1267+ new int [ ] { 0 , 0 , 0 , 0 , 1 } ,
1268+ new int [ ] { 0 , 0 , 0 , 0 , 0 } ) ]
12521269 [ Category ( "Events" ) ]
1253- [ Description ( "ISXB-1524 Events suppressed has side-effects on actions when based on polling" ) ]
1254- public void Events_ShouldRespectHandledPolicyUponUpdate ( InputEventHandledPolicy policy ,
1255- int [ ] expectedProcessed , int [ ] expectedCancelled ) // EDIT
1270+ [ Description ( "ISXB-1524, ISXB-1396 Events suppressed has side-effects on actions" ) ]
1271+ public void Events_ShouldRespectHandledPolicyUponUpdateAndSuppressedPressTransition (
1272+ InputEventHandledPolicy policy , string interactions ,
1273+ int [ ] expectedStarted , int [ ] expectedPerformed , int [ ] expectedCancelled )
12561274 {
12571275 // Update setting to match desired scenario
12581276 InputSystem . s_Manager . inputEventHandledPolicy = policy ;
@@ -1264,42 +1282,91 @@ public void Events_ShouldRespectHandledPolicyUponUpdate(InputEventHandledPolicy
12641282 ( inputEvent , _ ) =>
12651283 {
12661284 // If we mark the event handled, the system should skip it and not
1267- // let it go to the device.
1268- inputEvent . handled = data . markNextEventHandled ;
1285+ // let it go to the device (SuppressStateUpdates) or let it propagate
1286+ // but not fire actions (SuppressActionUpdates).
1287+ inputEvent . handled = data . MarkNextEventHandled ;
12691288 } ;
12701289
12711290 var device = InputSystem . AddDevice < Gamepad > ( ) ;
1272- var action = new InputAction ( type : InputActionType . Button , binding : "<Gamepad>/buttonNorth" ) ;
1291+ var action = new InputAction ( type : InputActionType . Button ,
1292+ binding : "<Gamepad>/buttonNorth" ,
1293+ interactions : interactions ) ;
12731294 action . Enable ( ) ;
1274- action . started += _ => ++ data . startedCount ;
1275- action . performed += _ => ++ data . performedCount ;
1276- action . canceled += _ => ++ data . canceledCount ;
1295+ action . started += _ => ++ data . StartedCount ;
1296+ action . performed += _ => ++ data . PerformedCount ;
1297+ action . canceled += _ => ++ data . CanceledCount ;
12771298
12781299 // Ensure state is updated/initialized
12791300 InputSystem . QueueStateEvent ( device , new GamepadState ( ) { leftStick = new Vector2 ( 0.01f , 0.0f ) } ) ;
12801301 InputSystem . Update ( ) ;
1281- Assert . That ( data . performedCount , Is . EqualTo ( expectedProcessed [ 0 ] ) ) ;
1282- Assert . That ( data . canceledCount , Is . EqualTo ( expectedCancelled [ 0 ] ) ) ;
1283-
1284- // Press button north with event suppression active
1285- data . markNextEventHandled = true ;
1286- InputSystem . QueueStateEvent ( device , new GamepadState ( ) { leftStick = new Vector2 ( 0.00f , 0.01f ) } . WithButton ( GamepadButton . North ) ) ;
1302+ Assert . That ( data . StartedCount , Is . EqualTo ( expectedStarted [ 0 ] ) ) ;
1303+ Assert . That ( data . PerformedCount , Is . EqualTo ( expectedPerformed [ 0 ] ) ) ;
1304+ Assert . That ( data . CanceledCount , Is . EqualTo ( expectedCancelled [ 0 ] ) ) ;
1305+ var performedThisFrame = expectedPerformed [ 0 ] != 0 ;
1306+ Assert . That ( action . WasPerformedThisFrame , Is . EqualTo ( performedThisFrame ) ) ;
1307+ Assert . That ( action . WasPressedThisFrame , Is . EqualTo ( performedThisFrame ) ) ;
1308+ var releasedThisFrame = expectedCancelled [ 0 ] != 0 ;
1309+ Assert . That ( action . WasReleasedThisFrame , Is . EqualTo ( releasedThisFrame ) ) ;
1310+ // TODO Assert.That(Gamepad.current.buttonNorth.wasPressedThisFrame, Is.False); <-- TODO Needs separate handling, just suppress?
1311+
1312+ // Press button north and left stick with event suppression active
1313+ data . MarkNextEventHandled = true ;
1314+ InputSystem . QueueStateEvent ( device , new GamepadState ( ) { leftStick = new Vector2 ( 1.00f , 0.01f ) }
1315+ . WithButton ( GamepadButton . North ) ) ;
12871316 InputSystem . Update ( ) ;
1288- Assert . That ( data . performedCount , Is . EqualTo ( expectedProcessed [ 1 ] ) ) ;
1289- Assert . That ( data . canceledCount , Is . EqualTo ( expectedCancelled [ 1 ] ) ) ;
1290-
1291- // Simulate a periodic reading, this will trigger performed count
1292- data . markNextEventHandled = false ;
1293- InputSystem . QueueStateEvent ( device , new GamepadState ( ) { leftStick = new Vector2 ( 0.01f , 0.00f ) } . WithButton ( GamepadButton . North ) ) ;
1317+ Assert . That ( data . StartedCount , Is . EqualTo ( expectedStarted [ 1 ] ) ) ;
1318+ Assert . That ( data . PerformedCount , Is . EqualTo ( expectedPerformed [ 1 ] ) ) ;
1319+ Assert . That ( data . CanceledCount , Is . EqualTo ( expectedCancelled [ 1 ] ) ) ;
1320+ performedThisFrame = expectedPerformed [ 1 ] - expectedPerformed [ 0 ] > 0 ;
1321+ Assert . That ( action . WasPerformedThisFrame , Is . EqualTo ( performedThisFrame ) ) ;
1322+ Assert . That ( action . WasPressedThisFrame , Is . EqualTo ( performedThisFrame ) ) ;
1323+ releasedThisFrame = expectedCancelled [ 1 ] - expectedCancelled [ 0 ] > 0 ;
1324+ Assert . That ( action . WasReleasedThisFrame , Is . EqualTo ( releasedThisFrame ) ) ;
1325+ // TODO Assert.That(Gamepad.current.buttonNorth.wasPressedThisFrame, Is.EqualTo(expectedPerformed[1] - expectedPerformed[0] > 0));
1326+
1327+ // Simulate a periodic reading (e.g. driven by noise or irrelevant control), this will trigger performed count.
1328+ // Note that for SuppressStateUpdates (default), this would trigger a state change since North button
1329+ // transitions from 0 to 1 which is considered a press.
1330+ data . MarkNextEventHandled = false ;
1331+ InputSystem . QueueStateEvent ( device , new GamepadState ( ) { leftStick = new Vector2 ( 0.99f , 0.00f ) }
1332+ . WithButton ( GamepadButton . North ) ) ;
12941333 InputSystem . Update ( ) ;
1295- Assert . That ( data . performedCount , Is . EqualTo ( expectedProcessed [ 2 ] ) ) ; // Firing without actual change
1296- Assert . That ( data . canceledCount , Is . EqualTo ( expectedCancelled [ 2 ] ) ) ;
1297-
1298- // Release button north
1334+ Assert . That ( data . StartedCount , Is . EqualTo ( expectedStarted [ 2 ] ) ) ;
1335+ Assert . That ( data . PerformedCount , Is . EqualTo ( expectedPerformed [ 2 ] ) ) ; // Firing without actual change
1336+ Assert . That ( data . CanceledCount , Is . EqualTo ( expectedCancelled [ 2 ] ) ) ;
1337+ performedThisFrame = expectedPerformed [ 2 ] - expectedPerformed [ 1 ] > 0 ;
1338+ Assert . That ( action . WasPerformedThisFrame , Is . EqualTo ( performedThisFrame ) ) ;
1339+ Assert . That ( action . WasPressedThisFrame , Is . EqualTo ( performedThisFrame ) ) ;
1340+ releasedThisFrame = expectedCancelled [ 2 ] - expectedCancelled [ 1 ] > 0 ;
1341+ Assert . That ( action . WasReleasedThisFrame , Is . EqualTo ( releasedThisFrame ) ) ;
1342+ // TODO Assert.That(Gamepad.current.buttonNorth.wasPressedThisFrame, Is.EqualTo(expectedPerformed[2] - expectedPerformed[1] > 0));
1343+
1344+ // Release button north and stick while no longer being suppressed. This may result in a release if
1345+ // previous event was completely ignored without updating interaction state.
12991346 InputSystem . QueueStateEvent ( device , new GamepadState ( ) { leftStick = new Vector2 ( 0.00f , 0.01f ) } ) ;
13001347 InputSystem . Update ( ) ;
1301- Assert . That ( data . performedCount , Is . EqualTo ( expectedProcessed [ 3 ] ) ) ;
1302- Assert . That ( data . canceledCount , Is . EqualTo ( expectedCancelled [ 3 ] ) ) ;
1348+ Assert . That ( data . StartedCount , Is . EqualTo ( expectedStarted [ 3 ] ) ) ;
1349+ Assert . That ( data . PerformedCount , Is . EqualTo ( expectedPerformed [ 3 ] ) ) ;
1350+ Assert . That ( data . CanceledCount , Is . EqualTo ( expectedCancelled [ 3 ] ) ) ;
1351+ performedThisFrame = expectedPerformed [ 3 ] - expectedPerformed [ 2 ] > 0 ;
1352+ Assert . That ( action . WasPerformedThisFrame , Is . EqualTo ( performedThisFrame ) ) ;
1353+ Assert . That ( action . WasPressedThisFrame , Is . EqualTo ( performedThisFrame ) ) ;
1354+ releasedThisFrame = expectedCancelled [ 3 ] - expectedCancelled [ 2 ] > 0 ;
1355+ Assert . That ( action . WasReleasedThisFrame , Is . EqualTo ( releasedThisFrame ) ) ;
1356+ // TODO Assert.That(Gamepad.current.buttonNorth.wasPressedThisFrame, Is.EqualTo(expectedPerformed[3] - expectedPerformed[2] > 0));
1357+
1358+ // Press button north and stick again while not being suppressed.
1359+ InputSystem . QueueStateEvent ( device , new GamepadState ( ) { leftStick = new Vector2 ( 0.99f , 0.00f ) }
1360+ . WithButton ( GamepadButton . North ) ) ;
1361+ InputSystem . Update ( ) ;
1362+ Assert . That ( data . StartedCount , Is . EqualTo ( expectedStarted [ 4 ] ) ) ;
1363+ Assert . That ( data . PerformedCount , Is . EqualTo ( expectedPerformed [ 4 ] ) ) ;
1364+ Assert . That ( data . CanceledCount , Is . EqualTo ( expectedCancelled [ 4 ] ) ) ;
1365+ performedThisFrame = expectedPerformed [ 4 ] - expectedPerformed [ 3 ] > 0 ;
1366+ Assert . That ( action . WasPerformedThisFrame , Is . EqualTo ( performedThisFrame ) ) ;
1367+ Assert . That ( action . WasPressedThisFrame , Is . EqualTo ( performedThisFrame ) ) ;
1368+ releasedThisFrame = expectedCancelled [ 4 ] - expectedCancelled [ 3 ] > 0 ;
1369+ Assert . That ( action . WasReleasedThisFrame , Is . EqualTo ( releasedThisFrame ) ) ;
13031370 }
13041371
13051372 [ StructLayout ( LayoutKind . Explicit , Size = 2 ) ]
0 commit comments