Skip to content

Commit 74df617

Browse files
author
David Kline
authored
Merge pull request #2201 from keveleigh/PointingRaysExtra
[May18] Updating pointing rays to extend out to the pointing extent off holograms
2 parents f56fa76 + 56b9a6e commit 74df617

File tree

7 files changed

+89
-29
lines changed

7 files changed

+89
-29
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: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,24 @@ 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+
// This value is used to determine the cursor's default distance.
29+
// It is cached here to prevent repeated casting in the update loop.
30+
pointerIsInputSourcePointer = value is InputSourcePointer;
31+
pointer = value;
32+
}
33+
}
34+
private IPointingSource pointer;
35+
36+
/// <summary>
37+
/// Cached value if the pointer is of type InputSourcePointer,
38+
/// to prevent repeated casting in the update loop.
39+
/// </summary>
40+
private bool pointerIsInputSourcePointer = false;
2441

2542
/// <summary>
2643
/// Minimum distance for cursor if nothing is hit
@@ -110,6 +127,12 @@ public Vector3 LocalScale
110127
private Vector3 targetScale;
111128
private Quaternion targetRotation;
112129

130+
/// <summary>
131+
/// Keeps track of the starting setting for DefaultCursorDistance,
132+
/// to revert after a pointer overrides the value.
133+
/// </summary>
134+
private float originalDefaultCursorDistance;
135+
113136
/// <summary>
114137
/// Indicates if the cursor should be visible
115138
/// </summary>
@@ -126,6 +149,8 @@ public bool IsVisible
126149

127150
private void Awake()
128151
{
152+
originalDefaultCursorDistance = DefaultCursorDistance;
153+
129154
// Use the setter to update visibility of the cursor at startup based on user preferences
130155
IsVisible = isVisible;
131156
SetVisibility(isVisible);
@@ -298,6 +323,21 @@ protected virtual void UpdateCursorTransform()
298323
TargetedObject = null;
299324
TargetedCursorModifier = null;
300325

326+
if (pointerIsInputSourcePointer)
327+
{
328+
// This value get re-queried every update, in case the app has
329+
// changed the pointing extent of the pointer for the current scenario.
330+
float distance = FocusManager.Instance.GetPointingExtent(Pointer);
331+
if (DefaultCursorDistance != distance)
332+
{
333+
DefaultCursorDistance = distance;
334+
}
335+
}
336+
else if (DefaultCursorDistance != originalDefaultCursorDistance)
337+
{
338+
DefaultCursorDistance = originalDefaultCursorDistance;
339+
}
340+
301341
targetPosition = RayStep.GetPointByDistance(Pointer.Rays, DefaultCursorDistance);
302342
lookForward = -RayStep.GetDirectionByDistance(Pointer.Rays, DefaultCursorDistance);
303343
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: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@ 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;
41+
42+
private PointerLine instantiatedPointerLine;
4143

4244
#endregion
4345

@@ -301,30 +303,43 @@ private void AttachInputSourcePointer(IInputSource inputSource, uint sourceId)
301303
inputSourcePointer.ExtentOverride = null;
302304
inputSourcePointer.PrioritizedLayerMasksOverride = null;
303305

304-
if (inputSourcePointer.PointerRay != null)
306+
InteractionInputSource interactionInputSource = inputSource as InteractionInputSource;
307+
308+
// If the InputSource is not an InteractionInputSource, we don't display any ray visualizations.
309+
if (interactionInputSource == null)
305310
{
306-
Destroy(inputSourcePointer.PointerRay.gameObject);
311+
return;
307312
}
308313

309-
if (inputSource is InteractionInputSource && linePointerPrefab != null)
314+
// If no pointing ray prefab has been provided, we return early as there's nothing to display.
315+
if (linePointerPrefab == null)
316+
{
317+
return;
318+
}
319+
320+
// If the pointer line hasn't already been instantiated, create it and store it here.
321+
if (instantiatedPointerLine == null)
322+
{
323+
instantiatedPointerLine = Instantiate(linePointerPrefab).GetComponent<PointerLine>();
324+
}
325+
326+
inputSourcePointer.PointerRay = instantiatedPointerLine;
327+
328+
Handedness handedness;
329+
if (interactionInputSource.TryGetHandedness(sourceId, out handedness))
310330
{
311-
inputSourcePointer.PointerRay = Instantiate(linePointerPrefab).GetComponent<PointerLine>();
312-
inputSourcePointer.PointerRay.ExtentOverride = Cursor.DefaultCursorDistance;
313-
Handedness handedness;
314-
if (((InteractionInputSource)inputSource).TryGetHandedness(sourceId, out handedness))
315-
{
316331
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
317-
inputSourcePointer.PointerRay.Handedness = (InteractionSourceHandedness)handedness;
332+
// This updates the handedness of the pointer line, allowing for re-use if it was already in the scene.
333+
instantiatedPointerLine.ChangeHandedness((InteractionSourceHandedness)handedness);
318334
#endif
319-
}
320335
}
321336
}
322337

323338
private void DetachInputSourcePointer()
324339
{
325-
if (inputSourcePointer.PointerRay != null)
340+
if (instantiatedPointerLine != null)
326341
{
327-
Destroy(inputSourcePointer.PointerRay.gameObject);
342+
Destroy(instantiatedPointerLine.gameObject);
328343
}
329344
}
330345

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/ControllerFinder.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,22 @@ protected virtual void OnDestroy()
9090
#endif
9191
}
9292

93+
/// <summary>
94+
/// Allows the object to change which controller it tracks, based on handedness.
95+
/// </summary>
96+
/// <param name="newHandedness">The new handedness to track. Does nothing if the handedness doesn't change.</param>
97+
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
98+
public void ChangeHandedness(InteractionSourceHandedness newHandedness)
99+
{
100+
if (newHandedness != handedness)
101+
{
102+
RemoveControllerTransform(ControllerInfo);
103+
handedness = newHandedness;
104+
CheckModelAlreadyLoaded();
105+
}
106+
}
107+
#endif
108+
93109
protected virtual void AddControllerTransform(MotionControllerInfo newController)
94110
{
95111
#if UNITY_WSA && UNITY_2017_2_OR_NEWER

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)