This repository has been archived by the owner on Jun 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 128
/
UIManager.cs
405 lines (326 loc) · 10.1 KB
/
UIManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
public struct UXHandle
{
public UIManager.InstructionUI InstructionalUI;
public UIManager.InstructionGoals Goal;
public UXHandle(UIManager.InstructionUI ui, UIManager.InstructionGoals goal)
{
InstructionalUI = ui;
Goal = goal;
}
}
public class UIManager : MonoBehaviour
{
[SerializeField]
bool m_StartWithInstructionalUI = true;
public bool startWithInstructionalUI
{
get => m_StartWithInstructionalUI;
set => m_StartWithInstructionalUI = value;
}
public enum InstructionUI
{
CrossPlatformFindAPlane,
FindAFace,
FindABody,
FindAnImage,
FindAnObject,
ARKitCoachingOverlay,
TapToPlace,
None
};
[SerializeField]
InstructionUI m_InstructionalUI;
public InstructionUI instructionalUI
{
get => m_InstructionalUI;
set => m_InstructionalUI = value;
}
public enum InstructionGoals
{
FoundAPlane,
FoundMultiplePlanes,
FoundAFace,
FoundABody,
FoundAnImage,
FoundAnObject,
PlacedAnObject,
None
};
[SerializeField]
InstructionGoals m_InstructionalGoal;
public InstructionGoals instructionalGoal
{
get => m_InstructionalGoal;
set => m_InstructionalGoal = value;
}
[SerializeField]
bool m_ShowSecondaryInstructionalUI;
public bool showSecondaryInstructionalUI
{
get => m_ShowSecondaryInstructionalUI;
set => m_ShowSecondaryInstructionalUI = value;
}
[SerializeField]
InstructionUI m_SecondaryInstructionUI = InstructionUI.TapToPlace;
public InstructionUI secondaryInstructionUI
{
get => m_SecondaryInstructionUI;
set => m_SecondaryInstructionUI = value;
}
[SerializeField]
InstructionGoals m_SecondaryGoal = InstructionGoals.PlacedAnObject;
public InstructionGoals secondaryGoal
{
get => m_SecondaryGoal;
set => m_SecondaryGoal = value;
}
[SerializeField]
[Tooltip("Fallback to cross platform UI if ARKit coaching overlay is not supported")]
bool m_CoachingOverlayFallback;
public bool coachingOverlayFallback
{
get => m_CoachingOverlayFallback;
set => m_CoachingOverlayFallback = value;
}
[SerializeField]
GameObject m_ARSessionOrigin;
public GameObject arSessionOrigin
{
get => m_ARSessionOrigin;
set => m_ARSessionOrigin = value;
}
Func<bool> m_GoalReached;
bool m_SecondaryGoalReached;
Queue<UXHandle> m_UXOrderedQueue;
UXHandle m_CurrentHandle;
bool m_ProcessingInstructions;
bool m_PlacedObject;
[SerializeField]
ARPlaneManager m_PlaneManager;
public ARPlaneManager planeManager
{
get => m_PlaneManager;
set => m_PlaneManager = value;
}
[SerializeField]
ARFaceManager m_FaceManager;
public ARFaceManager faceManager
{
get => m_FaceManager;
set => m_FaceManager = value;
}
[SerializeField]
ARHumanBodyManager m_BodyManager;
public ARHumanBodyManager bodyManager
{
get => m_BodyManager;
set => m_BodyManager = value;
}
[SerializeField]
ARTrackedImageManager m_ImageManager;
public ARTrackedImageManager imageManager
{
get => m_ImageManager;
set => m_ImageManager = value;
}
[SerializeField]
ARTrackedObjectManager m_ObjectManager;
public ARTrackedObjectManager objectManager
{
get => m_ObjectManager;
set => m_ObjectManager = value;
}
[SerializeField]
ARUXAnimationManager m_AnimationManager;
public ARUXAnimationManager animationManager
{
get => m_AnimationManager;
set => m_AnimationManager = value;
}
bool m_FadedOff = false;
[SerializeField]
LocalizationManager m_LocalizationManager;
public LocalizationManager localizationManager
{
get => m_LocalizationManager;
set => m_LocalizationManager = value;
}
void OnEnable()
{
ARUXAnimationManager.onFadeOffComplete += FadeComplete;
PlaceObjectsOnPlane.onPlacedObject += () => m_PlacedObject = true;
GetManagers();
m_UXOrderedQueue = new Queue<UXHandle>();
if (m_StartWithInstructionalUI)
{
m_UXOrderedQueue.Enqueue(new UXHandle(m_InstructionalUI, m_InstructionalGoal));
}
if (m_ShowSecondaryInstructionalUI)
{
m_UXOrderedQueue.Enqueue(new UXHandle(m_SecondaryInstructionUI, m_SecondaryGoal));
}
}
void OnDisable()
{
ARUXAnimationManager.onFadeOffComplete -= FadeComplete;
}
void Update()
{
if (m_AnimationManager.localizeText)
{
if (!m_LocalizationManager.localizationComplete)
{
return;
}
}
if (m_UXOrderedQueue.Count > 0 && !m_ProcessingInstructions)
{
// pop off
m_CurrentHandle = m_UXOrderedQueue.Dequeue();
// exit instantly, if the goal is already met it will skip showing the first UI and move to the next in the queue
m_GoalReached = GetGoal(m_CurrentHandle.Goal);
if (m_GoalReached.Invoke())
{
return;
}
// fade on
FadeOnInstructionalUI(m_CurrentHandle.InstructionalUI);
m_ProcessingInstructions = true;
m_FadedOff = false;
}
if (m_ProcessingInstructions)
{
// start listening for goal reached
if (m_GoalReached.Invoke())
{
// if goal reached, fade off
if (!m_FadedOff)
{
m_FadedOff = true;
m_AnimationManager.FadeOffCurrentUI();
}
}
}
}
void GetManagers()
{
if (m_ARSessionOrigin)
{
if (m_ARSessionOrigin.TryGetComponent(out ARPlaneManager arPlaneManager))
{
m_PlaneManager = arPlaneManager;
}
if (m_ARSessionOrigin.TryGetComponent(out ARFaceManager arFaceManager))
{
m_FaceManager = arFaceManager;
}
if (m_ARSessionOrigin.TryGetComponent(out ARHumanBodyManager arHumanBodyManager))
{
m_BodyManager = arHumanBodyManager;
}
if (m_ARSessionOrigin.TryGetComponent(out ARTrackedImageManager arTrackedImageManager))
{
m_ImageManager = arTrackedImageManager;
}
if (m_ARSessionOrigin.TryGetComponent(out ARTrackedObjectManager arTrackedObjectManager))
{
m_ObjectManager = arTrackedObjectManager;
}
}
}
Func<bool> GetGoal(InstructionGoals goal)
{
switch (goal)
{
case InstructionGoals.FoundAPlane:
return PlanesFound;
case InstructionGoals.FoundMultiplePlanes:
return MultiplePlanesFound;
case InstructionGoals.FoundABody:
return BodyFound;
case InstructionGoals.FoundAFace:
return FaceFound;
case InstructionGoals.FoundAnImage:
return ImageFound;
case InstructionGoals.FoundAnObject:
return ObjectFound;
case InstructionGoals.PlacedAnObject:
return PlacedObject;
case InstructionGoals.None:
return () => false;
}
return () => false;
}
void FadeOnInstructionalUI(InstructionUI ui)
{
switch (ui)
{
case InstructionUI.CrossPlatformFindAPlane:
m_AnimationManager.ShowCrossPlatformFindAPlane();
break;
case InstructionUI.FindAFace:
m_AnimationManager.ShowFindFace();
break;
case InstructionUI.FindABody:
m_AnimationManager.ShowFindBody();
break;
case InstructionUI.FindAnImage:
m_AnimationManager.ShowFindImage();
break;
case InstructionUI.FindAnObject:
m_AnimationManager.ShowFindObject();
break;
case InstructionUI.ARKitCoachingOverlay:
if (m_AnimationManager.ARKitCoachingOverlaySupported())
{
m_AnimationManager.ShowCoachingOverlay();
}
else
{
// fall back to cross platform overlay
if (m_CoachingOverlayFallback)
{
m_AnimationManager.ShowCrossPlatformFindAPlane();
}
}
break;
case InstructionUI.TapToPlace:
m_AnimationManager.ShowTapToPlace();
break;
case InstructionUI.None:
break;
}
}
bool PlanesFound() => m_PlaneManager && m_PlaneManager.trackables.count > 0;
bool MultiplePlanesFound() => m_PlaneManager && m_PlaneManager.trackables.count > 1;
bool FaceFound() => m_FaceManager && m_FaceManager.trackables.count > 0;
bool BodyFound() => m_BodyManager && m_BodyManager.trackables.count > 0;
bool ImageFound() => m_ImageManager && m_ImageManager.trackables.count > 0;
bool ObjectFound() => m_ObjectManager && m_ObjectManager.trackables.count > 0;
void FadeComplete()
{
m_ProcessingInstructions = false;
}
bool PlacedObject()
{
// reset flag to be used multiple times
if (m_PlacedObject)
{
m_PlacedObject = false;
return true;
}
return m_PlacedObject;
}
public void AddToQueue(UXHandle uxHandle)
{
m_UXOrderedQueue.Enqueue(uxHandle);
}
public void TestFlipPlacementBool()
{
m_PlacedObject = true;
}
}