Skip to content

Commit eda4221

Browse files
Fixed mouse resetting after timer wind down even though it was still enabled.
Made sure that disabling the "Hide Cursor when active" flag didn't hide it after timer winddown Consolidated some duplicated code. Updated inspector.
1 parent af4cfcf commit eda4221

File tree

6 files changed

+102
-76
lines changed

6 files changed

+102
-76
lines changed

Assets/MixedRealityToolkit-SDK/Features/UX/Prefabs/Pointers/MousePointer.prefab

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ MonoBehaviour:
5555
destroyOnSourceLost: 0
5656
useSourcePoseData: 1
5757
poseAction:
58-
id: 0
59-
description: None
60-
axisConstraint: 0
58+
id: 12
59+
description: Mouse Delta
60+
axisConstraint: 4
6161
cursorPrefab: {fileID: 1151083198953756, guid: 667821d88830305449757690d22f71e0,
6262
type: 2}
6363
disableCursorOnStart: 1

Assets/MixedRealityToolkit-SDK/Features/UX/Scripts/Pointers/BaseControllerPointer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public abstract class BaseControllerPointer : ControllerPoseSynchronizer, IMixed
3030
[SerializeField]
3131
private bool disableCursorOnStart = false;
3232

33+
protected bool DisableCursorOnStart => disableCursorOnStart;
34+
3335
[SerializeField]
3436
private bool setCursorVisibilityOnSourceDetected = false;
3537

Assets/MixedRealityToolkit-SDK/Features/UX/Scripts/Pointers/MousePointer.cs

Lines changed: 91 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,42 @@ namespace Microsoft.MixedReality.Toolkit.SDK.UX.Pointers
1717
/// </summary>
1818
public class MousePointer : BaseControllerPointer, IMixedRealityMousePointer
1919
{
20+
private float timeoutTimer = 0.0f;
21+
22+
private bool isInteractionEnabled = false;
23+
24+
private bool cursorWasDisabledOnDown = false;
25+
26+
private bool isDisabled = true;
27+
28+
#region IMixedRealityMousePointer Implementaiton
29+
2030
[SerializeField]
2131
[Tooltip("Should the mouse cursor be hidden when no active input is received?")]
2232
private bool hideCursorWhenInactive = true;
2333

2434
/// <inheritdoc />
25-
public bool HideCursorWhenInactive => hideCursorWhenInactive;
35+
bool IMixedRealityMousePointer.HideCursorWhenInactive => hideCursorWhenInactive;
2636

2737
[SerializeField]
2838
[Range(0.01f, 1f)]
2939
[Tooltip("What is the movement threshold to reach before un-hiding mouse cursor?")]
3040
private float movementThresholdToUnHide = 0.1f;
3141

3242
/// <inheritdoc />
33-
public float MovementThresholdToUnHide => movementThresholdToUnHide;
43+
float IMixedRealityMousePointer.MovementThresholdToUnHide => movementThresholdToUnHide;
3444

3545
[SerializeField]
3646
[Range(0f, 10f)]
3747
[Tooltip("How long should it take before the mouse cursor is hidden?")]
3848
private float hideTimeout = 3.0f;
3949

4050
/// <inheritdoc />
41-
public float HideTimeout => hideTimeout;
51+
float IMixedRealityMousePointer.HideTimeout => hideTimeout;
4252

43-
private float timeoutTimer;
53+
#endregion IMixedRealityMousePointer Implementation
4454

45-
private bool isInteractionEnabled = false;
46-
47-
private bool cursorWasDisabledOnDown = false;
55+
#region IMixedRealityPointer Implementaiton
4856

4957
/// <inheritdoc />
5058
public override bool IsInteractionEnabled => isInteractionEnabled;
@@ -82,61 +90,57 @@ public override void OnPreRaycast()
8290
}
8391
}
8492

85-
public override void OnSourcePoseChanged(SourcePoseEventData<Vector2> eventData)
93+
#endregion IMixedRealityPointer Implementaiton
94+
95+
#region IMixedRealitySourcePoseHandler Implementaiton
96+
97+
/// <inheritdoc />
98+
public override void OnSourceDetected(SourceStateEventData eventData)
8699
{
87-
if (Controller == null ||
88-
eventData.Controller == null ||
89-
eventData.Controller.InputSource.SourceId != Controller.InputSource.SourceId)
100+
if (RayStabilizer != null)
90101
{
91-
return;
102+
RayStabilizer = null;
92103
}
93104

94-
if (UseSourcePoseData)
95-
{
96-
if (BaseCursor != null &&
97-
!BaseCursor.IsVisible &&
98-
(eventData.SourceData.x >= movementThresholdToUnHide ||
99-
eventData.SourceData.y >= MovementThresholdToUnHide))
100-
{
101-
BaseCursor.SetVisibility(true);
102-
transform.rotation = CameraCache.Main.transform.rotation;
103-
}
105+
base.OnSourceDetected(eventData);
104106

105-
var newRotation = Vector3.zero;
106-
newRotation.x += eventData.SourceData.y;
107-
newRotation.y += eventData.SourceData.x;
108-
transform.Rotate(newRotation, Space.World);
107+
if (eventData.SourceId == Controller?.InputSource.SourceId)
108+
{
109+
isInteractionEnabled = true;
109110
}
110111
}
111112

112113
/// <inheritdoc />
113-
public override void OnPositionInputChanged(InputEventData<Vector2> eventData)
114+
public override void OnSourceLost(SourceStateEventData eventData)
114115
{
116+
base.OnSourceLost(eventData);
117+
115118
if (eventData.SourceId == Controller?.InputSource.SourceId)
116119
{
117-
if (!UseSourcePoseData &&
118-
PoseAction == eventData.MixedRealityInputAction)
119-
{
120-
if (BaseCursor != null &&
121-
!BaseCursor.IsVisible &&
122-
(eventData.InputData.x >= movementThresholdToUnHide ||
123-
eventData.InputData.y >= MovementThresholdToUnHide))
124-
{
125-
BaseCursor.SetVisibility(true);
126-
transform.rotation = CameraCache.Main.transform.rotation;
127-
}
128-
129-
IsTracked = true;
130-
TrackingState = TrackingState.Tracked;
131-
132-
var newRotation = Vector3.zero;
133-
newRotation.x += eventData.InputData.x;
134-
newRotation.y += eventData.InputData.y;
135-
transform.Rotate(newRotation, Space.World);
136-
}
120+
isInteractionEnabled = false;
137121
}
138122
}
139123

124+
/// <inheritdoc />
125+
public override void OnSourcePoseChanged(SourcePoseEventData<Vector2> eventData)
126+
{
127+
if (Controller == null ||
128+
eventData.Controller == null ||
129+
eventData.Controller.InputSource.SourceId != Controller.InputSource.SourceId)
130+
{
131+
return;
132+
}
133+
134+
if (UseSourcePoseData)
135+
{
136+
UpdateMousePosition(eventData.SourceData.x, eventData.SourceData.y);
137+
}
138+
}
139+
140+
#endregion IMixedRealitySourcePoseHandler Implementaiton
141+
142+
#region IMixedRealityInputHandler Implementaiton
143+
140144
/// <inheritdoc />
141145
public override void OnInputDown(InputEventData eventData)
142146
{
@@ -162,8 +166,27 @@ public override void OnInputUp(InputEventData eventData)
162166
}
163167
}
164168

169+
/// <inheritdoc />
170+
public override void OnPositionInputChanged(InputEventData<Vector2> eventData)
171+
{
172+
if (eventData.SourceId == Controller?.InputSource.SourceId)
173+
{
174+
if (!UseSourcePoseData &&
175+
PoseAction == eventData.MixedRealityInputAction)
176+
{
177+
UpdateMousePosition(eventData.InputData.x, eventData.InputData.y);
178+
}
179+
}
180+
}
181+
182+
#endregion IMixedRealityInputHandler Implementaiton
183+
184+
#region Monobehaviour Implementaiton
185+
165186
protected override void Start()
166187
{
188+
isDisabled = DisableCursorOnStart;
189+
167190
base.Start();
168191

169192
if (RayStabilizer != null)
@@ -183,42 +206,42 @@ protected override void Start()
183206

184207
private void Update()
185208
{
186-
if (!isInteractionEnabled) { return; }
209+
if (!hideCursorWhenInactive || isDisabled) { return; }
187210

188211
timeoutTimer += Time.unscaledDeltaTime;
189212

190213
if (timeoutTimer >= hideTimeout)
191214
{
192215
timeoutTimer = 0.0f;
193216
BaseCursor?.SetVisibility(false);
217+
isDisabled = true;
194218
}
195219
}
196220

197-
/// <inheritdoc />
198-
public override void OnSourceDetected(SourceStateEventData eventData)
221+
#endregion Monobehaviour Implementaiton
222+
223+
private void UpdateMousePosition(float mouseX, float mouseY)
199224
{
200-
if (RayStabilizer != null)
225+
if (Mathf.Abs(mouseX) >= movementThresholdToUnHide ||
226+
Mathf.Abs(mouseY) >= movementThresholdToUnHide)
201227
{
202-
RayStabilizer = null;
203-
}
204-
205-
base.OnSourceDetected(eventData);
228+
if (isDisabled)
229+
{
230+
BaseCursor?.SetVisibility(true);
231+
transform.rotation = CameraCache.Main.transform.rotation;
232+
}
233+
else
234+
{
235+
timeoutTimer = 0.0f;
236+
}
206237

207-
if (eventData.SourceId == Controller?.InputSource.SourceId)
208-
{
209-
isInteractionEnabled = true;
238+
isDisabled = false;
210239
}
211-
}
212-
213-
/// <inheritdoc />
214-
public override void OnSourceLost(SourceStateEventData eventData)
215-
{
216-
base.OnSourceLost(eventData);
217240

218-
if (eventData.SourceId == Controller?.InputSource.SourceId)
219-
{
220-
isInteractionEnabled = false;
221-
}
241+
var newRotation = Vector3.zero;
242+
newRotation.x += mouseX;
243+
newRotation.y += mouseY;
244+
transform.Rotate(newRotation, Space.World);
222245
}
223246
}
224247
}

Assets/MixedRealityToolkit-SDK/Features/UX/Scripts/Utilities/HoverLight.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ private void AddHoverLight(HoverLight light)
9191
{
9292
if (activeHoverLights.Count >= hoverLightCount)
9393
{
94-
Debug.LogWarningFormat("Max hover light count ({0}) exceeded.", hoverLightCount);
94+
Debug.LogWarning($"Max hover light count ({hoverLightCount}) exceeded.");
95+
return;
9596
}
9697

9798
activeHoverLights.Add(light);

Assets/MixedRealityToolkit-SDK/Inspectors/UX/Pointers/MousePointerInspector.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ namespace Microsoft.MixedReality.Toolkit.SDK.Inspectors.UX.Pointers
1010
public class MousePointerInspector : BaseControllerPointerInspector
1111
{
1212
private SerializedProperty hideCursorWhenInactive;
13-
private SerializedProperty movementThresholdToUnHide;
1413
private SerializedProperty hideTimeout;
14+
private SerializedProperty movementThresholdToUnHide;
1515
private bool mousePointerFoldout = true;
1616

1717
protected override void OnEnable()
@@ -38,8 +38,8 @@ public override void OnInspectorGUI()
3838

3939
if (hideCursorWhenInactive.boolValue)
4040
{
41-
EditorGUILayout.PropertyField(movementThresholdToUnHide);
4241
EditorGUILayout.PropertyField(hideTimeout);
42+
EditorGUILayout.PropertyField(movementThresholdToUnHide);
4343
}
4444

4545
EditorGUI.indentLevel--;

Assets/MixedRealityToolkit/_Core/Devices/UnityInput/MouseController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public void Update()
7474
}
7575

7676
// Don't ask me why it's mapped weird. Bc Unity...
77-
mouseDelta.x = Input.GetAxis("Mouse X");
78-
mouseDelta.y = -Input.GetAxis("Mouse Y");
77+
mouseDelta.x = -Input.GetAxis("Mouse Y");
78+
mouseDelta.y = Input.GetAxis("Mouse X");
7979
MixedRealityToolkit.InputSystem?.RaiseSourcePositionChanged(InputSource, this, mouseDelta);
8080
MixedRealityToolkit.InputSystem?.RaiseSourcePoseChanged(InputSource, this, controllerPose);
8181
MixedRealityToolkit.InputSystem?.RaiseSourcePositionChanged(InputSource, this, Input.mouseScrollDelta);

0 commit comments

Comments
 (0)