Table of Contents

Class InputManager

Namespace
Koala.Simulation.Input
Assembly
Koala.Simulation.dll

Centralized input system built on Unity's new Input System.

Provides event-based access to all input actions, automatic handling of action maps, and support for runtime map switching with stack semantics.

Key features:

  • Subscribe/unsubscribe to any action by name
  • Global OnAnyActionStarted event for catching all input started phase
  • Global OnAnyActionPhase event for catching all input phase (started, performed, canceled)
  • Switch, push, and pop between multiple action maps
  • Notifies when the active action map changes
  • Integrates with InputSettingsService for binding overrides

Access this class directly via InputManager. Requires SimulationManager to be present in the scene. Only one instance of SimulationManager should exist.

public sealed class InputManager

Examples

Example: Subscribing to the "Jump" action

private void OnEnable()
{
    InputManager.Subscribe("Jump", OnJump);
}

private void OnDisable()
{
    InputManager.Unsubscribe("Jump", OnJump);
}

private void OnJump(InputAction.CallbackContext ctx)
{
    if (ctx.performed)
        Debug.Log("Jump pressed!");
}

Example: Listening to all actions

private void OnEnable()
{
    InputManager.OnAnyAction += OnAny;
}

private void OnDisable()
{
    InputManager.OnAnyAction -= OnAny;
}

private void OnAny(InputAction.CallbackContext ctx)
{
    Debug.Log($"Action fired: {ctx.action.name}");
}

Example: Switching action maps

// Set UI as the active map (stack cleared)
InputManager.SetActionMap("UI");

// Push Pause menu map (UI stays underneath)
InputManager.PushActionMap("Pause");

// Pop Pause -> returns to UI
InputManager.PopActionMap();

Constructors

Name Declaration Description
InputManager(InputActionAsset, string, InputSpriteAsset) public InputManager(InputActionAsset actionAsset, string defaultActionMap, InputSpriteAsset inputSpriteAsset)

Properties

Name Declaration Description
CurrentActionMap public static string CurrentActionMap { get; }

Gets the name of the currently active action map. Returns null if no map is active.

Methods

Name Declaration Description
FindAction(string) public static InputAction FindAction(string actionName)

Find an action by name in the currently active action map. Returns null if not found.

GetKeyDisplayName(string, int) public static string GetKeyDisplayName(string actionName, int bindingIndex = 0)

Gets the display name of the binding for a given action. Uses caching for fast repeated access. Call Koala.Simulation.Input.InputManager.InvalidateCache() after rebinding.

PopActionMap() public static void PopActionMap()

Pops the current action map from the stack and restores the previous one. Does nothing if there is only one map left.

PushActionMap(string) public static void PushActionMap(string mapName)

Pushes a new action map onto the stack and activates it. When popped, the previous map will be restored.

SetActionMap(string) public static void SetActionMap(string mapName)

Sets the active action map directly. Clears the internal stack and replaces it with the given map.

Subscribe(string, Action<CallbackContext>) public static void Subscribe(string actionName, Action<InputAction.CallbackContext> callback)

Subscribes a callback to the specified action by name. The callback is invoked for all phases of the action (Started, Performed, and Canceled). Use this when you need the full UnityEngine.InputSystem.InputAction.CallbackContext.

Example: InputManager.Subscribe("Jump", OnJump).

Subscribe(string, Action<CallbackContext>, InputActionPhase) public static void Subscribe(string actionName, Action<InputAction.CallbackContext> callback, InputActionPhase phase = InputActionPhase.Started)

Subscribes a callback to the specified action by name, filtered by phase.

The callback is only invoked when the action enters the given phase (Started, Performed, or Canceled). Defaults to UnityEngine.InputSystem.InputActionPhase.Started for button-like behavior.

Example: Called only once when "Jump" starts InputManager.Subscribe("Jump", OnJump, InputActionPhase.Started);

Called every frame while "Move" is performed InputManager.Subscribe("Move", OnMove, InputActionPhase.Performed);

TryGetSprite(string, out Sprite) public static bool TryGetSprite(string actionName, out Sprite sprite)

Gets a sprite for a given action name if it exists. e.g LMB, RMB

Unsubscribe(string, Action<CallbackContext>) public static void Unsubscribe(string actionName, Action<InputAction.CallbackContext> callback)

Unsubscribe from a previously subscribed action.

Events

Name Declaration Description
OnActionMapChanged public static event Action<string> OnActionMapChanged

Raised whenever the active action map changes. Provides the new action map's name.

OnAnyActionPhase public static event Action<InputAction.CallbackContext> OnAnyActionPhase

Raised for every input action, regardless of phase. Provides the UnityEngine.InputSystem.InputAction.CallbackContext for the event.

OnAnyActionStarted public static event Action<InputAction.CallbackContext> OnAnyActionStarted

Raised when any input action enters the Started phase. Provides the UnityEngine.InputSystem.InputAction.CallbackContext for the event.