Skip to content

Commit c8e5efd

Browse files
committed
Update pointer visualizer to set default cursor distance
Fixes #2166.
1 parent e69be7f commit c8e5efd

File tree

6 files changed

+37
-17
lines changed

6 files changed

+37
-17
lines changed

Assets/HoloToolkit/Input/Prefabs/LinearControllerPointer.prefab

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ MonoBehaviour:
6262
ScaleOffset: {x: 1, y: 1, z: 1}
6363
SetScaleOnAttach: 0
6464
CurrentPointerOrientation: 0
65-
extentOverride: 2
6665
RaycastOrigin: {fileID: 0}
6766
LineColorSelected:
6867
serializedVersion: 2

Assets/HoloToolkit/Input/Scripts/Cursor/Cursor.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,19 @@ public abstract class Cursor : MonoBehaviour, ICursor
2020
/// <summary>
2121
/// The pointer that this cursor should follow and process input from.
2222
/// </summary>
23-
public IPointingSource Pointer { get; set; }
23+
public IPointingSource Pointer
24+
{
25+
get { return pointer; }
26+
set
27+
{
28+
pointerIsInputSourcePointer = value is InputSourcePointer;
29+
pointer = value;
30+
}
31+
}
32+
33+
private IPointingSource pointer;
34+
35+
private bool pointerIsInputSourcePointer = false;
2436

2537
/// <summary>
2638
/// Minimum distance for cursor if nothing is hit
@@ -110,6 +122,8 @@ public Vector3 LocalScale
110122
private Vector3 targetScale;
111123
private Quaternion targetRotation;
112124

125+
private float originalDefaultCursorDistance;
126+
113127
/// <summary>
114128
/// Indicates if the cursor should be visible
115129
/// </summary>
@@ -126,6 +140,8 @@ public bool IsVisible
126140

127141
private void Awake()
128142
{
143+
originalDefaultCursorDistance = DefaultCursorDistance;
144+
129145
// Use the setter to update visibility of the cursor at startup based on user preferences
130146
IsVisible = isVisible;
131147
SetVisibility(isVisible);
@@ -298,6 +314,21 @@ protected virtual void UpdateCursorTransform()
298314
TargetedObject = null;
299315
TargetedCursorModifier = null;
300316

317+
if (pointerIsInputSourcePointer)
318+
{
319+
// This value get re-queried every update, in case the app has
320+
// changed the pointing extent of the pointer for the current scenario.
321+
float distance = FocusManager.Instance.GetPointingExtent(Pointer);
322+
if (DefaultCursorDistance != distance)
323+
{
324+
DefaultCursorDistance = distance;
325+
}
326+
}
327+
else if (DefaultCursorDistance != originalDefaultCursorDistance)
328+
{
329+
DefaultCursorDistance = originalDefaultCursorDistance;
330+
}
331+
301332
targetPosition = RayStep.GetPointByDistance(Pointer.Rays, DefaultCursorDistance);
302333
lookForward = -RayStep.GetDirectionByDistance(Pointer.Rays, DefaultCursorDistance);
303334
targetRotation = lookForward.magnitude > 0 ? Quaternion.LookRotation(lookForward, Vector3.up) : transform.rotation;

Assets/HoloToolkit/Input/Scripts/Focus/InputSourcePointer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public virtual void OnPostRaycast()
129129
{
130130
if (PointerRay != null)
131131
{
132-
PointerRay.UpdateRenderedLine(rays, Result, selectPressed);
132+
PointerRay.UpdateRenderedLine(rays, Result, selectPressed, FocusManager.Instance.GetPointingExtent(this));
133133
}
134134
}
135135

Assets/HoloToolkit/Input/Scripts/Focus/SimpleSinglePointerSelector.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ public class SimpleSinglePointerSelector : MonoBehaviour, ISourceStateHandler, I
3030
private bool searchForCursorIfUnset = true;
3131
public bool SearchForCursorIfUnset { get { return searchForCursorIfUnset; } set { searchForCursorIfUnset = value; } }
3232

33-
[Tooltip("If true, always select the best pointer available (OS behaviour does not autoselect).")]
33+
[Tooltip("If true, always select the best pointer available (OS behavior does not auto-select).")]
3434
[SerializeField]
3535
private bool autoselectBestAvailable = false;
3636
public bool AutoselectBestAvailable { get { return autoselectBestAvailable; } set { autoselectBestAvailable = value; } }
3737

3838
[Tooltip("The line pointer prefab to use, if any.")]
3939
[SerializeField]
40-
private GameObject linePointerPrefab;
40+
private GameObject linePointerPrefab = null;
4141

4242
private PointerLine instantiatedPointerLine;
4343

Assets/HoloToolkit/Input/Scripts/Utilities/BaseControllerPointer.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,10 @@ public abstract class BaseControllerPointer : AttachToController
1010
[Range(0f, 360f)]
1111
protected float CurrentPointerOrientation;
1212

13-
[SerializeField]
14-
[Range(0.5f, 50f)]
15-
private float extentOverride = 2f;
16-
1713
[SerializeField]
1814
[Tooltip("Source transform for raycast origin - leave null to use default transform")]
1915
protected Transform RaycastOrigin;
2016

21-
public float? ExtentOverride
22-
{
23-
get { return extentOverride; }
24-
set { extentOverride = value ?? FocusManager.Instance.GlobalPointingExtent; }
25-
}
26-
2717
/// <summary>
2818
/// The Y orientation of the pointer target - used for touchpad rotation and navigation
2919
/// </summary>

Assets/HoloToolkit/Input/Scripts/Utilities/PointerLine.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected override void OnEnable()
6767
LineBase.enabled = false;
6868
}
6969

70-
public void UpdateRenderedLine(RayStep[] lines, PointerResult result, bool selectPressed)
70+
public void UpdateRenderedLine(RayStep[] lines, PointerResult result, bool selectPressed, float extent)
7171
{
7272
if (LineBase == null) { return; }
7373

@@ -85,7 +85,7 @@ public void UpdateRenderedLine(RayStep[] lines, PointerResult result, bool selec
8585
}
8686
else
8787
{
88-
LineBase.LastPoint = RayStep.GetPointByDistance(lines, ExtentOverride.Value);
88+
LineBase.LastPoint = RayStep.GetPointByDistance(lines, extent);
8989
}
9090

9191
if (selectPressed)

0 commit comments

Comments
 (0)