Skip to content

Commit 92fa3bd

Browse files
Reverted the unregistering of pointers on source lost.
Updated internal pointer utilities. misc formatting.
1 parent 7f094ca commit 92fa3bd

File tree

4 files changed

+83
-70
lines changed

4 files changed

+83
-70
lines changed

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

Lines changed: 72 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,7 @@ protected override void Awake()
5151

5252
private void Start()
5353
{
54-
if (gazeManagerPointingData == null)
55-
{
56-
if (GazeManager.IsInitialized)
57-
{
58-
gazeManagerPointingData = new PointerData(GazeManager.Instance);
59-
}
60-
}
61-
else
62-
{
63-
Debug.Assert(ReferenceEquals(gazeManagerPointingData.PointingSource, GazeManager.Instance));
64-
}
65-
66-
if ((pointers.Count == 0) && autoRegisterGazePointerIfNoPointersRegistered && GazeManager.IsInitialized)
54+
if (pointers.Count == 0 && autoRegisterGazePointerIfNoPointersRegistered && GazeManager.IsInitialized)
6755
{
6856
RegisterPointer(GazeManager.Instance);
6957
}
@@ -261,27 +249,33 @@ public Camera UIRaycastCamera
261249

262250
public void RegisterPointer(IPointingSource pointingSource)
263251
{
264-
Debug.Assert(pointingSource != null);
252+
Debug.Assert(pointingSource != null, "Can't register a pointer if you give us one.");
253+
254+
int pointerIndex;
255+
PointerData pointer;
265256

266-
if (TryGetPointerIndex(pointingSource) != null)
257+
if (TryGetPointerIndex(pointingSource, out pointerIndex))
267258
{
268259
// This pointing source is already registered and active.
269260
return;
270261
}
271262

272-
PointerData pointer;
273-
274263
if (pointingSource is GazeManager)
275264
{
276265
if (gazeManagerPointingData == null)
277266
{
278-
gazeManagerPointingData = new PointerData(pointingSource);
267+
if (GazeManager.IsInitialized)
268+
{
269+
gazeManagerPointingData = new PointerData(GazeManager.Instance);
270+
}
279271
}
280272
else
281273
{
274+
Debug.Assert(ReferenceEquals(gazeManagerPointingData.PointingSource, GazeManager.Instance));
282275
gazeManagerPointingData.ResetFocusedObjects();
283276
}
284277

278+
Debug.Assert(gazeManagerPointingData != null);
285279
pointer = gazeManagerPointingData;
286280
}
287281
else
@@ -294,14 +288,17 @@ public void RegisterPointer(IPointingSource pointingSource)
294288

295289
public void UnregisterPointer(IPointingSource pointingSource)
296290
{
297-
Debug.Assert(pointingSource != null);
291+
Debug.Assert(pointingSource != null, "Can't unregister a pointer if you give us one.");
298292

299-
int? iPointer = TryGetPointerIndex(pointingSource);
300-
Debug.Assert(iPointer != null);
293+
int pointerIndex;
294+
TryGetPointerIndex(pointingSource, out pointerIndex);
295+
296+
PointerData pointer;
297+
GetPointer(pointingSource, out pointer);
301298

302-
PointerData pointer = pointers[iPointer.Value];
299+
// Should we be protecting against unregistering the GazeManager?
303300

304-
pointers.RemoveAt(iPointer.Value);
301+
pointers.RemoveAt(pointerIndex);
305302

306303
// Raise focus events if needed:
307304

@@ -331,13 +328,11 @@ public void UnregisterPointer(IPointingSource pointingSource)
331328

332329
public FocusDetails? TryGetFocusDetails(BaseEventData eventData)
333330
{
334-
for (int iPointer = 0; iPointer < pointers.Count; iPointer++)
331+
for (int i = 0; i < pointers.Count; i++)
335332
{
336-
PointerData pointer = pointers[iPointer];
337-
338-
if (pointer.PointingSource.OwnsInput(eventData))
333+
if (pointers[i].PointingSource.OwnsInput(eventData))
339334
{
340-
return pointer.End;
335+
return pointers[i].End;
341336
}
342337
}
343338

@@ -356,20 +351,20 @@ public GameObject TryGetFocusedObject(BaseEventData eventData)
356351
IPointingSource pointingSource;
357352
TryGetPointingSource(eventData, out pointingSource);
358353
PointerInputEventData pointerInputEventData = GetSpecificPointerEventData(pointingSource);
354+
355+
Debug.Assert(pointerInputEventData != null);
359356
pointerInputEventData.selectedObject = details.Value.Object;
360357

361358
return details.Value.Object;
362359
}
363360

364361
public bool TryGetPointingSource(BaseEventData eventData, out IPointingSource pointingSource)
365362
{
366-
for (int iPointer = 0; iPointer < pointers.Count; iPointer++)
363+
for (int i = 0; i < pointers.Count; i++)
367364
{
368-
PointerData pointer = pointers[iPointer];
369-
370-
if (pointer.PointingSource.OwnsInput(eventData))
365+
if (pointers[i].PointingSource.OwnsInput(eventData))
371366
{
372-
pointingSource = pointer.PointingSource;
367+
pointingSource = pointers[i].PointingSource;
373368
return true;
374369
}
375370
}
@@ -380,12 +375,28 @@ public bool TryGetPointingSource(BaseEventData eventData, out IPointingSource po
380375

381376
public FocusDetails GetFocusDetails(IPointingSource pointingSource)
382377
{
383-
return GetPointer(pointingSource).End;
378+
PointerData pointerData;
379+
FocusDetails details = default(FocusDetails);
380+
381+
if (GetPointer(pointingSource, out pointerData))
382+
{
383+
details = pointerData.End;
384+
}
385+
386+
return details;
384387
}
385388

386389
public GameObject GetFocusedObject(IPointingSource pointingSource)
387390
{
388-
return GetPointer(pointingSource).End.Object;
391+
PointerData pointerData;
392+
GameObject focusedObject = null;
393+
394+
if (GetPointer(pointingSource, out pointerData))
395+
{
396+
focusedObject = pointerData.End.Object;
397+
}
398+
399+
return focusedObject;
389400
}
390401

391402
/// <summary>
@@ -426,12 +437,19 @@ public PointerInputEventData GetGazePointerEventData()
426437

427438
public PointerInputEventData GetSpecificPointerEventData(IPointingSource pointer)
428439
{
429-
return GetPointer(pointer).UnityUIPointerData;
440+
PointerData pointerEventData;
441+
return GetPointer(pointer, out pointerEventData) ? pointerEventData.UnityUIPointerData : null;
430442
}
431443

432444
public float GetPointingExtent(IPointingSource pointingSource)
433445
{
434-
return GetPointingExtent(GetPointer(pointingSource));
446+
PointerData pointerData;
447+
return GetPointer(pointingSource, out pointerData) ? GetPointingExtent(pointerData) : pointingExtent;
448+
}
449+
450+
private float GetPointingExtent(PointerData pointer)
451+
{
452+
return pointer.PointingSource.ExtentOverride ?? pointingExtent;
435453
}
436454

437455
#endregion
@@ -777,32 +795,33 @@ private void RaisePointerSpecificFocusChangedEvents(IPointingSource pointer, Gam
777795
}
778796
}
779797

780-
private PointerData GetPointer(IPointingSource pointingSource)
798+
private bool GetPointer(IPointingSource pointingSource, out PointerData pointerData)
781799
{
782-
Debug.Assert(pointers.Count > 0, "No Pointers registered!");
783-
int? iPointer = TryGetPointerIndex(pointingSource);
784-
return iPointer != null ? pointers[iPointer.Value] : pointers[0];
800+
int pointerIndex;
801+
802+
if (TryGetPointerIndex(pointingSource, out pointerIndex))
803+
{
804+
pointerData = pointers[pointerIndex];
805+
return true;
806+
}
807+
808+
pointerData = null;
809+
return false;
785810
}
786811

787-
private int? TryGetPointerIndex(IPointingSource pointingSource)
812+
private bool TryGetPointerIndex(IPointingSource pointingSource, out int pointerIndex)
788813
{
789-
int? found = null;
790-
791814
for (int i = 0; i < pointers.Count; i++)
792815
{
793-
if (pointers[i].PointingSource == pointingSource)
816+
if (pointingSource == pointers[i].PointingSource)
794817
{
795-
found = i;
796-
break;
818+
pointerIndex = i;
819+
return true;
797820
}
798821
}
799822

800-
return found;
801-
}
802-
803-
private float GetPointingExtent(PointerData pointer)
804-
{
805-
return (pointer.PointingSource.ExtentOverride ?? pointingExtent);
823+
pointerIndex = -1;
824+
return false;
806825
}
807826

808827
private RaycastHit? PrioritizeHits(RaycastHit[] hits, LayerMask[] layerMasks)

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public bool InteractionEnabled
5151
[Obsolete("Will be removed in a later version. Use OnPreRaycast / OnPostRaycast instead.")]
5252
public void UpdatePointer()
5353
{
54-
5554
}
5655

5756
public virtual void OnPreRaycast()
@@ -62,9 +61,9 @@ public virtual void OnPreRaycast()
6261
}
6362
else
6463
{
65-
Debug.Assert(InputSource.SupportsInputInfo(InputSourceId, SupportedInputInfo.Pointing));
64+
Debug.Assert(InputSource.SupportsInputInfo(InputSourceId, SupportedInputInfo.Pointing), string.Format("{0} with id {1} does not support pointing!", InputSource, InputSourceId));
6665

67-
Ray pointingRay = default(Ray);
66+
Ray pointingRay;
6867
if (InputSource.TryGetPointingRay(InputSourceId, out pointingRay))
6968
{
7069
rays[0].CopyRay(pointingRay, FocusManager.Instance.GetPointingExtent(this));

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,12 @@ private void Start()
4545
started = true;
4646

4747
InputManager.AssertIsInitialized();
48-
GazeManager.AssertIsInitialized();
4948
FocusManager.AssertIsInitialized();
49+
GazeManager.AssertIsInitialized();
5050

5151
AddInputManagerListenerIfNeeded();
5252
FindCursorIfNeeded();
5353
ConnectBestAvailablePointer();
54-
55-
Debug.Assert(currentPointer != null, this);
5654
}
5755

5856
private void OnEnable()
@@ -79,12 +77,6 @@ void ISourceStateHandler.OnSourceDetected(SourceStateEventData eventData)
7977

8078
void ISourceStateHandler.OnSourceLost(SourceStateEventData eventData)
8179
{
82-
IPointingSource pointingSource;
83-
if (FocusManager.Instance.TryGetPointingSource(eventData, out pointingSource))
84-
{
85-
FocusManager.Instance.UnregisterPointer(pointingSource);
86-
}
87-
8880
if (IsInputSourcePointerActive && inputSourcePointer.InputIsFromSource(eventData))
8981
{
9082
ConnectBestAvailablePointer();
@@ -162,6 +154,11 @@ private void SetPointer(IPointingSource newPointer)
162154
{
163155
if (currentPointer != newPointer)
164156
{
157+
if (currentPointer != null)
158+
{
159+
FocusManager.Instance.UnregisterPointer(currentPointer);
160+
}
161+
165162
currentPointer = newPointer;
166163

167164
if (newPointer != null)
@@ -174,6 +171,8 @@ private void SetPointer(IPointingSource newPointer)
174171
Cursor.Pointer = newPointer;
175172
}
176173
}
174+
175+
Debug.Assert(currentPointer != null, "No Pointer Set!");
177176
}
178177

179178
private void ConnectBestAvailablePointer()
@@ -229,7 +228,6 @@ private void HandleInputAction(InputEventData eventData)
229228
// TODO: robertes: see if we can treat voice separately from the other simple committers,
230229
// so voice doesn't steal from a pointing controller. I think input Kind would need
231230
// to come through with the event data.
232-
233231
SetPointer(GazeManager.Instance);
234232
pointerWasChanged = true;
235233
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,7 @@ public LayerMask[] PrioritizedLayerMasksOverride
133133

134134
public bool InteractionEnabled
135135
{
136-
get
137-
{
138-
return true;
139-
}
136+
get { return true; }
140137
}
141138

142139
private float lastHitDistance = 2.0f;

0 commit comments

Comments
 (0)