//Locates and initializes components public void Init(CinemaDatabase db) { database = db; slider = GetComponentInChildren <Slider>(); Text[] texts = GetComponentsInChildren <Text>(); foreach (Text text in texts) { if (text.CompareTag("valueText")) { valueText = text; } else if (text.CompareTag("labelText")) { labelText = text; } } Button[] buttons = GetComponentsInChildren <Button>(); foreach (Button button in buttons) { if (button.CompareTag("nextButton")) { button.onClick.AddListener(Next); } else if (button.CompareTag("prevButton")) { button.onClick.AddListener(Prev); } else if (button.CompareTag("firstButton")) { button.onClick.AddListener(First); } else if (button.CompareTag("lastButton")) { button.onClick.AddListener(Last); } else if (button.CompareTag("playButton")) { button.onClick.AddListener(Play); playButton = button; playButton.image.sprite = playSprite; } } }
private void Init() { string directory = path.Substring(0, path.LastIndexOf(Path.DirectorySeparatorChar)); if (!singleDatabase) { //Load multiple databases //Read file into JSONObject JSONObject json_data = new JSONObject(File.ReadAllText(path)); //Attempt to create boundaries from data in json, throwing an exception if data couldn't be found try { Vector3 max = VectorFromJson(json_data["metadata"]["maxBounds"]); Vector3 min = VectorFromJson(json_data["metadata"]["minBounds"]); CreateBoundaries(max, min); } catch (Exception e) { CreateBoundaries(new Vector3(100, 100, 100), new Vector3(-100, -100, -100)); addError("Boundaries not defined.\n" + "Defaulting to [100,100,100],[-100,-100,-100].\n" + "Details:\n" + e.GetType().ToString() + "\n" + e.Message); } try { Cache.maxItems = int.Parse(json_data["metadata"]["maxCacheSize"].ToString()); } catch (Exception e) { addError("Max cache size not defined.\nDefaulting to 100 images.\n" + "Details:\n" + e.GetType().ToString() + "\n" + e.Message); Cache.maxItems = 100; } float scale; try { scale = float.Parse(json_data["metadata"]["scale"].ToString()); } catch (Exception) { scale = 1.0f; } defaultParams = new DatabaseParams(); try { defaultParams.parseParameters(json_data["metadata"]); } catch (Exception e) { addError("Error parsing default parameters:\n" + e.GetType().ToString() + "\n" + e.Message); } //Iterate through databases and instantiate a database prefab for each one JSONObject[] databases = new JSONObject[0]; if (json_data.HasField("runs")) { databases = new JSONObject[json_data["runs"].Count]; } else { addError("Error reading JSON: Couldn't find field 'runs'"); } for (int i = 0; i < databases.Length; i++) { try { databases[i] = json_data["runs"][i]; Vector3 spawnPos = VectorFromJson(databases[i]["position"]); spawnPos *= scale; GameObject newDatabase = (GameObject)Instantiate(databasePrefab, spawnPos, new Quaternion()); newDatabase.SetActive(false); CinemaDatabase db = newDatabase.GetComponent <CinemaDatabase>(); db.setParams(new DatabaseParams(defaultParams)); db.getParams().parseParameters(databases[i]); if (!db.getParams().getOnline()) { db.getParams().setDirectory(directory + db.getParams().getDirectory()); } newDatabase.SetActive(true); } catch (Exception e) { addError("Error initializing database:\n" + e.GetType().ToString() + "\n" + e.Message); } } } else { try { //Load single database CreateBoundaries(new Vector3(15, 15, 15), new Vector3(-15, -15, -15)); GameObject newDatabase = (GameObject)Instantiate(databasePrefab); CinemaDatabase db = newDatabase.GetComponent <CinemaDatabase>(); db.setParams(new DatabaseParams()); db.getParams().setDirectory(directory); Cache.maxItems = 100; } catch (Exception e) { addError("Error initializing database:\n" + e.GetType() + "\n" + e.Message); } } }