IMHOTEP Framework
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Pages
LoadingScreen.cs
1 using UnityEngine;
2 using UnityEngine.UI;
3 using System.Collections;
4 using System.Collections.Generic;
5 
16 public class LoadingScreen : MonoBehaviour {
17 
18  public GameObject LoadingScreenWidget;
19  public GameObject TextPatientName;
20  //public GameObject TextLoadingProcess;
21  private Text mTextPatientName;
22  //private Text mTextLoadingProcess;
23  private List<string> activeJobs = new List<string>();
24 
25  // Use this for initialization
26  void Start () {
27  // Get the text components to be modified later:
28  //mTextLoadingProcess = TextLoadingProcess.GetComponent<Text> ();
29  mTextPatientName = TextPatientName.GetComponent<Text> ();
30 
31  // Start listening to events which are called during the loading process:
32  PatientEventSystem.startListening (PatientEventSystem.Event.PATIENT_StartLoading,
33  loadingStarted);
34  PatientEventSystem.startListening (PatientEventSystem.Event.LOADING_AddLoadingJob,
35  addLoadingJob);
36  PatientEventSystem.startListening (PatientEventSystem.Event.LOADING_RemoveLoadingJob,
37  removeLoadingJob);
38  }
39 
40  // Called when a new patient is being loaded:
41  void loadingStarted( object obj )
42  {
43  // The passed object should be the patient entry of the patient to be loaded:
44  PatientMeta patientEntry = obj as PatientMeta;
45  if (patientEntry != null) {
46  mTextPatientName.text = patientEntry.name;
47  }
48 
49  //mTextLoadingProcess.text = "Started Loading\n";
50  LoadingScreenWidget.SetActive (true);
51  }
52 
53  void addLoadingJob( object obj )
54  {
55  if (!LoadingScreenWidget.activeSelf)
56  return;
57 
58  string msg = obj as string;
59  if (msg != null) {
60  activeJobs.Add (msg);
61  }
62  updateInfo ();
63  }
64  void removeLoadingJob( object obj )
65  {
66  if (!LoadingScreenWidget.activeSelf)
67  return;
68 
69  string msg = obj as string;
70  if (msg != null) {
71  if (activeJobs.Contains (msg)) {
72  activeJobs.Remove (msg);
73  }
74  }
75  updateInfo ();
76 
77  // If all jobs have finished, close loading screen:
78  if (activeJobs.Count <= 0) {
79  LoadingScreenWidget.SetActive (false);
80  // Let others know that loading is considered finished:
81  // (TODO: maybe move this elsewhere?
82  PatientEventSystem.triggerEvent( PatientEventSystem.Event.PATIENT_FinishedLoading );
83  }
84  }
85  void updateInfo ()
86  {
87  string info = "";
88  foreach( string s in activeJobs )
89  {
90  info += s + ": Loading\n";
91  }
92  //mTextLoadingProcess.text = info;
93  }
94 
95 }