// Loads every single site and it's data. // Warning: This can take a LONG time! Best when scheduled when nobody will be using the application. public IEnumerator LoadAllSites() { // Set the status text so the user knows to wait. StatusText.SetText("Loading All Sites. Please Wait."); // Lock all input. GamepadInput.LockInput(true); // Check one more time to make sure we're supposed to be doing this. if (GameManager.instance.caveSettings.loadAllDataOnStart) { // Iterate through every single site. for (int i = 0; i < sites.Count; i++) { // Store the site at this array index. Site site = sites[i]; // Iterate through all data sets that are part of this site. for (int j = 0; j < site.dataSets.Count; j++) { // Store the data set. SiteElementSet dataSet = site.dataSets[j]; // Iterate through all data elements that are part of this data set. for (int k = 0; k < dataSet.siteElements.Count; k++) { // Store this data element. SiteElement dataElement = dataSet.siteElements[k]; // Set the status text to a helpful message. string statusString = string.Format("Loading element {0} of {1} from set {2} of {3} from site {4} of {5}", k, dataSet.siteElements.Count, j, site.dataSets.Count, i, sites.Count); StatusText.SetText(statusString); Debug.Log(statusString); // Wait for this data element to load before proceeding. yield return(dataElement.Load()); } } } } // Unlock input. GamepadInput.LockInput(false); }
// Wait for the object to load. Adds a layer of abstraction. private IEnumerator WaitForLoad() { // Don't try to load two different elements at once. Could get messy. while (SiteManager.loading) { yield return(null); } // Lock user input so they can't interact while an object is loading. GamepadInput.LockInput(true); SiteManager.loading = true; // Show the loading status. StatusText.Show(); // If there's no specified scene name in the JSON, then we just load the data normally. if (string.IsNullOrEmpty(siteData.sceneName)) { yield return(StartCoroutine(LoadCoroutine())); yield return(StartCoroutine(LoadCustomData())); } // Otherwise, we just load the scene specified in JSON. else { // Variable to keep track if we actually found the scene or not. bool foundScene = false; // Iterate through all existing scenes. for (int i = 0; i < SceneManager.sceneCount; i++) { // Get the scene at specified index. Scene scene = SceneManager.GetSceneAt(i); // Check if the names match. if (scene.name.Equals(siteData.sceneName)) { // If they match, scene was found. Load the scene. foundScene = true; AsyncOperation sceneLoad = SceneManager.LoadSceneAsync(siteData.sceneName); // Load the scene specified in JSON and wait for it to finish loading. while (!sceneLoad.isDone) { yield return(null); } // Break, since we found the scene. break; } } // If we didn't find the scene, log an error and try to load normally... which probably won't work. if (!foundScene) { Debug.LogErrorFormat("Could not find scene name '{0}', which was provided in JSON data file. Ensure this scene exists and is added to build settings."); yield return(StartCoroutine(LoadCoroutine())); } } // Everything is now loaded. loaded = true; // Hide the status text. StatusText.Hide(); // Unlock input and mark scene as not loading anymore. GamepadInput.LockInput(false); SiteManager.loading = false; }