Skip to content

Commit 7b5f3ff

Browse files
committed
Tweaks
1 parent 41b4328 commit 7b5f3ff

4 files changed

Lines changed: 14 additions & 83 deletions

File tree

Runtime/Axis.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public class Axis
6868
/// Create a new <see cref="Axis"/>.
6969
/// </summary>
7070
public Axis()
71-
{ }
71+
{}
7272

7373
/// <summary>
7474
/// Create a new <see cref="Axis"/> and tie it to an <see cref="InputAction"/>.

Runtime/Button.cs

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,67 +19,31 @@ public class Button
1919
/// <returns>
2020
/// The amount of frames the <see cref="Button"/> has been pressed, and -1 if it is currently released.
2121
/// </returns>
22-
public int PressDurationFrames
23-
{
24-
get
25-
{
26-
if (set && Value && pressFrame >= releaseFrame)
27-
return Time.frameCount - pressFrame;
28-
else
29-
return -1;
30-
}
31-
}
22+
public int PressDurationFrames => set && Value && pressFrame >= releaseFrame ? Time.frameCount - pressFrame : -1;
3223

3324
/// <summary>
3425
/// How long the <see cref="Button"/> has been pressed, if it currently is.
3526
/// </summary>
3627
/// <returns>
3728
/// The amount of seconds the <see cref="Button"/> has been pressed, and -1f if it is currently released.
3829
/// </returns>
39-
public float PressDurationTime
40-
{
41-
get
42-
{
43-
if (set && Value && pressTime >= releaseTime)
44-
return Time.unscaledTime - pressTime;
45-
else
46-
return -1f;
47-
}
48-
}
30+
public float PressDurationTime => set && Value && pressTime >= releaseTime ? Time.unscaledTime - pressTime : -1f;
4931

5032
/// <summary>
5133
/// How long the <see cref="Button"/> has been released, if it currently is.
5234
/// </summary>
5335
/// <returns>
5436
/// The amount of frames the <see cref="Button"/> has been released, and -1 if it is currently pressed.
5537
/// </returns>
56-
public int ReleasedDurationFrames
57-
{
58-
get
59-
{
60-
if (set && !Value && releaseFrame >= pressFrame)
61-
return Time.frameCount - releaseFrame;
62-
else
63-
return -1;
64-
}
65-
}
38+
public int ReleasedDurationFrames => set && !Value && releaseFrame >= pressFrame ? Time.frameCount - releaseFrame : -1;
6639

6740
/// <summary>
6841
/// How long the <see cref="Button"/> has been released, if it currently is.
6942
/// </summary>
7043
/// <returns>
7144
/// The amount of seconds the <see cref="Button"/> has been released, and -1f if it is currently pressed.
7245
/// </returns>
73-
public float ReleasedDurationTime
74-
{
75-
get
76-
{
77-
if (set && !Value && releaseTime >= pressTime)
78-
return Time.unscaledTime - releaseTime;
79-
else
80-
return -1f;
81-
}
82-
}
46+
public float ReleasedDurationTime => set && !Value && releaseTime >= pressTime ? Time.unscaledTime - releaseTime : -1f;
8347

8448
/// <summary>
8549
/// Invoked when <see cref="Value"/> is set through either <see cref="Press"/>, <see cref="Release"/>, or <see cref="Toggle"/>.

Runtime/TwinAxes.cs

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class TwinAxes
1111
/// <summary>
1212
/// The value of the <see cref="TwinAxes"/> represented as a <see cref="Vector2"/>.
1313
/// </summary>
14-
public Vector2 Value { get; private set; } = Vector2.zero;
14+
public Vector2 Value => new Vector2(AxisX.Value, AxisY.Value);
1515

1616
/// <summary>
1717
/// The angle of <see cref="Value"/>, as compared to <see cref="Vector2.up"/>.
@@ -30,20 +30,15 @@ public class TwinAxes
3030

3131
/// <summary>
3232
/// True if the <see cref="Axis.Value"/> of <see cref="AxisX"/> and <see cref="AxisY"/> are both neutral (0f).
33-
/// <para>Will always be false if <see cref="SetValue(Vector2)"/> or <see cref="SetNeutral"/> have never been called.</para>
33+
/// <para>Will always be false if <see cref="SetValue(Vector2)"/> has never been called.</para>
3434
/// </summary>
35-
public bool Neutral { get { if (AxisX.Neutral && AxisY.Neutral) return true; else return false; } }
35+
public bool Neutral => AxisX.Neutral && AxisY.Neutral;
3636

3737
/// <summary>
38-
/// Invoked when <see cref="Value"/> is set through <see cref="SetValue(Vector2)"/> or <see cref="SetNeutral"/>.
38+
/// Invoked when <see cref="Value"/> is set through <see cref="SetValue(Vector2)"/>.
3939
/// </summary>
4040
public event System.Action<Vector2> OnValueChanged;
4141

42-
/// <summary>
43-
/// Invoked when the <see cref="Axis.Value"/> of <see cref="AxisX"/> or <see cref="AxisY"/> is set by something other than the <see cref="TwinAxes"/>.
44-
/// </summary>
45-
public event System.Action<Vector2> OnValueTampered;
46-
4742
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
4843

4944
private InputAction action;
@@ -54,10 +49,7 @@ public class TwinAxes
5449
/// Create a new <see cref="TwinAxes"/>.
5550
/// </summary>
5651
public TwinAxes()
57-
{
58-
AxisX.OnValueChanged += DirtyAxisUpdateX;
59-
AxisY.OnValueChanged += DirtyAxisUpdateY;
60-
}
52+
{}
6153

6254
/// <summary>
6355
/// Create a new <see cref="TwinAxes"/> and tie it to an <see cref="InputAction"/>.
@@ -69,8 +61,6 @@ public TwinAxes(InputAction action)
6961
throw new System.ArgumentNullException("action");
7062
if (action.expectedControlType != "Vector2")
7163
throw new System.ArgumentException("InputAction " + action.name + " does not have an expected Vector2 control type.");
72-
AxisX.OnValueChanged += DirtyAxisUpdateX;
73-
AxisY.OnValueChanged += DirtyAxisUpdateY;
7464
SetInputAction(action);
7565
}
7666

@@ -93,23 +83,12 @@ public TwinAxes(InputAction action)
9383
/// <param name="value">The value to set <see cref="Value"/> to.</param>
9484
public void SetValue(Vector2 value)
9585
{
96-
Value = value;
9786
// The Axes' update events are not invoked, because TwinAxes is the one setting their value.
98-
AxisX.SetValue(Value.x, false);
99-
AxisY.SetValue(Value.y, false);
87+
AxisX.SetValue(value.x, false);
88+
AxisY.SetValue(value.y, false);
10089
OnValueChanged?.Invoke(Value);
10190
}
10291

103-
/// <summary>
104-
/// Sets <see cref="Value"/> to <see cref="Vector2.zero"/>.
105-
/// <para>Both <see cref="Axis"/> of the <see cref="TwinAxes"/> log the <see cref="Time.frameCount"/> and <see cref="Time.unscaledTime"/>
106-
/// whenever <see cref="Value"/> is set.</para>
107-
/// </summary>
108-
public void SetNeutral()
109-
{
110-
SetValue(Vector2.zero);
111-
}
112-
11392
/// <summary>
11493
/// Tie the <see cref="TwinAxes"/> to an <see cref="InputAction"/>.
11594
/// </summary>
@@ -125,18 +104,6 @@ public void RegisterInputAction(InputAction action)
125104

126105
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
127106

128-
private void DirtyAxisUpdateX(float xValue)
129-
{
130-
Value = new Vector2(xValue, AxisY.Value);
131-
OnValueTampered?.Invoke(Value);
132-
}
133-
134-
private void DirtyAxisUpdateY(float yValue)
135-
{
136-
Value = new Vector2(AxisX.Value, yValue);
137-
OnValueTampered?.Invoke(Value);
138-
}
139-
140107
private void SetInputAction(InputAction action)
141108
{
142109
if (this.action != null)
@@ -156,7 +123,7 @@ private void ActionPerformed(InputAction.CallbackContext context)
156123

157124
private void ActionCanceled(InputAction.CallbackContext context)
158125
{
159-
SetNeutral();
126+
SetValue(Vector2.zero);
160127
}
161128
}
162129
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.stephanhooft.input-processing",
3-
"version": "1.2.3",
3+
"version": "1.3.0",
44
"displayName": "Input Processing",
55
"description": "A package that contains helper classes to store and evaluate user input.",
66
"unity": "2020.3",

0 commit comments

Comments
 (0)