Skip to content

Commit 2c92134

Browse files
committed
Initial commit
1 parent 29ff159 commit 2c92134

File tree

5 files changed

+69
-24
lines changed

5 files changed

+69
-24
lines changed

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

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -507,25 +507,33 @@ private void UpdatePointer(PointerData pointer)
507507
{
508508
// Don't clear the previous focused object since we still want to trigger FocusExit events
509509
pointer.ResetFocusedObjects(false);
510-
return;
511510
}
511+
else
512+
{
513+
// If the pointer is locked
514+
// Keep the focus objects the same
515+
// This will ensure that we execute events on those objects
516+
// even if the pointer isn't pointing at them
517+
if (!pointer.PointingSource.FocusLocked)
518+
{
519+
// Otherwise, continue
520+
var prioritizedLayerMasks = (pointer.PointingSource.PrioritizedLayerMasksOverride ?? pointingRaycastLayerMasks);
512521

513-
// Otherwise, continue
514-
var prioritizedLayerMasks = (pointer.PointingSource.PrioritizedLayerMasksOverride ?? pointingRaycastLayerMasks);
522+
// Perform raycast to determine focused object
523+
RaycastPhysics(pointer, prioritizedLayerMasks);
515524

516-
// Perform raycast to determine focused object
517-
RaycastPhysics(pointer, prioritizedLayerMasks);
525+
// If we have a unity event system, perform graphics raycasts as well to support Unity UI interactions
526+
if (EventSystem.current != null)
527+
{
528+
// NOTE: We need to do this AFTER RaycastPhysics so we use the current hit point to perform the correct 2D UI Raycast.
529+
RaycastUnityUI(pointer, prioritizedLayerMasks);
530+
}
518531

519-
// If we have a unity event system, perform graphics raycasts as well to support Unity UI interactions
520-
if (EventSystem.current != null)
521-
{
522-
// NOTE: We need to do this AFTER RaycastPhysics so we use the current hit point to perform the correct 2D UI Raycast.
523-
RaycastUnityUI(pointer, prioritizedLayerMasks);
532+
// Set the pointer's result last
533+
pointer.PointingSource.Result = pointer;
534+
}
524535
}
525536

526-
// Set the pointer's result last
527-
pointer.PointingSource.Result = pointer;
528-
529537
// Call the pointer's OnPostRaycast function
530538
// This will give it a chance to respond to raycast results
531539
// eg by updating its appearance
@@ -601,6 +609,9 @@ private void RaycastUnityUI(PointerData pointer, LayerMask[] prioritizedLayerMas
601609
RayStep rayStep = default(RayStep);
602610
int rayStepIndex = 0;
603611

612+
Debug.Assert(pointer.PointingSource.Rays != null);
613+
Debug.Assert(pointer.PointingSource.Rays.Length > 0);
614+
604615
// Cast rays for every step until we score a hit
605616
for (int i = 0; i < pointer.PointingSource.Rays.Length; i++)
606617
{
@@ -613,7 +624,7 @@ private void RaycastUnityUI(PointerData pointer, LayerMask[] prioritizedLayerMas
613624
}
614625

615626
// Check if we need to overwrite the physics raycast info
616-
if ((pointer.End.Object == null || overridePhysicsRaycast) && uiRaycastResult.module.eventCamera == UIRaycastCamera)
627+
if ((pointer.End.Object == null || overridePhysicsRaycast) && (uiRaycastResult.module != null && uiRaycastResult.module.eventCamera == UIRaycastCamera))
617628
{
618629
newUiRaycastPosition.x = uiRaycastResult.screenPosition.x;
619630
newUiRaycastPosition.y = uiRaycastResult.screenPosition.y;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,7 @@ public interface IPointingSource
3333
void OnPostRaycast();
3434

3535
bool OwnsInput(BaseEventData eventData);
36+
37+
bool FocusLocked { get; set; }
3638
}
3739
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public bool InteractionEnabled
4646
}
4747
}
4848

49+
public bool FocusLocked { get; set; }
50+
4951
private RayStep[] rays = new RayStep[1] { new RayStep(Vector3.zero, Vector3.forward) };
5052

5153
[Obsolete("Will be removed in a later version. Use OnPreRaycast / OnPostRaycast instead.")]

Assets/HoloToolkit/Input/Scripts/Gaze/GazeManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ public bool InteractionEnabled
139139
}
140140
}
141141

142+
public bool FocusLocked { get; set; }
143+
142144
private float lastHitDistance = 2.0f;
143145

144146
protected override void Awake()

Assets/HoloToolkit/UX/Scripts/Receivers/InteractionReceiver.cs

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace HoloToolkit.Unity.Receivers
1313
/// An interaction receiver is simply a component that attached to a list of interactable objects and does something
1414
/// based on events from those interactable objects. This is the base abstract class to extend from.
1515
/// </summary>
16-
public abstract class InteractionReceiver : MonoBehaviour, IInputHandler, IHoldHandler, IInputClickHandler
16+
public abstract class InteractionReceiver : MonoBehaviour, IInputHandler, IHoldHandler, IInputClickHandler, IManipulationHandler
1717
{
1818
#region Public Members
1919
/// <summary>
@@ -31,11 +31,25 @@ public abstract class InteractionReceiver : MonoBehaviour, IInputHandler, IHoldH
3131
/// <summary>
3232
/// Flag for locking focus while selected
3333
/// </summary>
34-
[Tooltip("If true, this object will remain the prime focus while select is held")]
35-
public bool _LockFocus;
34+
public bool LockFocus
35+
{
36+
get
37+
{
38+
return lockFocus;
39+
}
40+
set
41+
{
42+
lockFocus = value;
43+
CheckLockFocus(_selectingFocuser);
44+
}
45+
}
3646
#endregion
3747

3848
#region Private and Protected Members
49+
[Tooltip("If true, this object will remain the prime focus while select is held")]
50+
[SerializeField]
51+
private bool lockFocus = false;
52+
3953
/// <summary>
4054
/// Protected focuser for the current selecting focuser
4155
/// </summary>
@@ -148,27 +162,39 @@ protected bool Isinteractable(GameObject interactable)
148162

149163
private void CheckLockFocus(IPointingSource focuser)
150164
{
151-
if (_LockFocus)
165+
// If our previous selecting focuser isn't the same
166+
if (_selectingFocuser != null && _selectingFocuser != focuser)
167+
{
168+
// If our focus is currently locked, unlock it before moving on
169+
if (LockFocus)
170+
{
171+
_selectingFocuser.FocusLocked = false;
172+
}
173+
}
174+
175+
// Set to the new focuser
176+
_selectingFocuser = focuser;
177+
if (_selectingFocuser != null)
152178
{
153-
//LockFocus(focuser);
179+
_selectingFocuser.FocusLocked = LockFocus;
154180
}
155181
}
156182

157-
private void LockFocus(IPointingSource focuser)
183+
private void LockFocuser(IPointingSource focuser)
158184
{
159185
if (focuser != null)
160186
{
161-
ReleaseFocus();
187+
ReleaseFocuser();
162188
_selectingFocuser = focuser;
163-
// _selectingFocuser.LockFocus();
189+
_selectingFocuser.FocusLocked = true;
164190
}
165191
}
166192

167-
private void ReleaseFocus()
193+
private void ReleaseFocuser()
168194
{
169195
if (_selectingFocuser != null)
170196
{
171-
// _selectingFocuser.ReleaseFocus();
197+
_selectingFocuser.FocusLocked = false;
172198
_selectingFocuser = null;
173199
}
174200
}
@@ -193,6 +219,8 @@ private void OnPointerSpecificFocusChanged(IPointingSource pointer, GameObject o
193219
{
194220
FocusExit(oldFocusedObject, eventData);
195221
}
222+
223+
CheckLockFocus(pointer);
196224
}
197225

198226
#region Global Listener Callbacks

0 commit comments

Comments
 (0)