Skip to main content

KeyboardEventTriggers

A class in Root.Township, the global namespace.

Static registry that calls handlers when keyboard keys are pressed or released, using the Unity Input System. One instance in the scene polls the tracked keys each frame and is only enabled while any key is registered.

Constructors​

MemberWhat it is
KeyboardEventTriggers()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

4 private and internal fields
MemberWhat it is
private static List<Key> currentKeysList of tracked keys, walked by Update.
private static KeyboardEventTriggers instanceThe scene component doing the polling.
private static Logger loggerLogger for this class.
private static Dictionary<Key, KeyboardEventTriggers.KeyTracker> mappedTrackersTracker holding the down and up handlers for each key.

Methods​

MemberWhat it is
static void DeRegisterKeyPressed(ref IKeyBoardTriggerHandler triggerHandler)Removes a handler added by RegisterKeyPressed and nulls the handle. Stops tracking the key once it has no handlers left.
static void RegisterKeyPressed(Key key, bool isDown, KeyEventHandler handler, out IKeyBoardTriggerHandler triggerHandler)Adds a handler for a key going down or up and returns a handle for removing it. Gives a null handle if there's no keyboard.
3 private and internal methods
MemberWhat it is
private void Awake()Becomes the polling instance and enables itself only if keys are already registered.
private void OnDestroy()Clears the polling instance.
private void Update()Polls each tracked key and fires its down or up handlers for this frame.