Skip to content

Commit de1ab14

Browse files
Teleport Cursor Fix
1 parent 4deb038 commit de1ab14

File tree

6 files changed

+29
-26
lines changed

6 files changed

+29
-26
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ MonoBehaviour:
267267
axisConstraint: 7
268268
cursorPrefab: {fileID: 1554777696564956, guid: ae2b3fffb00f464287cda86f49109b47,
269269
type: 2}
270+
disableCursorOnStart: 1
270271
raycastOrigin: {fileID: 0}
271272
activeHoldAction:
272273
id: 0

Assets/MixedRealityToolkit-SDK/Features/UX/Scripts/Cursors/BaseCursor.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,13 @@ public virtual void OnSourceDetected(SourceStateEventData eventData)
141141
if (eventData.InputSource.Pointers[i].PointerId == Pointer.PointerId)
142142
{
143143
visibleSourcesCount++;
144-
SetVisibility(true);
144+
145+
if (visibleSourcesCount == 1 &&
146+
InputSystem.GazeProvider.GazePointer.PointerId != Pointer.PointerId)
147+
{
148+
SetVisibility(isVisible);
149+
}
150+
145151
return;
146152
}
147153
}
@@ -173,10 +179,14 @@ public virtual void OnSourceLost(SourceStateEventData eventData)
173179
}
174180
}
175181

176-
if (visibleSourcesCount == 0)
182+
if (!IsSourceDetected)
177183
{
178184
IsPointerDown = false;
179-
SetVisibility(false);
185+
186+
if (InputSystem.GazeProvider.GazePointer.PointerId != Pointer.PointerId)
187+
{
188+
SetVisibility(false);
189+
}
180190
}
181191
}
182192

@@ -231,13 +241,6 @@ public virtual void OnPointerUp(MixedRealityPointerEventData eventData)
231241

232242
#region MonoBehaviour Implementation
233243

234-
private void Awake()
235-
{
236-
// Use the setter to update visibility of the cursor at startup based on user preferences
237-
IsVisible = isVisible;
238-
SetVisibility(isVisible);
239-
}
240-
241244
private void Update()
242245
{
243246
UpdateCursorState();

Assets/MixedRealityToolkit-SDK/Features/UX/Scripts/Cursors/TeleportCursor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ protected override void UpdateCursorTransform()
8383
if (Pointer == null)
8484
{
8585
Debug.LogError($"[TeleportCursor.{name}] No Pointer has been assigned!");
86+
SetVisibility(false);
8687
return;
8788
}
8889

@@ -93,6 +94,7 @@ protected override void UpdateCursorTransform()
9394
Debug.LogError(InputSystem.FocusProvider.IsPointerRegistered(Pointer)
9495
? $"{gameObject.name}: Unable to get focus details for {pointer.GetType().Name}!"
9596
: $"{pointer.GetType().Name} has not been registered!");
97+
SetVisibility(false);
9698
return;
9799
}
98100

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ public abstract class BaseControllerPointer : ControllerPoseSynchronizer, IMixed
3030
[SerializeField]
3131
private GameObject cursorPrefab = null;
3232

33+
[SerializeField]
34+
private bool disableCursorOnStart = false;
35+
3336
private GameObject cursorInstance = null;
3437

3538
[SerializeField]
@@ -73,7 +76,7 @@ public abstract class BaseControllerPointer : ControllerPoseSynchronizer, IMixed
7376
/// Set a new cursor for this <see cref="IMixedRealityPointer"/>
7477
/// </summary>
7578
/// <remarks>This <see cref="GameObject"/> must have a <see cref="IMixedRealityCursor"/> attached to it.</remarks>
76-
/// <param name="newCursor"></param>
79+
/// <param name="newCursor">The new cursor</param>
7780
public virtual void SetCursor(GameObject newCursor = null)
7881
{
7982
if (cursorInstance != null)
@@ -104,6 +107,11 @@ public virtual void SetCursor(GameObject newCursor = null)
104107
{
105108
BaseCursor.DefaultCursorDistance = PointerExtent;
106109
BaseCursor.Pointer = this;
110+
111+
if (disableCursorOnStart)
112+
{
113+
BaseCursor.SetVisibility(false);
114+
}
107115
}
108116
else
109117
{
@@ -118,7 +126,6 @@ protected override void OnEnable()
118126
{
119127
base.OnEnable();
120128
SetCursor();
121-
BaseCursor?.SetVisibility(true);
122129

123130
if (MixedRealityManager.IsInitialized && TeleportSystem != null && !lateRegisterTeleport)
124131
{

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,6 @@ protected Gradient GetLineGradient(TeleportSurfaceResult targetResult)
9797
}
9898
}
9999

100-
protected override void OnEnable()
101-
{
102-
base.OnEnable();
103-
BaseCursor?.SetVisibility(false);
104-
}
105-
106-
/// <inheritdoc />
107-
public override void SetCursor(GameObject newCursor = null)
108-
{
109-
base.SetCursor(newCursor);
110-
BaseCursor?.SetVisibility(false);
111-
}
112-
113100
#region IMixedRealityPointer Implementation
114101

115102
/// <inheritdoc />
@@ -180,7 +167,6 @@ public override void OnPostRaycast()
180167
// If we hit something
181168
if (Result.CurrentPointerTarget != null)
182169
{
183-
BaseCursor?.SetVisibility(true);
184170
// Check if it's in our valid layers
185171
if (((1 << Result.CurrentPointerTarget.layer) & ValidLayers.value) != 0)
186172
{
@@ -236,6 +222,7 @@ public override void OnPostRaycast()
236222

237223
// Clamp the end of the parabola to the result hit's point
238224
LineBase.LineEndClamp = LineBase.GetNormalizedLengthFromWorldLength(clearWorldLength, LineCastResolution);
225+
BaseCursor?.SetVisibility(TeleportSurfaceResult == TeleportSurfaceResult.Valid || TeleportSurfaceResult == TeleportSurfaceResult.HotSpot);
239226
}
240227
else
241228
{

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace Microsoft.MixedReality.Toolkit.SDK.Inspectors.UX.Pointers
1111
public class BaseControllerPointerInspector : ControllerPoseSynchronizerInspector
1212
{
1313
private SerializedProperty cursorPrefab;
14+
private SerializedProperty disableCursorOnStart;
1415
private SerializedProperty raycastOrigin;
1516
private SerializedProperty pointerExtent;
1617
private SerializedProperty activeHoldAction;
@@ -27,6 +28,7 @@ protected override void OnEnable()
2728
base.OnEnable();
2829

2930
cursorPrefab = serializedObject.FindProperty("cursorPrefab");
31+
disableCursorOnStart = serializedObject.FindProperty("disableCursorOnStart");
3032
raycastOrigin = serializedObject.FindProperty("raycastOrigin");
3133
pointerExtent = serializedObject.FindProperty("pointerExtent");
3234
activeHoldAction = serializedObject.FindProperty("activeHoldAction");
@@ -48,6 +50,7 @@ public override void OnInspectorGUI()
4850
if (basePointerFoldout)
4951
{
5052
EditorGUILayout.PropertyField(cursorPrefab);
53+
EditorGUILayout.PropertyField(disableCursorOnStart);
5154
EditorGUILayout.PropertyField(raycastOrigin);
5255
EditorGUILayout.PropertyField(pointerExtent);
5356
EditorGUILayout.PropertyField(pointerOrientation);

0 commit comments

Comments
 (0)