-
Notifications
You must be signed in to change notification settings - Fork 2
/
controller-feedback-fix.diff
74 lines (71 loc) · 3.37 KB
/
controller-feedback-fix.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
diff --git a/Assets/MagicLeap/Examples/Scripts/ControllerFeedbackExample.cs b/Assets/MagicLeap/Examples/Scripts/ControllerFeedbackExample.cs
index 1c71783..b3af4b7 100755
--- a/Assets/MagicLeap/Examples/Scripts/ControllerFeedbackExample.cs
+++ b/Assets/MagicLeap/Examples/Scripts/ControllerFeedbackExample.cs
@@ -49,8 +49,16 @@ namespace MagicLeap
{
_controllerConnectionHandler = GetComponent<ControllerConnectionHandler>();
+ if (!_controllerConnectionHandler.enabled)
+ {
+ Debug.LogWarning("Error ControllerFeedbackExample starting MLInput, disabling script.");
+ enabled = false;
+ return;
+ }
+
MLInput.OnControllerButtonUp += HandleOnButtonUp;
MLInput.OnControllerButtonDown += HandleOnButtonDown;
+ MLInput.OnTriggerUp += HandleOnTriggerUp;
MLInput.OnTriggerDown += HandleOnTriggerDown;
}
@@ -69,9 +77,10 @@ namespace MagicLeap
{
if (MLInput.IsStarted)
{
- MLInput.OnTriggerDown -= HandleOnTriggerDown;
MLInput.OnControllerButtonDown -= HandleOnButtonDown;
MLInput.OnControllerButtonUp -= HandleOnButtonUp;
+ MLInput.OnTriggerUp -= HandleOnTriggerUp;
+ MLInput.OnTriggerDown -= HandleOnTriggerDown;
}
}
#endregion
@@ -118,6 +127,14 @@ namespace MagicLeap
}
#endregion
+ public void Buzz()
+ {
+ if (_controllerConnectionHandler == null) return;
+ MLInputController controller = _controllerConnectionHandler.ConnectedController;
+ if (controller == null) return;
+ controller.StartFeedbackPatternVibe(MLInputControllerFeedbackPatternVibe.ForceDwell, MLInputControllerFeedbackIntensity.Medium);
+ }
+
#region Event Handlers
/// <summary>
/// Handles the event for button down.
@@ -163,8 +180,23 @@ namespace MagicLeap
MLInputController controller = _controllerConnectionHandler.ConnectedController;
if (controller != null && controller.Id == controllerId)
{
- MLInputControllerFeedbackIntensity intensity = (MLInputControllerFeedbackIntensity)((int)(value * 2.0f));
- controller.StartFeedbackPatternVibe(MLInputControllerFeedbackPatternVibe.Buzz, intensity);
+ // NOTE: Hardcoded to 0.1 since there was a bug that would make the controller vibrate max when
+ // trigger > 0.8 but < 1.0
+ MLInputControllerFeedbackIntensity intensity = (MLInputControllerFeedbackIntensity) 0.1f;
+// controller.StartFeedbackPatternVibe(MLInputControllerFeedbackPatternVibe.Buzz, intensity);
+ }
+ }
+
+ /// <summary>
+ /// Handles the event for trigger up.
+ /// </summary>
+ /// <param name="controller_id">The id of the controller.</param>
+ /// <param name="value">The value of the trigger button.</param>
+ private void HandleOnTriggerUp(byte controllerId, float value)
+ {
+ MLInputController controller = _controllerConnectionHandler.ConnectedController;
+ if (controller != null && controller.Id == controllerId) {
+ controller.StopFeedbackPatternVibe();
}
}
#endregion