Input Module - HueSamai/CementSource GitHub Wiki
The Input Module provides a way to map inputs to beasts. Let's say you want to turn all beasts who jump, purple. This Module allows you to do that. Here's the code for what I exactly just said:
using CementTools.Modules.InputModule;
// these methods will go in a CementMod
void AssignCallback()
{
// for keyboards
InputManager.onInput(Input.space).bind(TurnPlayerPurple);
// for controllers
InputManager.onInput(Input.buttonsouth).bind(TurnPlayerPurple);
}
void TurnPlayerPurple(Actor beast)
{
beast.primaryColor = Color.magenta;
}
The Input class is static and just contains a bunch of fields of const strings, which makes it easy to find which input you are looking for, without having to memorise the low level path of the input.
I'm not going to go through all of them here, cause there are a lot, but one thing to keep in mind is that the controller buttons are generic, so as we saw in the last example, the XBox A
button and the Playstation X
button are both represented by buttonsouth
.
You can search through all of the different fields for the Input class, in your IDE, or by looking at the source code.
InputManager is a static class, which allows you to get a CallbackManager, a class which allows you to bind events, for an input or set of inputs. To help understand better, the InputManager, manages CallbackManager, whilst CallbackManagers handle firing all the callbacks associated with an event.
public static CallbackManager onInput(string inputName)
Takes in an input path, and returns a CallbackManager, for that input path, which will be fired once on the first frame the input is pressed.
public static CallbackManager onInputs(params string[] inputNames)
Takes any number of input paths as an input, and returns a CallbackManager, which will only be fired once on the first frame where all the given inputs are pressed.
public static CallbackManager onInputHeld(string inputName)
Same as onInput, but the CallbackManager will be fired every frame the input is pressed.
public static CallbackManager onInputsHeld(params string[] inputNames)
Same as onInputs, but the CallbackManager will be fired every frame all the inputs is pressed.
public static InputDevice GetInputDeviceFromActor(Actor actor)
Allows you to get the InputDevice associated with a specific actor (beast/player).
A class which manages binding, unbinding, and firing events. An instance of a CallbackManager gets returned by the InputManager for every input or specific set of inputs.
public void bind(Action<Actor> callback)
Bind a callback (a method) which takes the Actor (beast) associated with the InputDevice which triggered the input callback, as an argument, and returns nothing. This method will be added to a list of callbacks, which will get fired, when the specific event associated with the CallbackManager occurs.
public void unbind(Action<Actor> callback)
Unbind a previously binded callback, from the list of callbacks.
public void TriggerCallbacks(Actor actor)
Triggers the list of callbacks for a CallbackManager. This is used by the InputManager.
public CallbackManager(string input)
Used by InputManager, to create a new CallbackManager associated with just one input.
public CallbackManager(string[] inputs)
Used by InputManager, to create a new CallbackManager associated with multiple inputs.