Skip to content

Commit b854395

Browse files
committed
Additional work on on screen controls including UI visualisation
1 parent 07161d9 commit b854395

19 files changed

+1605
-222
lines changed

Assets/Samples/RebindingUI/InputActionIndicator.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ public class InputActionIndicator : MonoBehaviour
3434
private void OnEnable()
3535
{
3636
if (action != null && action.action != null)
37+
{
3738
action.action.performed += OnPerformed; // TODO Problem here after domain reload, InputAction.addperformed(), CallbackArray.AddCallback,. InputArrayExtensions.Contains
39+
}
3840
}
3941

4042
private void OnDisable()

Assets/Samples/RebindingUI/OnScreen/ActiveDetector.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
namespace UnityEngine.InputSystem.Samples.RebindUI
44
{
5-
class ActiveDetector : ITouchProcessor
5+
internal class ActiveDetector : ITouchProcessor
66
{
77
private Vector2 m_InitialPosition = Vector2.zero;
88
private double m_InitialTime = 0;
99
private bool m_Valid = true;
1010

11-
public void OnTouchBegin(ChangeMonitor context, in TouchState[] touches, int count, int index)
11+
public void OnTouchBegin(Detector context, in TouchState[] touches, int count, int index)
1212
{
1313
if (count == 1)
1414
{
@@ -19,7 +19,7 @@ public void OnTouchBegin(ChangeMonitor context, in TouchState[] touches, int cou
1919
GestureEvent @event = new GestureEvent(
2020
delta: Vector2.zero,
2121
duration: 0.0,
22-
flags: GestureFlags.Active | GestureFlags.PhaseStart,
22+
flags: GestureEvent.Flags.Active | GestureEvent.Flags.PhaseStart,
2323
start: m_InitialPosition
2424
);
2525
context.FireEvent(in @event);
@@ -30,33 +30,33 @@ public void OnTouchBegin(ChangeMonitor context, in TouchState[] touches, int cou
3030
}
3131
}
3232

33-
public void OnTouchEnd(ChangeMonitor context, in TouchState[] touches, int count, int index)
33+
public void OnTouchEnd(Detector context, in TouchState[] touches, int count, int index)
3434
{
3535
if (m_Valid)
3636
{
3737
GestureEvent @event = new GestureEvent(
3838
delta: touches[index].position - m_InitialPosition,
3939
duration: Time.realtimeSinceStartupAsDouble - m_InitialTime,
40-
flags: GestureFlags.Active | GestureFlags.PhaseEnd, start: m_InitialPosition);
40+
flags: GestureEvent.Flags.Active | GestureEvent.Flags.PhaseEnd, start: m_InitialPosition);
4141
context.FireEvent(in @event);
4242
}
4343
}
4444

45-
public void OnTouchMoved(ChangeMonitor context, in TouchState[] touches, int count, int index)
45+
public void OnTouchMoved(Detector context, in TouchState[] touches, int count, int index)
4646
{
4747
// Ignored
4848
}
4949

50-
public void OnTouchCanceled(ChangeMonitor context, in TouchState[] touches, int count, int index)
50+
public void OnTouchCanceled(Detector context, in TouchState[] touches, int count, int index)
5151
{
5252
if (m_Valid)
5353
{
5454
m_Valid = false;
5555

56-
GestureEvent @event = new GestureEvent(
56+
var @event = new GestureEvent(
5757
delta: touches[index].position - m_InitialPosition,
5858
duration: Time.realtimeSinceStartupAsDouble - m_InitialTime,
59-
flags: GestureFlags.Active | GestureFlags.PhaseCancel,
59+
flags: GestureEvent.Flags.Active | GestureEvent.Flags.PhaseCancel,
6060
start: m_InitialPosition);
6161
context.FireEvent(in @event);
6262
}

Assets/Samples/RebindingUI/OnScreen/Curve.cs

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,49 @@
22

33
namespace UnityEngine.InputSystem.Samples.RebindUI
44
{
5-
public enum PredefinedCurve
5+
/// <summary>
6+
/// Represents a response curve for mapping normalized values onto the normalized value axis.
7+
/// </summary>
8+
public enum Curve
69
{
10+
/// <summary>
11+
/// Linear curve f(x) = x.
12+
/// </summary>
713
Linear,
8-
Quatratic,
14+
15+
/// <summary>
16+
/// Quadratic curve f(x) = x^2.
17+
/// </summary>
18+
Quadratic,
19+
20+
/// <summary>
21+
/// Cubic curve f(x) = x^3.
22+
/// </summary>
923
Cubic,
1024
}
1125

12-
public static class CurveExtensions
26+
/// <summary>
27+
/// Extension methods for <see cref="Curve"/>.
28+
/// </summary>
29+
internal static class CurveExtensions
1330
{
1431
/// <summary>
1532
/// Apply response curve shaping to vlaue <paramref name="v"/>.
1633
/// </summary>
17-
/// <param name="v">The normalized value to be transformed.</param>
1834
/// <param name="curve">The response curve.</param>
35+
/// <param name="v">The normalized value to be transformed.</param>
1936
/// <returns>Transformed normalized value.</returns>
2037
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="curve"/> is outside valid range.</exception>
21-
public static float Transform(float x, PredefinedCurve curve)
38+
public static float Transform(this Curve curve, float v)
2239
{
2340
switch (curve)
2441
{
25-
case PredefinedCurve.Linear:
26-
return x;
27-
case PredefinedCurve.Quatratic:
28-
return x * x;
29-
case PredefinedCurve.Cubic:
30-
return x * x * x;
42+
case Curve.Linear:
43+
return v;
44+
case Curve.Quadratic:
45+
return v * v;
46+
case Curve.Cubic:
47+
return v * v * v;
3148
default:
3249
throw new ArgumentOutOfRangeException(nameof(curve));
3350
}
@@ -38,12 +55,12 @@ public static float Transform(float x, PredefinedCurve curve)
3855
/// </summary>
3956
/// <remarks>The provided vector is first transformed to polar form, then the vector length is scaled
4057
/// before it is finally converted back to euclidean space.</remarks>
41-
/// <param name="v">A normalized Euclidean vector to be transformed.</param>
4258
/// <param name="curve">The response curve.</param>
59+
/// <param name="v">A normalized Euclidean vector to be transformed.</param>
4360
/// <returns>Transformed normalized Euclidean vector.</returns>
44-
public static Vector2 Transform(Vector2 v, PredefinedCurve curve)
61+
public static Vector2 Transform(this Curve curve, Vector2 v)
4562
{
46-
var r = Transform(v.magnitude, curve);
63+
var r = curve.Transform(v.magnitude);
4764
var theta = Mathf.Atan2(v.y, v.x);
4865
return new Vector2(r * Mathf.Cos(theta), r * Mathf.Sin(theta));
4966
}

0 commit comments

Comments
 (0)