Skip to content

Commit e4e8ea6

Browse files
Merge pull request #29 from keveleigh/CursorVisibilityFix
Update cursor visibility based on source detection
2 parents 6a5bd5d + ff290e6 commit e4e8ea6

File tree

6 files changed

+17
-4
lines changed

6 files changed

+17
-4
lines changed

Assets/MixedRealityToolkit-SDK/Features/Input/GazeProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ protected override void Start()
278278
var cursorObj = Instantiate(cursorPrefab, transform.parent);
279279
GazePointer.BaseCursor = cursorObj.GetComponent<IMixedRealityCursor>();
280280
Debug.Assert(GazePointer.BaseCursor != null, "Failed to load cursor");
281+
GazePointer.BaseCursor.SetVisibilityOnSourceDetected = false;
281282
GazePointer.BaseCursor.Pointer = GazePointer;
282283
}
283284

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ MonoBehaviour:
104104
axisConstraint: 0
105105
cursorPrefab: {fileID: 1000012072213228, guid: 5b3e2856904e43c680f84f326861032a,
106106
type: 2}
107+
disableCursorOnStart: 1
108+
setCursorVisibilityOnSourceDetected: 1
107109
raycastOrigin: {fileID: 0}
108110
activeHoldAction:
109111
id: 0

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public class BaseCursor : InputSystemGlobalListener, IMixedRealityCursor
1818
{
1919
public CursorStateEnum CursorState { get; private set; } = CursorStateEnum.None;
2020

21+
public bool SetVisibilityOnSourceDetected { get; set; } = false;
22+
2123
/// <summary>
2224
/// Surface distance to place the cursor off of the surface at
2325
/// </summary>
@@ -130,10 +132,9 @@ public virtual void OnSourceDetected(SourceStateEventData eventData)
130132
{
131133
visibleSourcesCount++;
132134

133-
if (visibleSourcesCount == 1 &&
134-
InputSystem.GazeProvider.GazePointer.PointerId != Pointer.PointerId)
135+
if (SetVisibilityOnSourceDetected && visibleSourcesCount == 1)
135136
{
136-
SetVisibility(isVisible);
137+
SetVisibility(true);
137138
}
138139

139140
return;
@@ -171,7 +172,7 @@ public virtual void OnSourceLost(SourceStateEventData eventData)
171172
{
172173
IsPointerDown = false;
173174

174-
if (InputSystem.GazeProvider.GazePointer.PointerId != Pointer.PointerId)
175+
if (SetVisibilityOnSourceDetected)
175176
{
176177
SetVisibility(false);
177178
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public abstract class BaseControllerPointer : ControllerPoseSynchronizer, IMixed
3333
[SerializeField]
3434
private bool disableCursorOnStart = false;
3535

36+
[SerializeField]
37+
private bool setCursorVisibilityOnSourceDetected = false;
38+
3639
private GameObject cursorInstance = null;
3740

3841
[SerializeField]
@@ -107,6 +110,7 @@ public virtual void SetCursor(GameObject newCursor = null)
107110
{
108111
BaseCursor.DefaultCursorDistance = PointerExtent;
109112
BaseCursor.Pointer = this;
113+
BaseCursor.SetVisibilityOnSourceDetected = setCursorVisibilityOnSourceDetected;
110114

111115
if (disableCursorOnStart)
112116
{

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class BaseControllerPointerInspector : ControllerPoseSynchronizerInspecto
1212
{
1313
private SerializedProperty cursorPrefab;
1414
private SerializedProperty disableCursorOnStart;
15+
private SerializedProperty setCursorVisibilityOnSourceDetected;
1516
private SerializedProperty raycastOrigin;
1617
private SerializedProperty pointerExtent;
1718
private SerializedProperty activeHoldAction;
@@ -29,6 +30,7 @@ protected override void OnEnable()
2930

3031
cursorPrefab = serializedObject.FindProperty("cursorPrefab");
3132
disableCursorOnStart = serializedObject.FindProperty("disableCursorOnStart");
33+
setCursorVisibilityOnSourceDetected = serializedObject.FindProperty("setCursorVisibilityOnSourceDetected");
3234
raycastOrigin = serializedObject.FindProperty("raycastOrigin");
3335
pointerExtent = serializedObject.FindProperty("pointerExtent");
3436
activeHoldAction = serializedObject.FindProperty("activeHoldAction");
@@ -51,6 +53,7 @@ public override void OnInspectorGUI()
5153
{
5254
EditorGUILayout.PropertyField(cursorPrefab);
5355
EditorGUILayout.PropertyField(disableCursorOnStart);
56+
EditorGUILayout.PropertyField(setCursorVisibilityOnSourceDetected);
5457
EditorGUILayout.PropertyField(raycastOrigin);
5558
EditorGUILayout.PropertyField(pointerExtent);
5659
EditorGUILayout.PropertyField(pointerOrientation);

Assets/MixedRealityToolkit/_Core/Interfaces/InputSystem/IMixedRealityCursor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public interface IMixedRealityCursor : IMixedRealityFocusChangedHandler, IMixedR
4242
/// <param name="visible">True if cursor should be visible, false if not.</param>
4343
void SetVisibility(bool visible);
4444

45+
bool SetVisibilityOnSourceDetected { get; set; }
46+
4547
/// <summary>
4648
/// Returns the <see cref="IMixedRealityCursor"/>'s <see cref="GameObject"/> reference.
4749
/// </summary>

0 commit comments

Comments
 (0)