DoopelPonger
Classes | Public Types | Public Member Functions | List of all members
InputManager Class Reference

Important class that handles all user input. More...

Inheritance diagram for InputManager:
Inheritance graph
[legend]
Collaboration diagram for InputManager:
Collaboration graph
[legend]

Public Types

enum  InputTriggerOption {
  InputTriggerOption.PLAYER_0_MOVEMENT, InputTriggerOption.PLAYER_1_MOVEMENT, InputTriggerOption.PLAYER_0_POWER, InputTriggerOption.PLAYER_1_POWER,
  InputTriggerOption.PLAYER_0_SHIELD, InputTriggerOption.PLAYER_1_SHIELD, InputTriggerOption.MENU_UP, InputTriggerOption.MENU_DOWN,
  InputTriggerOption.MENU_SELECT, InputTriggerOption.MENU_BACK, InputTriggerOption.PAUSE
}
 The type of listeners classes can register to receive input for. More...
 
enum  InputCheckerType { InputCheckerType.CONTINUOUS_PRESS, InputCheckerType.RELEASE, InputCheckerType.SINGLE_PRESS_UPDATE, InputCheckerType.SINGLE_PRESS_FIXED_UPDATE }
 Controls how the registered listener will get notified. More...
 

Public Member Functions

delegate void MovementTrigger (float movement)
 
delegate void ButtonPressTrigger ()
 
delegate bool StoppableButtonPressTrigger ()
 
delegate void AnyButtonPressTrigger (KeyCode keyCode)
 
void Awake ()
 Initialize data structures used by the manager. More...
 
void Update ()
 Check with all the registered InputCheckers to see what work should be done on the next FixedUpdate tick. More...
 
void FixedUpdate ()
 Drain the queue of listeners to notify a key has been pressed. More...
 
void RegisterMovementTrigger (InputTriggerOption triggerOption, MovementTrigger trigger, string tag)
 Register to be notified of a movement trigger when an InputTriggerOption being triggered. More...
 
void RegisterAnyKeyPressedTrigger (AnyButtonPressTrigger trigger)
 Register to be notified when any key is pressed. When the any key listener is registered it prevents all other listeners from being notified. More...
 
void RegisterStoppableButtonPressTrigger (InputTriggerOption triggerOption, StoppableButtonPressTrigger trigger, string tag)
 Register for a listener that can break the chain of listener notifications, useful for UI when players shouldn't move when paused. More...
 
void RegisterButtonPressTrigger (InputTriggerOption triggerOption, ButtonPressTrigger trigger, string tag, params InputCheckerType[] inputCheckerTypes)
 Register for a listener to be notified when the triggerOption is pressed. More...
 
void DeregisterAnyKeyPressedTrigger ()
 Remove the any key pressed listener. More...
 
void DeregisterTrigger (InputTriggerOption triggerOption, string tag)
 Remove the triggerOption and tag from the listeners. More...
 

Detailed Description

Important class that handles all user input.

The class has a way for classes to register callbacks based on input issued by the user. To register callbacks, code supplies the InputTriggerOption they want to get notified on and the function this class should call. This class then has a mapping from InputTriggerOption to Actions. Those Actions are then linked to KeyCodes. InputTriggerOptions have a 1 to many relationship for Actions and Actions have a 1 to 1 relationship with KeyCodes. This three tier structure is used so that dependencies can say "Hey notify me when player 0 activates the shield" The player 0 shield InputTriggerOption can then map to the player 0 shield primary and player 0 shield secondary actions. And finally each action can be mapped to a user configurable KeyCode (left and right arrow can spawn the shield).

Member Enumeration Documentation

◆ InputCheckerType

Controls how the registered listener will get notified.

CONTINUOUS_PRESS will make sure the callback is triggered every FixedUpdate tick the key is held down RELEASE will make sure the callback is triggered the FixuedUpdate tick the key is released SINGLE_PRESS_UPDATE will make sure the callback is triggered only on the frame the key is pressed SINGLE_PRESS_FIXED_UPDATE will make sure the callback is triggered only on the FixedUpdate tick after the key is pressed

Enumerator
CONTINUOUS_PRESS 
RELEASE 
SINGLE_PRESS_UPDATE 
SINGLE_PRESS_FIXED_UPDATE 

◆ InputTriggerOption

The type of listeners classes can register to receive input for.

Enumerator
PLAYER_0_MOVEMENT 
PLAYER_1_MOVEMENT 
PLAYER_0_POWER 
PLAYER_1_POWER 
PLAYER_0_SHIELD 
PLAYER_1_SHIELD 
MENU_UP 
MENU_DOWN 
MENU_SELECT 
MENU_BACK 
PAUSE 

Member Function Documentation

◆ AnyButtonPressTrigger()

delegate void InputManager.AnyButtonPressTrigger ( KeyCode  keyCode)

Callback for the listeners that want to be notified when any key is pressed, don't care what the key is.

Parameters
keyCodeKey pressed.

◆ Awake()

void InputManager.Awake ( )

Initialize data structures used by the manager.

◆ ButtonPressTrigger()

delegate void InputManager.ButtonPressTrigger ( )

Callback for listeners that want to know when a key is pressed.

◆ DeregisterAnyKeyPressedTrigger()

void InputManager.DeregisterAnyKeyPressedTrigger ( )

Remove the any key pressed listener.

◆ DeregisterTrigger()

void InputManager.DeregisterTrigger ( InputTriggerOption  triggerOption,
string  tag 
)

Remove the triggerOption and tag from the listeners.

Parameters
triggerOptionInput to remove
tagThe matching tag to the triggerOption to remove.

◆ FixedUpdate()

void InputManager.FixedUpdate ( )

Drain the queue of listeners to notify a key has been pressed.

◆ MovementTrigger()

delegate void InputManager.MovementTrigger ( float  movement)

Callback for listeners of values between -1 to 1. The use in this game is movement where 0 is not moving, -1 is down, and 1 is up.

Parameters
movementThe value between -1 to 1, calculated from buttons being pressed.

◆ RegisterAnyKeyPressedTrigger()

void InputManager.RegisterAnyKeyPressedTrigger ( AnyButtonPressTrigger  trigger)

Register to be notified when any key is pressed. When the any key listener is registered it prevents all other listeners from being notified.

Parameters
triggerCallback for when any key is pressed.

◆ RegisterButtonPressTrigger()

void InputManager.RegisterButtonPressTrigger ( InputTriggerOption  triggerOption,
ButtonPressTrigger  trigger,
string  tag,
params InputCheckerType []  inputCheckerTypes 
)

Register for a listener to be notified when the triggerOption is pressed.

Parameters
triggerOptionWhen the trigger should be notified.
triggerCallback to notify.
tagUnique identifier used to remove the registered listener.
inputCheckerTypesWhen during the Update/FixedUpdate ticks the listener should be notified.

◆ RegisterMovementTrigger()

void InputManager.RegisterMovementTrigger ( InputTriggerOption  triggerOption,
MovementTrigger  trigger,
string  tag 
)

Register to be notified of a movement trigger when an InputTriggerOption being triggered.

Parameters
triggerOptionThe input to trigger the notification on.
triggerThe callback method.
tagUnique identifier used to remove the registered listener.

◆ RegisterStoppableButtonPressTrigger()

void InputManager.RegisterStoppableButtonPressTrigger ( InputTriggerOption  triggerOption,
StoppableButtonPressTrigger  trigger,
string  tag 
)

Register for a listener that can break the chain of listener notifications, useful for UI when players shouldn't move when paused.

Parameters
triggerOptionWhen the trigger should be notified.
triggerCallback to notify.
tagUnique identifier used to remove the registered listener.

◆ StoppableButtonPressTrigger()

delegate bool InputManager.StoppableButtonPressTrigger ( )

Callback for listeners that want to know when a key is pressed and also want to prevent other input listeners from getting notifications.

Returns
True if no more listeners should be notiied of the input triggered.

◆ Update()

void InputManager.Update ( )

Check with all the registered InputCheckers to see what work should be done on the next FixedUpdate tick.


The documentation for this class was generated from the following file: