55using UnityEngine . InputSystem ;
66using UnityEngine . TestTools ;
77using UnityEngine ;
8+ using System . Collections ;
89
910#if UNITY_EDITOR
1011using System . IO ;
@@ -143,11 +144,11 @@ public void ProjectWideActions_AppearInEnabledActions()
143144
144145 [ Category ( TestCategory ) ]
145146 [ Test ]
146- [ TestCase ( "Player" , true , Description = "PlayerInput using project-wide actions has the default action map set " +
147+ [ TestCase ( "Player" , true , Description = "PlayerInput using project-wide actions can have default action map set " +
147148 "enabled, and all others disabled." ) ]
148149 [ TestCase ( null , false , Description = "PlayerInput using project wide actions has all action maps of project-wide " +
149150 "actions disabled, if there is no default action map assigned." ) ]
150- public void ProjectWideActions_AreDisabledWithPlayerInput ( string actionMapName , bool expectedResult )
151+ public void ProjectWideActions_CanEnableCurrentActionMapOfPlayerInput ( string actionMapName , bool expectedResult )
151152 {
152153 var keyboard = InputSystem . AddDevice < Keyboard > ( ) ;
153154 var go = new GameObject ( "PlayerInput" ) ;
@@ -159,29 +160,40 @@ public void ProjectWideActions_AreDisabledWithPlayerInput(string actionMapName,
159160 // will be called.
160161 playerInput . defaultActionMap = actionMapName ;
161162
162- #if UNITY_EDITOR
163+ // PWA actions assigned to playerInput start enabled
164+ Assert . That ( playerInput . actions . enabled , Is . True ) ;
165+ Assert . That ( ReferenceEquals ( playerInput . actions , InputSystem . actions ) ) ;
166+
167+ #if UNITY_EDITOR
163168 InputSystem . OnPlayModeChange ( PlayModeStateChange . ExitingEditMode ) ;
164- #endif
169+ #endif
165170
166171 // This makes sure to call PlayerInput.OnEnable()
167172 go . SetActive ( true ) ;
168173
169- Assert . That ( ReferenceEquals ( playerInput . actions , InputSystem . actions ) ) ;
174+ // This mimics usings to disabling actions on Start/Awake.
175+ InputSystem . actions . Disable ( ) ;
176+
177+ if ( ! string . IsNullOrEmpty ( actionMapName ) )
178+ playerInput . SwitchCurrentActionMap ( "Player" ) ;
179+
170180 Assert . That ( playerInput . actions . enabled , Is . EqualTo ( expectedResult ) ) ;
171181
172- #if UNITY_EDITOR
173- // This mimics the behavior of entering play-mode, which will check if InputSystem.EnableActions() should
174- // be called.
182+ // We do this on the editor to make sure project-wide actions maintain the enabled state
183+ // after entering PlayMode.
184+ #if UNITY_EDITOR
175185 InputSystem . OnPlayModeChange ( PlayModeStateChange . EnteredPlayMode ) ;
176- #endif
186+ Assert . That ( playerInput . actions . enabled , Is . EqualTo ( expectedResult ) ) ;
187+ #endif
177188
178- if ( actionMapName != null )
189+ if ( ! string . IsNullOrEmpty ( actionMapName ) )
179190 Assert . That ( playerInput . currentActionMap . enabled , Is . EqualTo ( expectedResult ) ) ;
180191
192+ // Check state of all action maps in the asset
181193 Assert . That ( InputSystem . actions . FindActionMap ( "Player" ) . enabled , Is . EqualTo ( expectedResult ) ) ;
182194 Assert . That ( InputSystem . actions . FindActionMap ( "UI" ) . enabled , Is . False ) ;
183195
184- //NOTE: Asset actions will be considered enabled even if a single action map is enabled
196+ //NOTE: Asset actions are considered enabled even if a single action map is enabled
185197 Assert . That ( playerInput . actions . enabled , Is . EqualTo ( expectedResult ) ) ;
186198 }
187199}
0 commit comments