Skip to content

Commit 7ce9b72

Browse files
committed
Update BaseFocusHandler, as a FocusExit does not always mean focus was lost
1 parent cd20d72 commit 7ce9b72

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

Assets/MixedRealityToolkit-SDK/Features/Input/Handlers/BaseFocusHandler.cs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public abstract class BaseFocusHandler : MonoBehaviour, IMixedRealityFocusHandle
2020
protected static IMixedRealityInputSystem InputSystem => inputSystem ?? (inputSystem = MixedRealityManager.Instance.GetManager<IMixedRealityInputSystem>());
2121

2222
[SerializeField]
23-
[Tooltip("Is Focus capabilities enabled for this component?")]
23+
[Tooltip("Is focus enabled for this component?")]
2424
private bool focusEnabled = true;
2525

2626
/// <inheritdoc />
@@ -30,10 +30,8 @@ public virtual bool FocusEnabled
3030
set { focusEnabled = value; }
3131
}
3232

33-
private bool hasFocus;
34-
3533
/// <inheritdoc />
36-
public bool HasFocus => FocusEnabled && hasFocus;
34+
public bool HasFocus => FocusEnabled && Focusers.Count > 0;
3735

3836
/// <inheritdoc />
3937
public List<IMixedRealityPointer> Focusers { get; } = new List<IMixedRealityPointer>(0);
@@ -47,25 +45,17 @@ public virtual void OnFocusExit(FocusEventData eventData) { }
4745
/// <inheritdoc />
4846
public virtual void OnBeforeFocusChange(FocusEventData eventData)
4947
{
50-
// If we're the new target object
51-
// Add the pointer to the list of focusers
52-
// and update our hasFocus flag if focusing is enabled.
48+
// If we're the new target object,
49+
// add the pointer to the list of focusers.
5350
if (eventData.NewFocusedObject == gameObject)
5451
{
5552
eventData.Pointer.FocusTarget = this;
5653
Focusers.Add(eventData.Pointer);
57-
58-
if (focusEnabled)
59-
{
60-
hasFocus = true;
61-
}
6254
}
63-
// If we're the old focused target object
64-
// update our flag and remove the pointer from our list.
55+
// If we're the old focused target object,
56+
// remove the pointer from our list.
6557
else if (eventData.OldFocusedObject == gameObject)
6658
{
67-
hasFocus = false;
68-
6959
Focusers.Remove(eventData.Pointer);
7060

7161
// If there is no new focused target

0 commit comments

Comments
 (0)