Skip to content

Commit d4327f2

Browse files
committed
v2.0.0
* Axis, TwinAxes and Button now have implicit conversions to float, Vector2, and bool * TwinAxes now has a custom angle comparison method * TwinAxes now uses a custom Axis class that only the TwinAxes may set * Axis has new evaluation methods * Reviewed XLM documentation * Coding style review
1 parent 27c208d commit d4327f2

File tree

5 files changed

+1049
-416
lines changed

5 files changed

+1049
-416
lines changed

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# input-processing
22
This Unity package contains a series of classes that help with the storage and processing of (user) inputs.
33

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.
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. The classes in this package act as intermediary data structures to evaluate inputs over a longer range of time.
55
## Button
66
The ``Button`` class stores pressed/released (``bool``) input values, and offers some specialised helper methods to interpret button presses/releases over time.
77
### Setting Button values
88
A ``Button``'s value can be updated in two primary ways:
99
1. Manually, through the ``Button.Press()``, ``Button.Release()``, or ``Button.Toggle()`` methods.
1010
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.
1111
### 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``.
12+
A ``Button`` whose value is reliably updated can be read from. A ``Button`` offers various ways of doing so. These include:
13+
1. The ``bool`` property ``Button.Value`` returns the most recently set value of the ``Button``. A ``Button`` can also be implicitly converted to a ``bool`` value.
14+
2. How long a ``Button`` has been pressed or released in frames (``int``) or seconds (``float``) is returned by methods such as ``Button.GetPressDurationFrames()``, ``Button.GetPressDurationSeconds()``, ``Button.GetReleaseDurationFrames()``, and ``Button.GetReleaseDurationSeconds()``.
1515
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.
1616
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.
1717
5. The ``Button`` exposes events (``Button.OnValueChanged``, ``Button.OnPressed``, and ``Button.OnReleased``), which can be subscribed to.
@@ -22,22 +22,22 @@ An ``Axis``' value can be updated in two primary ways:
2222
1. Manually, through the ``Axis.SetValue()`` method.
2323
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.
2424
### 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.
25+
An ``Axis`` whose value is reliably updated can be read from. An ``Axis`` offers various ways of doing so. These include:
26+
1. The ``float`` property ``Axis.Value`` returns the most recently set value of the Axis. An ``Axis`` can also be implicitly converted to a ``float`` value.
2727
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()``.
28+
3. How long an ``Axis`` has been positive (> 0f), neutral (== 0f), or negative (< 0f) can be returned in frames (``int``) or seconds (``float``) using methods such as ``Axis.GetPositiveDurationFrames()``, ``Axis.GetPositiveDurationSeconds()``, ``Axis.GetNeutralDurationFrames()``, ``Axis.GetNeutralDurationSeconds()``, ``Axis.GetNegativeDurationFrames()``, and ``Axis.GetNegativeDurationSeconds()``.
2929
4. The ``Axis`` exposes events (``Axis.OnValueChanged``, ``Axis.OnPositive``, ``Axis.OnNeutral``, and ``Axis.OnNegative``), which can be subscribed to.
3030
## 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.
31+
The ``TwinAxes`` class stores a pair (``Vector2``) of ``TwinAxes.Axis`` instances, making it highly recommended for joy-/control-sticks. It has some dedicated methods to easily manage and read both ``TwinAxes.Axis`` at once.
3232
### Setting TwinAxes values
33-
A ``TwinAxes``' value can be updated in three primary ways:
33+
A ``TwinAxes``' value can be updated in two primary ways:
3434
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.
35+
2. 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.
36+
Directly setting the value of one ``TwinAxes.Axis`` is not permitted.
3737
### 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``.
38+
A ``TwinAxes`` whose value is reliably updated can be read from. A ``TwinAxes`` offers various ways of doing so. These include:
39+
1. The ``Vector2`` property ``TwinAxes.Value`` returns the most recently set value of the ``TwinAxes``. A ``TwinAxes`` can also be implicitly converted to a ``Vector2`` value.
40+
2. The ``TwinAxes.Angle()`` method returns the angle of the ``TwinAxes`` compared to another ``Vector2`` value.
4141
3. The ``TwinAxes.AxisX`` and ``TwinAxes.AxisY`` properties allow for each ``Axis`` to be directly accessed as described above.
4242
4. The ``bool`` property ``TwinAxes.Neutral`` can be called on to evaluate the current ``TwinAxes`` value for conditional statements.
4343
5. The class exposes an event (``TwinAxes.OnValueChanged``), which can be subscribed to.

0 commit comments

Comments
 (0)