Skip to content

Commit 46a6595

Browse files
Modified Interactable to keep track of pointers using focus changed events
1 parent 1439b5c commit 46a6595

File tree

1 file changed

+25
-6
lines changed
  • Assets/MixedRealityToolkit.SDK/Features/UX/Interactable/Scripts

1 file changed

+25
-6
lines changed

Assets/MixedRealityToolkit.SDK/Features/UX/Interactable/Scripts/Interactable.cs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace Microsoft.MixedReality.Toolkit.SDK.UX.Interactable
3535

3636
[System.Serializable]
3737

38-
public class Interactable : MonoBehaviour, IMixedRealityFocusHandler, IMixedRealityInputHandler, IMixedRealityPointerHandler, IMixedRealitySpeechHandler // TEMP , IInputClickHandler, IFocusable, IInputHandler
38+
public class Interactable : MonoBehaviour, IMixedRealityFocusChangedHandler, IMixedRealityFocusHandler, IMixedRealityInputHandler, IMixedRealityPointerHandler, IMixedRealitySpeechHandler // TEMP , IInputClickHandler, IFocusable, IInputHandler
3939
{
4040
/// <summary>
4141
/// Setup the input system
@@ -518,17 +518,37 @@ private void RemovePointer(IMixedRealityPointer pointer)
518518

519519
#endregion PointerManagement
520520

521-
#region MixedRealityFocusHandlers
521+
#region MixedRealityFocusChangedHandlers
522522

523-
public void OnFocusEnter(FocusEventData eventData)
523+
public void OnBeforeFocusChange(FocusEventData eventData)
524524
{
525525
if (!CanInteract())
526526
{
527527
return;
528528
}
529529

530-
AddPointer(eventData.Pointer);
531-
SetFocus(pointers.Count > 0);
530+
if (eventData.NewFocusedObject == gameObject)
531+
{
532+
AddPointer(eventData.Pointer);
533+
}
534+
else if (eventData.OldFocusedObject == gameObject)
535+
{
536+
RemovePointer(eventData.Pointer);
537+
}
538+
}
539+
540+
public void OnFocusChanged(FocusEventData eventData) {}
541+
542+
#endregion MixedRealityFocusChangedHandlers
543+
544+
#region MixedRealityFocusHandlers
545+
546+
public void OnFocusEnter(FocusEventData eventData)
547+
{
548+
if (CanInteract())
549+
{
550+
SetFocus(pointers.Count > 0);
551+
}
532552
}
533553

534554
public void OnFocusExit(FocusEventData eventData)
@@ -538,7 +558,6 @@ public void OnFocusExit(FocusEventData eventData)
538558
return;
539559
}
540560

541-
RemovePointer(eventData.Pointer);
542561
SetFocus(pointers.Count > 0);
543562
}
544563

0 commit comments

Comments
 (0)