Skip to content

Commit 232d275

Browse files
authored
Create README.md
1 parent d9f7933 commit 232d275

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# input-processing
2+
This Unity package contains a series of classes that help with the storage and processing of (user) inputs.
3+
4+
While Unity's own Input System is very useful for abstracting input on the hardware level, there are some limitations on the processing front. InputActions fire ``performed`` and ``canceled`` events when input is detected, but the context of these events is meant to be discarded as soon as they are processed. That leaves a gap when evaluating inputs over a longer range of time. The classes in this package serve as an intermediary to that effect.
5+
## Button
6+
The ``Button`` class stores pressed/released (``bool``) input values, and offers some specialised helper methods to interpret button presses/releases over time.
7+
### Setting Button values
8+
A ``Button``'s value can be updated in two primary ways:
9+
1. Manually, through the ``Button.Press()``, ``Button.Release()``, or ``Button.Toggle()`` methods.
10+
2. By attaching an ``InputAction`` to the Button with ``Button.RegisterInputAction()``, or by specifying the ``InputAction`` upon instantiation. This causes the ``Button`` to subscribe to the ``performed`` and ``canceled`` events of said ``InputAction``, and removes the need to use manual methods listed above.
11+
### Reading Button values
12+
A ``Button`` whose value is reliably updated can be read from. A ``Button`` offers various ways of doing so:
13+
1. The ``bool`` property ``Button.Value`` returns the most recently set value of the Button.
14+
2. How long a ``Button`` has been pressed or released in frames (``int``) or seconds (``float``) is returned by properties such as ``Button.PressDurationFrames``, ``Button.PressDurationTime``, ``Button.ReleaseDurationFrames``, and ``Button.ReleaseDurationTime``.
15+
3. Methods such as ``Button.Pressed()``, ``Button.PressedOnCurrentFrame()``, ``Button.Released()``, and ``Button.ReleasedOnCurrentFrame()`` help with detecting individual button presses/releases. ``Button.Accept()`` or optional parameters in the prior methods can be used to acknowledge such button presses/releases, so the ``Button`` doesn't return them more than once.
16+
4. The ``Button`` remembers when it was last pressed/released. This can be used to acknowledge presses/releases that happened before the current frame, thus enabling "buffered" button presses. The methods ``Button.PressedInFrameBuffer()``, ``Button.PressedInTimeBuffer()``, ``Button.ReleasedInFrameBuffer()``, and ``Button.ReleasedInTimeBuffer()`` can be used for this.
17+
5. The ``Button`` exposes events (``Button.OnValueChanged``, ``Button.OnPressed``, and ``Button.OnReleased``), which can be subscribed to.
18+
## Axis
19+
The ``Axis`` class stores axial (``float``) values, as used by triggers and sticks. (Using TwinAxes is recommended for sticks.) Like the ``Button`` class, it offers helper methods to interpret
20+
### Setting Axis values
21+
An ``Axis``' value can be updated in two primary ways:
22+
1. Manually, through the ``Axis.SetValue()`` method.
23+
2. By attaching an ``InputAction`` to the ``Axis`` with ``Axis.RegisterInputAction()``, or by specifying the ``InputAction`` upon instantiation. This causes the ``Axis`` to subscribe to the ``performed`` and ``canceled`` events of said ``InputAction``, and removes the need to use manual methods listed above. The ``InputAction`` **MUST** have "Axis" as its expected Control Type.
24+
### Reading Axis values
25+
An ``Axis`` whose value is reliably updated can be read from. An ``Axis`` offers various ways of doing so:
26+
1. The ``float`` property ``Axis.Value`` returns the most recently set value of the Axis.
27+
2. The ``bool`` properties ``Axis.Positive``, ``Axis.Neutral``, and ``Axis.Negative`` can be called on to evaluate the current ``Axis``' value for conditional statements.
28+
3. How long an ``Axis`` has been positive (> 0f), neutral (== 0f), or negative (< 0f) can be calculated in frames (``int``) or seconds (``float``) using methods such as ``Axis.PositiveDurationFrames()``, ``Axis.PositiveDurationTime()``, ``Axis.NeutralDurationFrames()``, ``Axis.NeutralDurationTime()``, ``Axis.GetNegativeDurationFrames()``, and ``Axis.GetNegativeDurationTime()``.
29+
4. The ``Axis`` exposes events (``Axis.OnValueChanged``, ``Axis.OnPositive``, ``Axis.OnNeutral``, and ``Axis.OnNegative``), which can be subscribed to.
30+
## TwinAxes
31+
The ``TwinAxes`` class stores a pair (``Vector2``) of ``Axis`` instances, making it highly recommended for joy-/control-sticks. It has some dedicated methods to easily manage and read both ``Axis`` at once.
32+
### Setting TwinAxes values
33+
A ``TwinAxes``' value can be updated in three primary ways:
34+
1. Manually, through the ``TwinAxes.SetValue()`` method.
35+
2. Manually, by calling ``TwinAxes.AxisX.SetValue()`` or ``TwinAxes.AxisY.SetValue()``.
36+
3. By attaching an ``InputAction`` to the TwinAxes with ``TwinAxes.RegisterInputAction()``, or by specifying the ``InputAction`` upon instantiation. This causes the ``TwinAxes`` to subscribe to the ``performed`` and ``canceled`` events of said ``InputAction``, and removes the need to use manual methods listed above. The ``InputAction`` **MUST** have "Vector2" as its expected Control Type.
37+
### Reading TwinAxes values
38+
A ``TwinAxes`` whose value is reliably updated can be read from. A ``TwinAxes`` offers various ways of doing so:
39+
1. The ``Vector2`` property ``TwinAxes.Value`` returns the most recently set value of the ``TwinAxes``.
40+
2. The ``float`` property ``TwinAxes.Angle`` returns the angle of the ``TwinAxes``.
41+
3. The ``TwinAxes.AxisX`` and ``TwinAxes.AxisY`` properties allow for each ``Axis`` to be directly accessed as described above.
42+
4. The ``bool`` property ``TwinAxes.Neutral`` can be called on to evaluate the current ``TwinAxes`` value for conditional statements.
43+
5. The class exposes an event (``TwinAxes.OnValueChanged``), which can be subscribed to.

0 commit comments

Comments
 (0)