AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
ProgressExamples.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
5 using System.Collections;
6 using UnityEngine;
7 
8 #if UNITY_WSA && UNITY_2017_2_OR_NEWER
9 using UnityEngine.XR.WSA;
10 #endif
11 
12 
13 namespace HoloToolkit.Examples.UX
14 {
15  public class ProgressExamples : MonoBehaviour
16  {
17  [Header("How long to spend on each stage of loading")]
18  [SerializeField]
19  private float leadInTime = 1.5f;
20 
21  [SerializeField]
22  private float loadingTime = 5f;
23 
24  [SerializeField]
25  private float finishTime = 1.5f;
26 
27  [Header("Set these to override the defaults set in the ProgressIndicator prefab")]
28  [SerializeField]
29  private GameObject loadingPrefab = null;
30 
31  [SerializeField]
32  private Texture2D loadingIcon = null;
33 
34  [Header("Messages displayed during loading")]
35  [SerializeField]
36  private string leadInMessage = "Lead in Message";
37  [SerializeField]
38  private string loadTextMessage = "Loading with message only";
39  [SerializeField]
40  private string loadOrbsMessage = "Loading with Orbs";
41  [SerializeField]
42  private string loadIconMessage = "Loading with Icon";
43  [SerializeField]
44  private string loadPrefabMessage = "Loading with Prefab";
45  [SerializeField]
46  private string loadProgressMessage = "Loading with Progress";
47  [SerializeField]
48  private string loadProgressBarMessage = "Loading with Bar";
49  [SerializeField]
50  private string finishMessage = "Finished!";
51 
52  [SerializeField]
53  private GameObject buttonCollection = null;
54 
55  public float LeadInTime
56  {
57  get
58  {
59  return leadInTime;
60  }
61 
62  set
63  {
64  leadInTime = value;
65  }
66  }
67 
68  public float LoadingTime
69  {
70  get
71  {
72  return loadingTime;
73  }
74 
75  set
76  {
77  loadingTime = value;
78  }
79  }
80 
81  public float FinishTime
82  {
83  get
84  {
85  return finishTime;
86  }
87 
88  set
89  {
90  finishTime = value;
91  }
92  }
93 
94  public GameObject LoadingPrefab
95  {
96  get
97  {
98  return loadingPrefab;
99  }
100 
101  set
102  {
103  loadingPrefab = value;
104  }
105  }
106 
107  public Texture2D LoadingIcon
108  {
109  get
110  {
111  return loadingIcon;
112  }
113 
114  set
115  {
116  loadingIcon = value;
117  }
118  }
119 
120  public GameObject ButtonCollection
121  {
122  get
123  {
124  return buttonCollection;
125  }
126 
127  set
128  {
129  buttonCollection = value;
130  }
131  }
132 
133  public string LeadInMessage
134  {
135  get
136  {
137  return leadInMessage;
138  }
139 
140  set
141  {
142  leadInMessage = value;
143  }
144  }
145 
146  public string LoadTextMessage
147  {
148  get
149  {
150  return loadTextMessage;
151  }
152 
153  set
154  {
155  loadTextMessage = value;
156  }
157  }
158 
159  public string LoadOrbsMessage
160  {
161  get
162  {
163  return loadOrbsMessage;
164  }
165 
166  set
167  {
168  loadOrbsMessage = value;
169  }
170  }
171 
172  public string LoadIconMessage
173  {
174  get
175  {
176  return loadIconMessage;
177  }
178 
179  set
180  {
181  loadIconMessage = value;
182  }
183  }
184 
185  public string LoadPrefabMessage
186  {
187  get
188  {
189  return loadPrefabMessage;
190  }
191 
192  set
193  {
194  loadPrefabMessage = value;
195  }
196  }
197 
198  public string LoadProgressMessage
199  {
200  get
201  {
202  return loadProgressMessage;
203  }
204 
205  set
206  {
207  loadProgressMessage = value;
208  }
209  }
210 
211  public string LoadProgressBarMessage
212  {
213  get
214  {
215  return loadProgressBarMessage;
216  }
217 
218  set
219  {
220  loadProgressBarMessage = value;
221  }
222  }
223 
224  public string FinishMessage
225  {
226  get
227  {
228  return finishMessage;
229  }
230 
231  set
232  {
233  finishMessage = value;
234  }
235  }
236 
237  public void LaunchProgress(IndicatorStyleEnum indicatorStyle, ProgressStyleEnum progressStyle)
238  {
239  if (ProgressIndicator.Instance.IsLoading)
240  {
241  return;
242  }
243 
244  switch (indicatorStyle)
245  {
246  case IndicatorStyleEnum.None:
247  //progressbar examples all assume IndicatorStyleEnum = None
248  switch (progressStyle)
249  {
250  case ProgressStyleEnum.Percentage:
252  IndicatorStyleEnum.None,
253  ProgressStyleEnum.Percentage,
254  ProgressMessageStyleEnum.Visible,
255  LeadInMessage);
256  StartCoroutine(LoadOverTime(LoadProgressMessage));
257  break;
258 
259  case ProgressStyleEnum.ProgressBar:
261  IndicatorStyleEnum.None,
262  ProgressStyleEnum.ProgressBar,
263  ProgressMessageStyleEnum.Visible,
264  LeadInMessage);
265  StartCoroutine(LoadOverTime(LoadProgressBarMessage));
266  break;
267 
268  case ProgressStyleEnum.None:
270  IndicatorStyleEnum.None,
271  ProgressStyleEnum.None,
272  ProgressMessageStyleEnum.Visible,
273  LeadInMessage);
274  StartCoroutine(LoadOverTime(LoadTextMessage));
275  break;
276  }
277  break;
278 
279  case IndicatorStyleEnum.AnimatedOrbs:
281  IndicatorStyleEnum.AnimatedOrbs,
282  ProgressStyleEnum.None,
283  ProgressMessageStyleEnum.Visible,
284  LeadInMessage);
285  StartCoroutine(LoadOverTime(LoadOrbsMessage));
286  break;
287 
288  case IndicatorStyleEnum.StaticIcon:
290  IndicatorStyleEnum.StaticIcon,
291  ProgressStyleEnum.None,
292  ProgressMessageStyleEnum.Visible,
293  LeadInMessage,
294  null);
295  StartCoroutine(LoadOverTime(LoadIconMessage));
296  break;
297 
298  case IndicatorStyleEnum.Prefab:
300  IndicatorStyleEnum.Prefab,
301  ProgressStyleEnum.None,
302  ProgressMessageStyleEnum.Visible,
303  LeadInMessage,
304  LoadingPrefab);
305  StartCoroutine(LoadOverTime(LoadPrefabMessage));
306  break;
307 
308  default:
309  break;
310  }
311  }
312 
313  protected IEnumerator LoadOverTime(string message)
314  {
315  // Wait for lead in time to end (optional)
316  float startTime = Time.time;
317  yield return new WaitForSeconds(LeadInTime);
318 
319  // Progress must be a number from 0-1 (it will be clamped)
320  // It will be formatted according to 'ProgressFormat' (0.0 by default) and followed with a '%' character
321  float progress = 0f;
322  // While we're in the loading period, update progress and message in 1/4 second intervals
323  // Displayed progress is smoothed out so you don't have to update every frame
324  startTime = Time.time;
325  while (Time.time < startTime + LoadingTime)
326  {
327  progress = (Time.time - startTime) / LoadingTime;
328  ProgressIndicator.Instance.SetMessage(message);
329  ProgressIndicator.Instance.SetProgress(progress);
330  yield return new WaitForSeconds(Random.Range(0.15f, 0.5f));
331  }
332 
333  // Give the user a final notification that loading has finished (optional)
334  ProgressIndicator.Instance.SetMessage(FinishMessage);
335  ProgressIndicator.Instance.SetProgress(1f);
336  yield return new WaitForSeconds(FinishTime);
337 
338  // Close the loading dialog
339  // ProgressIndicator.Instance.IsLoading will report true until its 'Closing' animation has ended
340  // This typically takes about 1 second
341  ProgressIndicator.Instance.Close();
342  while (ProgressIndicator.Instance.IsLoading)
343  {
344  yield return null;
345  }
346 
347  yield break;
348  }
349  }
350 }
void LaunchProgress(IndicatorStyleEnum indicatorStyle, ProgressStyleEnum progressStyle)
IEnumerator LoadOverTime(string message)
static T Instance
Returns the Singleton instance of the classes type. If no instance is found, then we search for an in...
Definition: Singleton.cs:26
ProgressMessageStyleEnum
The style of the Message portion of a Progress Indicator
IndicatorStyleEnum
Enum describing the style of the Indicator portion
Singleton for displaying a simple loading dialog Can be combined with a radial solver to keep locked ...