IMHOTEP Framework
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Pages
QuickLoad.cs
1 using UnityEngine;
2 using System.Collections;
3 using System.IO;
4 
5 public class QuickLoad : MonoBehaviour {
6 
7  public string patientFolderName;
8  public ToolWidget toolToLoad;
9  public GameObject sphere;
10  public GameObject sphereEmitters;
11  public GameObject patientSelector;
12 
13  // Use this for initialization
14  void Start () {
15 
16  PatientEventSystem.startListening (
17  PatientEventSystem.Event.PATIENT_NewPatientDirectoryFound,
18  addPatientEntry
19  );
20 
21  PatientEventSystem.startListening (
22  PatientEventSystem.Event.PATIENT_FinishedLoading,
23  loadedPatient
24  );
25 
26  // Start loading the patient directory:
27  PatientDirectoryLoader.setPath("../Patients/");
28 
29  // Activate all the objects:
30  sphere.SetActive (true);
31  sphereEmitters.SetActive (true);
32 
33  // Start the animations of the objects, and set their normalized time to 1 (the end)
34  sphereEmitters.GetComponent<Animator> ().Play ("EnableSphereEmitters", -1, 1f);
35  sphere.GetComponent<Animator> ().Play ("EnableSphere", -1, 1f);
36  }
37 
38  void addPatientEntry( object obj = null )
39  {
40  bool found = false;
41  for (int index = 0; index < PatientDirectoryLoader.getCount (); index++) {
42  PatientMeta patient = PatientDirectoryLoader.getEntry(index);
43  string folderName = Path.GetFileName (patient.path);
44  if (folderName == patientFolderName) {
45  Debug.Log ("Found patient " + patientFolderName);
46  PatientDirectoryLoader.loadPatient(index);
47  found = true;
48  break;
49  }
50  }
51  if( !found )
52  {
53  Debug.LogWarning ("Patient '" + patientFolderName + "' not found! Make sure to enter valid Patient folder in 'Patient Folder Name'!");
54  patientSelector.SetActive (true);
55  }
56  }
57 
58  void loadedPatient( object obj = null )
59  {
60  if( toolToLoad != null )
61  ToolControl.instance.chooseTool (toolToLoad);
62  }
63 }