Skip to content

Commit

Permalink
CHANGE: Switch from InputManager.asset to asset-based storage for Pro…
Browse files Browse the repository at this point in the history
…ject-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
  • Loading branch information
ekcoh committed Feb 18, 2024
1 parent a280e35 commit 241946a
Show file tree
Hide file tree
Showing 42 changed files with 1,596 additions and 838 deletions.
45 changes: 32 additions & 13 deletions Assets/Samples/ProjectWideActions/ProjectWideActionsExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,46 @@ public class ProjectWideActionsExample : MonoBehaviour
void Start()
{
// Project-Wide Actions
move = InputSystem.actions.FindAction("Player/Move");
look = InputSystem.actions.FindAction("Player/Look");
attack = InputSystem.actions.FindAction("Player/Attack");
jump = InputSystem.actions.FindAction("Player/Jump");
interact = InputSystem.actions.FindAction("Player/Interact");
next = InputSystem.actions.FindAction("Player/Next");
previous = InputSystem.actions.FindAction("Player/Previous");
sprint = InputSystem.actions.FindAction("Player/Sprint");
crouch = InputSystem.actions.FindAction("Player/Crouch");
if (InputSystem.actions)
{
move = InputSystem.actions.FindAction("Player/Move");
look = InputSystem.actions.FindAction("Player/Look");
attack = InputSystem.actions.FindAction("Player/Attack");
jump = InputSystem.actions.FindAction("Player/Jump");
interact = InputSystem.actions.FindAction("Player/Interact");
next = InputSystem.actions.FindAction("Player/Next");
previous = InputSystem.actions.FindAction("Player/Previous");
sprint = InputSystem.actions.FindAction("Player/Sprint");
crouch = InputSystem.actions.FindAction("Player/Crouch");

if (!InputSystem.actions.enabled)
{
Debug.Log("Project Wide Input Actions should be enabled by default by Unity but they are not - enabling to make sure the input works");
InputSystem.actions.Enable();
}
}
else
{
Debug.Log("Setup Project Wide Input Actions in the Player Settings, Input System section");
}

// Handle input by responding to callbacks
attack.performed += ctx => cube.GetComponent<Renderer>().material.color = Color.red;
attack.canceled += ctx => cube.GetComponent<Renderer>().material.color = Color.green;
if (attack != null)
{
attack.performed += ctx => cube.GetComponent<Renderer>().material.color = Color.red;
attack.canceled += ctx => cube.GetComponent<Renderer>().material.color = Color.green;
}
}

// Update is called once per frame
void Update()
{
// Handle input by polling each frame
var moveVal = move.ReadValue<Vector2>() * 10.0f * Time.deltaTime;
cube.transform.Translate(new Vector3(moveVal.x, moveVal.y, 0));
if (move != null)
{
var moveVal = move.ReadValue<Vector2>() * 10.0f * Time.deltaTime;
cube.transform.Translate(new Vector3(moveVal.x, moveVal.y, 0));
}
}
} // class ProjectWideActionsExample
} // namespace UnityEngine.InputSystem.Samples.ProjectWideActions
Expand Down
9 changes: 6 additions & 3 deletions Assets/Tests/InputSystem/CoreTests_Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2907,9 +2907,12 @@ public void Editor_LeavingPlayMode_DestroysAllActionStates()
// Exclude project-wide actions from this test
// With Project-wide Actions `InputSystem.actions`, we begin with some initial ActionState
// Disabling Project-wide actions so that we begin from zero.
Assert.That(InputActionState.s_GlobalState.globalList.length, Is.EqualTo(1));
InputSystem.actions?.Disable();
InputActionState.DestroyAllActionMapStates();
if (InputSystem.actions)
{
Assert.That(InputActionState.s_GlobalState.globalList.length, Is.EqualTo(1));
InputSystem.actions?.Disable();
InputActionState.DestroyAllActionMapStates();
}
#endif

// Initial state
Expand Down

0 comments on commit 241946a

Please sign in to comment.