Creating Custom Input Handlers
Overview
NeoFPS includes a number of example input handlers:
Handlers are attached to objects that require a unique control sceme. For example, each firearm has an input handler that is different from the handlers attached to melee weapons.
Handlers are context based and will not return any input when the context is not current.
FpsInputButton
NeoFPS uses a generated constant to define the available button/key inputs. This constant can be expanded based on your game requirements by changing the ConstantsSettings and regenerating the constant.
Take care that reordering entries in the constant will break those values in the inspector as they are stored based on index. Code will adapt to the changes in order, but inspector properties will need checking.
FpsInput Base Class
All input handlers derive from the FpsInputSystemHandler class. This controls context and exposes functions similar to Unity's Input class but uses the actions defined in the NeoFpsInputActions class instead of key codes and button IDs. This helps to separate the input from the key bindings.
The following is a simple example input handler:
public class InputExample : FpsInputSystemHandler
{
public override FpsInputContext inputContext
{
// This input will only work when the "character" input context is active
get { return FpsInputContext.Character; }
}
protected override void OnGainFocus()
{
// This method is called when the input context the handler uses gains focus
}
protected override void OnLoseFocus()
{
// This method is called when the input context the handler uses loses focus
}
protected override void UpdateInput()
{
// Main controls
var controls = NeoFpsNewInputManager.controls;
if (GetButtonDown (controls.Combat.PrimaryFire))
{
// React to the fire button
}
}
}