// Start is called before the first frame update void Start() { GameObject[] flora = GameObject.FindGameObjectsWithTag("flora"); SavedFlora testSave = SavedFlora.saveFlora(flora[0]); GameObject testLoad = SavedFlora.loadFlora(testSave); Instantiate(testLoad); }
public static SavedEcosystem getCurrentEcosystem() { Debug.Log("Preparing to profile..."); SavedEcosystem save = new SavedEcosystem(); GameObject ecoRef = GameObject.FindGameObjectWithTag("ecosystem"); // Gather arrays of references to all ecosystem components GameObject[] predators = GameObject.FindGameObjectsWithTag("predator"); GameObject[] prey = GameObject.FindGameObjectsWithTag("prey"); GameObject[] flora = GameObject.FindGameObjectsWithTag("flora"); GameObject[] faunaNutrients = GameObject.FindGameObjectsWithTag("faunaNutrient"); GameObject[] floraNutrients = GameObject.FindGameObjectsWithTag("floraNutrient"); GameObject[] waterSources = GameObject.FindGameObjectsWithTag("waterSource"); // Loop through each and add them to our save. // Nutrients for (int i = 0; i < faunaNutrients.Length; i++) { save.addFaunaNutrient(SavedFaunaNutrient.SaveNutrient(faunaNutrients[i])); } for (int i = 0; i < floraNutrients.Length; i++) { save.addFloraNutrient(SavedFloraNutrient.SaveNutrient(floraNutrients[i])); } // Water for (int i = 0; i < waterSources.Length; i++) { save.addWaterSource(SavedWater.saveWater(waterSources[i])); } // Organisms // Here we have "gathered" all of the organism GameObjects. We use // the save[organism]() functions for each respective organism to convert it to // a saveable (serializable) class and add it to our list of SavedOrganisms. for (int i = 0; i < prey.Length; i++) { save.addPrey(SavedPrey.savePrey(prey[i])); } for (int i = 0; i < predators.Length; i++) { save.addPredator(SavedPredator.savePredator(predators[i])); } for (int i = 0; i < flora.Length; i++) { save.addFlora(SavedFlora.saveFlora(flora[i])); } Debug.Log("Finished profile save! Returning to Save()"); return(save); }