@@ -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}
0 commit comments