Class InputBindingService
The default input binding service. It reads the devices once a frame and works out the state of each action.
public sealed class InputBindingService : IInputBindingService, IDisposable
- Inheritance
-
InputBindingService
- Implements
- Inherited Members
Constructors
InputBindingService(DeviceInputManager, InputContextManager)
Created by dependency injection. Makes itself the current InputBindingLocator when there is none.
public InputBindingService(DeviceInputManager deviceInputManager, InputContextManager contextManager)
Parameters
deviceInputManagerDeviceInputManagercontextManagerInputContextManager
Properties
KeysDown
The keys that went down this step. Named as on IKeyboardManager.
public IReadOnlyList<Key> KeysDown { get; }
Property Value
KeysPressed
Every key held down this step. Named as on IKeyboardManager.
public IReadOnlyList<Key> KeysPressed { get; }
Property Value
Methods
Consume(string)
Marks the action consumed for the rest of this frame. Does nothing for an unregistered action.
public void Consume(string actionId)
Parameters
actionIdstring
ConsumeAll()
Marks every action consumed for the rest of this frame.
public void ConsumeAll()
Dispose()
Stops this service being the current InputBindingLocator.
public void Dispose()
GetAxisValue(string)
The axis value of the action this frame. Zero when it has been consumed or is not registered.
public float GetAxisValue(string actionId)
Parameters
actionIdstring
Returns
GetBinding(string)
Returns a copy of the action's current binding.
public InputBinding GetBinding(string actionId)
Parameters
actionIdstring
Returns
Exceptions
- KeyNotFoundException
The action is not registered.
GetRegisteredActions()
The definitions of every registered action.
public IEnumerable<InputActionDefinition> GetRegisteredActions()
Returns
HasAction(string)
Whether an action with this id is registered.
public bool HasAction(string id)
Parameters
idstring
Returns
IsPressed(string)
Whether the action is down this frame and has not been consumed. False for an unregistered action.
public bool IsPressed(string actionId)
Parameters
actionIdstring
Returns
RegisterAction(InputActionDefinition)
Registers an action, or updates the definition of an action with the same id. A binding the player set is kept.
public void RegisterAction(InputActionDefinition definition)
Parameters
definitionInputActionDefinition
ResetBinding(string)
Returns the action to its default binding, discarding the player's changes.
public void ResetBinding(string actionId)
Parameters
actionIdstring
SetBinding(string, InputBinding)
Replaces the action's binding with a copy of binding. The binding is kept
when the action is re-registered.
public void SetBinding(string actionId, InputBinding binding)
Parameters
actionIdstringbindingInputBinding
Exceptions
- ArgumentException
The binding's inputs do not match the action's type.
- KeyNotFoundException
The action is not registered.
SetGamepadAxisBinding(string, GamepadAxis, bool, float)
Sets the gamepad stick or trigger of an axis action. The value can be inverted and is read as 0 inside the deadzone.
public void SetGamepadAxisBinding(string actionId, GamepadAxis axis, bool invert = false, float deadzone = 0.2)
Parameters
actionIdstringaxisGamepadAxisinvertbooldeadzonefloat
Exceptions
- InvalidOperationException
The action is not an axis action.
SetGamepadBinding(string, params GamepadButton[])
Replaces the gamepad buttons of a button action with buttons.
public void SetGamepadBinding(string actionId, params GamepadButton[] buttons)
Parameters
actionIdstringbuttonsGamepadButton[]
Exceptions
- InvalidOperationException
The action is not a button action.
SetGamepadButtonAxisBinding(string, GamepadButton, GamepadButton, float)
Sets the gamepad buttons of an axis action to one pair. Each held button adds
scale to the value.
public void SetGamepadButtonAxisBinding(string actionId, GamepadButton negative, GamepadButton positive, float scale = 1)
Parameters
actionIdstringnegativeGamepadButtonpositiveGamepadButtonscalefloat
Exceptions
- InvalidOperationException
The action is not an axis action.
SetKeyboardAxisBinding(string, Key, Key, float)
Sets the keyboard keys of an axis action to one key pair. Each held key adds
scale to the value.
public void SetKeyboardAxisBinding(string actionId, Key negative, Key positive, float scale = 1)
Parameters
Exceptions
- InvalidOperationException
The action is not an axis action.
SetKeyboardBinding(string, params Key[])
Replaces the keyboard keys of a button action with keys.
public void SetKeyboardBinding(string actionId, params Key[] keys)
Parameters
Exceptions
- InvalidOperationException
The action is not a button action.
TryGetBinding(string, out InputBinding)
Returns a copy of the action's current binding, and whether the action is registered.
public bool TryGetBinding(string actionId, out InputBinding binding)
Parameters
actionIdstringbindingInputBinding
Returns
UnregisterAction(string)
Removes an action. An unknown id does nothing.
public void UnregisterAction(string actionId)
Parameters
actionIdstring
Update(float)
Works out this frame's state from the devices. Does nothing once the frame loop drives the service, so calling it as well is harmless.
public void Update(float deltaTime)
Parameters
deltaTimefloat
WasJustPressed(string)
Whether the action went down this frame and has not been consumed. False for an unregistered action.
public bool WasJustPressed(string actionId)
Parameters
actionIdstring
Returns
WasJustPressedOrRepeated(string)
WasJustPressed(string), plus every OS key repeat while the action is held.
public bool WasJustPressedOrRepeated(string actionId)
Parameters
actionIdstring
Returns
Remarks
For actions where holding the key should keep acting: deleting a character, stepping through a list. Most actions want the plain WasJustPressed(string) -- firing, opening a menu, toggling anything -- which is why this is a separate call rather than a change to what "just pressed" means for everybody. Movement in particular must not use it: movement is read as a level and paced by the game, not by the OS repeat rate.
Keyboard only. A held gamepad button produces no repeat events, so for an action bound to one this reports exactly what WasJustPressed(string) does.
WasJustReleased(string)
Whether the action went up this frame and has not been consumed. False for an unregistered action.
public bool WasJustReleased(string actionId)
Parameters
actionIdstring