@@ -3723,6 +3723,36 @@ public void Actions_CanLookUpActionInAssetByName()
37233723 } , Is . Not . AllocatingGCMemory ( ) ) ;
37243724 }
37253725
3726+ [ Test ]
3727+ [ Category ( "Actions" ) ]
3728+ public void Actions_CanRemoveActionFromMap ( )
3729+ {
3730+ var asset = ScriptableObject . CreateInstance < InputActionAsset > ( ) ;
3731+
3732+ var map = new InputActionMap ( "test" ) ;
3733+ asset . AddActionMap ( map ) ;
3734+
3735+ var action1 = map . AddAction ( "action1" , binding : "<Gamepad>/buttonSouth" ) ;
3736+ var action2 = map . AddAction ( "action2" , binding : "<Gamepad>/buttonNorth" ) ;
3737+ var action3 = map . AddAction ( "action3" , binding : "<Gamepad>/buttonWest" ) ;
3738+
3739+ asset . RemoveAction ( "action2" ) ;
3740+
3741+ Assert . That ( action2 . actionMap , Is . Null ) ;
3742+ Assert . That ( asset . FindAction ( "action2" ) , Is . Null ) ;
3743+ Assert . That ( map . actions , Has . Count . EqualTo ( 2 ) ) ;
3744+ Assert . That ( map . actions , Has . Exactly ( 1 ) . SameAs ( action1 ) ) ;
3745+ Assert . That ( map . actions , Has . Exactly ( 1 ) . SameAs ( action3 ) ) ;
3746+ Assert . That ( action1 . bindings , Is . EquivalentTo ( new [ ] { new InputBinding ( "<Gamepad>/buttonSouth" , action : "action1" ) } ) ) ;
3747+ Assert . That ( action2 . bindings , Is . EquivalentTo ( new [ ] { new InputBinding ( "<Gamepad>/buttonNorth" , action : "action2" ) } ) ) ;
3748+ Assert . That ( action3 . bindings , Is . EquivalentTo ( new [ ] { new InputBinding ( "<Gamepad>/buttonWest" , action : "action3" ) } ) ) ;
3749+ Assert . That ( map . bindings , Is . EquivalentTo ( new [ ]
3750+ {
3751+ new InputBinding ( "<Gamepad>/buttonSouth" , action : "action1" ) ,
3752+ new InputBinding ( "<Gamepad>/buttonWest" , action : "action3" )
3753+ } ) ) ;
3754+ }
3755+
37263756 [ Test ]
37273757 [ Category ( "Actions" ) ]
37283758 public void Actions_CanRemoveActionMapFromAsset ( )
@@ -4132,8 +4162,9 @@ public void Actions_CanMaskOutBindingsByBindingGroup_OnAction()
41324162
41334163 action . bindingMask = new InputBinding { groups = "gamepad" } ;
41344164
4135- Assert . That ( action . controls , Has . Count . EqualTo ( 1 ) ) ;
4165+ Assert . That ( action . controls , Has . Count . EqualTo ( 2 ) ) ;
41364166 Assert . That ( action . controls , Has . Exactly ( 1 ) . SameAs ( gamepad . buttonSouth ) ) ;
4167+ Assert . That ( action . controls , Has . Exactly ( 1 ) . SameAs ( mouse . leftButton ) ) ;
41374168 Assert . That ( action . bindingMask , Is . EqualTo ( new InputBinding { groups = "gamepad" } ) ) ;
41384169
41394170 action . bindingMask = null ;
@@ -4206,8 +4237,9 @@ public void Actions_CanMaskOutBindingsByBindingGroup_OnActionMap()
42064237 map . bindingMask = new InputBinding { groups = "gamepad" } ;
42074238
42084239 Assert . That ( action1 . controls , Has . Count . EqualTo ( 1 ) ) ;
4209- Assert . That ( action2 . controls , Has . Count . Zero ) ;
42104240 Assert . That ( action1 . controls , Has . Exactly ( 1 ) . SameAs ( gamepad . buttonSouth ) ) ;
4241+ Assert . That ( action2 . controls , Has . Count . EqualTo ( 1 ) ) ;
4242+ Assert . That ( action2 . controls , Has . Exactly ( 1 ) . SameAs ( mouse . leftButton ) ) ;
42114243 }
42124244
42134245 [ Test ]
@@ -4254,6 +4286,26 @@ public void Actions_CanMaskOutBindingsByBindingGroup_OnAsset()
42544286 Assert . That ( action2 . controls , Has . Exactly ( 1 ) . SameAs ( keyboard . bKey ) ) ;
42554287 }
42564288
4289+ [ Test ]
4290+ [ Category ( "Actions" ) ]
4291+ public void Actions_WhenMaskingByGroup_BindingsNotInAnyGroupWillBeActive ( )
4292+ {
4293+ var gamepad = InputSystem . AddDevice < Gamepad > ( ) ;
4294+ var mouse = InputSystem . AddDevice < Mouse > ( ) ;
4295+ InputSystem . AddDevice < Keyboard > ( ) ;
4296+
4297+ var action = new InputAction ( ) ;
4298+ action . AddBinding ( "<Gamepad>/buttonSouth" , groups : "Gamepad" ) ;
4299+ action . AddBinding ( "<Keyboard>/space" , groups : "Keyboard&Mouse" ) ;
4300+ action . AddBinding ( "<Pointer>/press" ) ;
4301+
4302+ action . bindingMask = InputBinding . MaskByGroup ( "Gamepad" ) ;
4303+
4304+ Assert . That ( action . controls , Has . Count . EqualTo ( 2 ) ) ;
4305+ Assert . That ( action . controls , Has . Exactly ( 1 ) . SameAs ( gamepad . buttonSouth ) ) ;
4306+ Assert . That ( action . controls , Has . Exactly ( 1 ) . SameAs ( mouse . press ) ) ;
4307+ }
4308+
42574309 // When we have an .inputactions asset, at runtime we should end up with a single array of resolved
42584310 // controls, single array of trigger states, and so on. The expectation is that users won't generally
42594311 // go and configure each map in an asset in a wildly different way. Rather, the maps will usually perform
@@ -4387,6 +4439,54 @@ public void Actions_CanHaveParametersOnComposites()
43874439 Is . EqualTo ( CompositeWithParameters . EnumParameter . B ) ) ;
43884440 }
43894441
4442+ [ Test ]
4443+ [ Category ( "Actions" ) ]
4444+ [ TestCase ( "" , "<Gamepad>/buttonSouth" , "<Gamepad>/buttonWest" , "<Gamepad>/buttonEast" ) ]
4445+ [ TestCase ( "<Gamepad>/buttonNorth" , "" , "<Gamepad>/buttonWest" , "<Gamepad>/buttonEast" ) ]
4446+ [ TestCase ( "<Gamepad>/buttonNorth" , "<Gamepad>/buttonSouth" , "" , "<Gamepad>/buttonEast" ) ]
4447+ [ TestCase ( "<Gamepad>/buttonNorth" , "<Gamepad>/buttonSouth" , "<Gamepad>/buttonWest" , "" ) ]
4448+ public void Actions_CanHaveCompositesWithPartsThatAreNotBound ( string up , string down , string left , string right )
4449+ {
4450+ var gamepad = InputSystem . AddDevice < Gamepad > ( ) ;
4451+
4452+ var action = new InputAction ( ) ;
4453+ action . AddCompositeBinding ( "2DVector" )
4454+ . With ( "Up" , up )
4455+ . With ( "Down" , down )
4456+ . With ( "Left" , left )
4457+ . With ( "Right" , right ) ;
4458+
4459+ action . Enable ( ) ;
4460+
4461+ if ( ! string . IsNullOrEmpty ( up ) )
4462+ {
4463+ Press ( gamepad . buttonNorth ) ;
4464+ Assert . That ( action . ReadValue < Vector2 > ( ) , Is . EqualTo ( Vector2 . up ) . Using ( Vector2EqualityComparer . Instance ) ) ;
4465+ Release ( gamepad . buttonNorth ) ;
4466+ }
4467+
4468+ if ( ! string . IsNullOrEmpty ( down ) )
4469+ {
4470+ Press ( gamepad . buttonSouth ) ;
4471+ Assert . That ( action . ReadValue < Vector2 > ( ) , Is . EqualTo ( Vector2 . down ) . Using ( Vector2EqualityComparer . Instance ) ) ;
4472+ Release ( gamepad . buttonSouth ) ;
4473+ }
4474+
4475+ if ( ! string . IsNullOrEmpty ( left ) )
4476+ {
4477+ Press ( gamepad . buttonWest ) ;
4478+ Assert . That ( action . ReadValue < Vector2 > ( ) , Is . EqualTo ( Vector2 . left ) . Using ( Vector2EqualityComparer . Instance ) ) ;
4479+ Release ( gamepad . buttonWest ) ;
4480+ }
4481+
4482+ if ( ! string . IsNullOrEmpty ( right ) )
4483+ {
4484+ Press ( gamepad . buttonEast ) ;
4485+ Assert . That ( action . ReadValue < Vector2 > ( ) , Is . EqualTo ( Vector2 . right ) . Using ( Vector2EqualityComparer . Instance ) ) ;
4486+ Release ( gamepad . buttonEast ) ;
4487+ }
4488+ }
4489+
43904490 [ Test ]
43914491 [ Category ( "Actions" ) ]
43924492 [ Ignore ( "TODO" ) ]
@@ -5497,9 +5597,9 @@ public void Actions_ApplyingNullOverride_IsSameAsRemovingOverride()
54975597 public void Actions_ApplyingEmptyStringOverride_IsSameAsDisablingBinding ( )
54985598 {
54995599 var gamepad = InputSystem . AddDevice < Gamepad > ( ) ;
5500- var action = new InputAction ( binding : "/gamepad /leftTrigger" ) ;
5600+ var action = new InputAction ( binding : "<Gamepad> /leftTrigger" ) ;
55015601
5502- bool performed = false ;
5602+ var performed = false ;
55035603 action . performed += _ => performed = true ;
55045604
55055605 action . Enable ( ) ;
@@ -5516,6 +5616,11 @@ public void Actions_ApplyingEmptyStringOverride_IsSameAsDisablingBinding()
55165616 Press ( gamepad . leftTrigger ) ;
55175617
55185618 Assert . That ( performed , Is . False ) ;
5619+
5620+ // We had a bug (case 1187163) where InputActionState would cause an exception by not
5621+ // respecting the empty path when checking if a newly added device is affecting the state.
5622+ // Just add a device here to make sure that's handled correctly.
5623+ Assert . That ( ( ) => InputSystem . AddDevice < Gamepad > ( ) , Throws . Nothing ) ;
55195624 }
55205625
55215626 [ Test ]
0 commit comments