You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* 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
This Unity package contains a series of classes that help with the storage and processing of (user) inputs.
3
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.
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.
5
5
## Button
6
6
The ``Button`` class stores pressed/released (``bool``) input values, and offers some specialised helper methods to interpret button presses/releases over time.
7
7
### Setting Button values
8
8
A ``Button``'s value can be updated in two primary ways:
9
9
1. Manually, through the ``Button.Press()``, ``Button.Release()``, or ``Button.Toggle()`` methods.
10
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
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``.
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()``.
15
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
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
17
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:
22
22
1. Manually, through the ``Axis.SetValue()`` method.
23
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
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.
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.
27
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()``.
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()``.
29
29
4. The ``Axis`` exposes events (``Axis.OnValueChanged``, ``Axis.OnPositive``, ``Axis.OnNeutral``, and ``Axis.OnNegative``), which can be subscribed to.
30
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.
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.
32
32
### 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:
34
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.
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.
37
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``.
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.
41
41
3. The ``TwinAxes.AxisX`` and ``TwinAxes.AxisY`` properties allow for each ``Axis`` to be directly accessed as described above.
42
42
4. The ``bool`` property ``TwinAxes.Neutral`` can be called on to evaluate the current ``TwinAxes`` value for conditional statements.
43
43
5. The class exposes an event (``TwinAxes.OnValueChanged``), which can be subscribed to.
0 commit comments