Skip to content
This repository has been archived by the owner on May 9, 2023. It is now read-only.

InputManager

Sinai edited this page Jan 31, 2022 · 3 revisions

The InputManager class contains methods for using Unity's Input API regardless of which input package is being used by the game (Legacy or InputSystem).

It supports the common input API features such as MousePosition, MouseScrollDelta, GetKey/Down, GetMouseButton/Down, etc.

InputManager requires the startupDelay from Universe.Init to have finished, so any calls to its methods before then will return default.

See the InputManager source for details on the available methods.

Rebinding

The InputManager has a "rebinding" helper for simple rebinds (does not support key combinations yet).

void OnBeginRebindPressed()
{
    InputManager.BeginRebind(OnSelection, OnFinished);
}

void OnEndRebindPressed()
{
    InputManager.EndRebind();
}

void OnSelection(KeyCode pressed)
{
    // Perhaps update a displayed label with the pressed key to give the user some feedback
}

void OnFinished(KeyCode? bound)
{
    // The bound key may be null, indicating the user didn't press anything.
}

KeyCode/Key

All key-related InputManager methods take a UnityEngine.KeyCode as opposed to a UnityEngine.InputSystem.Key, since KeyCode is always included in all builds of Unity, whereas Key is only present in games which use the InputSystem package.

If the game in fact uses InputSytem, UniverseLib will translate the KeyCode into the corresponding Key to the best of its ability. If you find a Key which is unsupported, please create an issue in this repository.