Skip to content

Commit 241946a

Browse files
authored
CHANGE: Switch from InputManager.asset to asset-based storage for Project-wide actions (#1834)
* Replacing use of Inputmanager.asset with promoted InputActionsAsset ** Old settings in: ProjectSettings\InputManager.asset ** New settings in: Assets\InputSystem_Actions.inputactions * Improved UX for the project wide input actions in project settings * Added indication of selected project wide input actions asset * Fixed up some styles for the header * Fixed Editor_LeavingPlayMode_DestroysAllActionStates test for when InputSystem.actions is null * Sanity checks added to project wide input actions * Removed redundant code for saving InputActionAssets and relocated to InputActionAssetManager. Eliminated redundant dialog strings by utilising a common utility function regardless of editor framework. * Reset behavior is an in-memory operation that is undoable. * Added clear menu option to quickly clean up default asset if desirable. Modified CopyPasteHelpers, SerializationHelpers to allow using buffer modification for any string buffer. * Moved access to physical path to helper to avoid #ifdef in code. * Code added to migrate InputSystem's project-wide action assets from InputManager asset ** Only try to migrate project-wide input action assets from InputManager.asset file once. * Updated InputActionAsset and InputActionReference property drawers **Project wide input action assets now shown in separate column in InputActionAsset view like the InputActionReference view. **Removed the dropdown to select between at the top level since that's not so intuitive when the project wide asset reference can change. * Removed a fix for ISX-1721 which is having a side effect of limiting nesting in hierarchy * Project Settings Input Action Edito handles deleting assets while being open. Reenabled and updated and added some unit tests for related asset management. * Added confirmation box on creating an new asset that would overwrite an existing * Made sure project wide input actions are enabled on entering play mode * Disable project wide input actions on exit play mode (well enter edit mode) * Temporarily disabled ProjectWideActions_ThrowsWhenAddingOrRemovingWhileEnabled test since unclear of its relevance. * Corrected improper use of operator for null checks when using UnityEngine.Object * InputForUI hook added to update when InputSystem.actions changes * Removed one test which is causing next two to fail * Gracefully disable actions to avoid assert on destruction
1 parent a280e35 commit 241946a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1596
-838
lines changed

Assets/Samples/ProjectWideActions/ProjectWideActionsExample.cs

+32-13
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,46 @@ public class ProjectWideActionsExample : MonoBehaviour
2020
void Start()
2121
{
2222
// Project-Wide Actions
23-
move = InputSystem.actions.FindAction("Player/Move");
24-
look = InputSystem.actions.FindAction("Player/Look");
25-
attack = InputSystem.actions.FindAction("Player/Attack");
26-
jump = InputSystem.actions.FindAction("Player/Jump");
27-
interact = InputSystem.actions.FindAction("Player/Interact");
28-
next = InputSystem.actions.FindAction("Player/Next");
29-
previous = InputSystem.actions.FindAction("Player/Previous");
30-
sprint = InputSystem.actions.FindAction("Player/Sprint");
31-
crouch = InputSystem.actions.FindAction("Player/Crouch");
23+
if (InputSystem.actions)
24+
{
25+
move = InputSystem.actions.FindAction("Player/Move");
26+
look = InputSystem.actions.FindAction("Player/Look");
27+
attack = InputSystem.actions.FindAction("Player/Attack");
28+
jump = InputSystem.actions.FindAction("Player/Jump");
29+
interact = InputSystem.actions.FindAction("Player/Interact");
30+
next = InputSystem.actions.FindAction("Player/Next");
31+
previous = InputSystem.actions.FindAction("Player/Previous");
32+
sprint = InputSystem.actions.FindAction("Player/Sprint");
33+
crouch = InputSystem.actions.FindAction("Player/Crouch");
34+
35+
if (!InputSystem.actions.enabled)
36+
{
37+
Debug.Log("Project Wide Input Actions should be enabled by default by Unity but they are not - enabling to make sure the input works");
38+
InputSystem.actions.Enable();
39+
}
40+
}
41+
else
42+
{
43+
Debug.Log("Setup Project Wide Input Actions in the Player Settings, Input System section");
44+
}
3245

3346
// Handle input by responding to callbacks
34-
attack.performed += ctx => cube.GetComponent<Renderer>().material.color = Color.red;
35-
attack.canceled += ctx => cube.GetComponent<Renderer>().material.color = Color.green;
47+
if (attack != null)
48+
{
49+
attack.performed += ctx => cube.GetComponent<Renderer>().material.color = Color.red;
50+
attack.canceled += ctx => cube.GetComponent<Renderer>().material.color = Color.green;
51+
}
3652
}
3753

3854
// Update is called once per frame
3955
void Update()
4056
{
4157
// Handle input by polling each frame
42-
var moveVal = move.ReadValue<Vector2>() * 10.0f * Time.deltaTime;
43-
cube.transform.Translate(new Vector3(moveVal.x, moveVal.y, 0));
58+
if (move != null)
59+
{
60+
var moveVal = move.ReadValue<Vector2>() * 10.0f * Time.deltaTime;
61+
cube.transform.Translate(new Vector3(moveVal.x, moveVal.y, 0));
62+
}
4463
}
4564
} // class ProjectWideActionsExample
4665
} // namespace UnityEngine.InputSystem.Samples.ProjectWideActions

Assets/Tests/InputSystem/CoreTests_Editor.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -2907,9 +2907,12 @@ public void Editor_LeavingPlayMode_DestroysAllActionStates()
29072907
// Exclude project-wide actions from this test
29082908
// With Project-wide Actions `InputSystem.actions`, we begin with some initial ActionState
29092909
// Disabling Project-wide actions so that we begin from zero.
2910-
Assert.That(InputActionState.s_GlobalState.globalList.length, Is.EqualTo(1));
2911-
InputSystem.actions?.Disable();
2912-
InputActionState.DestroyAllActionMapStates();
2910+
if (InputSystem.actions)
2911+
{
2912+
Assert.That(InputActionState.s_GlobalState.globalList.length, Is.EqualTo(1));
2913+
InputSystem.actions?.Disable();
2914+
InputActionState.DestroyAllActionMapStates();
2915+
}
29132916
#endif
29142917

29152918
// Initial state

0 commit comments

Comments
 (0)