Skip to content

Commit de8efe8

Browse files
author
Stephen Hodgson
authored
Merge pull request #510 from NeerajW/master
InputManager: Add OverrideFocusedObject functionality
2 parents 370089f + 2f4f88f commit de8efe8

File tree

6 files changed

+545
-3
lines changed

6 files changed

+545
-3
lines changed

Assets/HoloToolkit/Input/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ Gazing on an object and saying "Select Object" will persistently select that obj
295295
after which the user can also adjust object size with "Make Smaller" and "Make Bigger" voice commands and finally clear
296296
currently selected object by saying "Clear Selection".
297297

298+
#### OverrideFocusedObjectTest.unity
299+
Test scene shows you in a simple way, how to route input to an object not being gazed/focused at.
300+
Useful for scenarios like placing head locked content or clicking around to create objects.
301+
298302
#### SpeechInputSource.unity
299303

300304
Shows how to use the SpeechInputSource.cs script to add keywords to your scene.

Assets/HoloToolkit/Input/Scripts/InputManager.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ namespace HoloToolkit.Unity.InputModule
1414
/// </summary>
1515
public class InputManager : Singleton<InputManager>
1616
{
17+
/// <summary>
18+
/// To tap on a hologram even when not focused on,
19+
/// set OverrideFocusedObject to desired game object.
20+
/// If it's null, then focused object will be used.
21+
/// </summary>
22+
public GameObject OverrideFocusedObject { get; set; }
23+
1724
public event Action InputEnabled;
1825
public event Action InputDisabled;
1926

@@ -208,6 +215,9 @@ public void HandleEvent<T>(BaseEventData eventData, ExecuteEvents.EventFunction<
208215
return;
209216
}
210217

218+
// Use focused object when OverrideFocusedObject is null.
219+
GameObject focusedObject = (OverrideFocusedObject == null) ? GazeManager.Instance.HitObject : OverrideFocusedObject;
220+
211221
// Send the event to global listeners
212222
for (int i = 0; i < globalListeners.Count; i++)
213223
{
@@ -222,7 +232,6 @@ public void HandleEvent<T>(BaseEventData eventData, ExecuteEvents.EventFunction<
222232

223233
// If there is a focused object in the hierarchy of the modal handler, start the event
224234
// bubble there
225-
GameObject focusedObject = GazeManager.Instance.HitObject;
226235
if (focusedObject != null && focusedObject.transform.IsChildOf(modalInput.transform))
227236
{
228237

@@ -242,9 +251,9 @@ public void HandleEvent<T>(BaseEventData eventData, ExecuteEvents.EventFunction<
242251
}
243252

244253
// If event was not handled by modal, pass it on to the current focused object
245-
if (GazeManager.Instance.HitObject != null)
254+
if (focusedObject != null)
246255
{
247-
bool eventHandled = ExecuteEvents.ExecuteHierarchy(GazeManager.Instance.HitObject, eventData, eventHandler);
256+
bool eventHandled = ExecuteEvents.ExecuteHierarchy(focusedObject, eventData, eventHandler);
248257
if (eventHandled)
249258
{
250259
return;

0 commit comments

Comments
 (0)