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); }
public static SavedFaunaNutrient SaveNutrient(GameObject nutrientObject) { FaunaNutrient nutrientscriptRef = nutrientObject.GetComponent <FaunaNutrient>(); SavedFaunaNutrient nutrientSave = new SavedFaunaNutrient(); nutrientSave.xCoord = nutrientObject.transform.position.x; nutrientSave.yCoord = nutrientObject.transform.position.y; nutrientSave.zCoord = nutrientObject.transform.position.z; nutrientSave.remainingNutrients = nutrientscriptRef.remainingNutrients; return(nutrientSave); }
public static GameObject loadNutrient(SavedFaunaNutrient nutrientSave) { // GameObject loadedNutrient = GameObject.CreatePrimitive(PrimitiveType.Cube); GameObject loadedNutrient = Resources.Load("Prefabs/FaunaNutrient") as GameObject; FaunaNutrient nutrientscriptRef = loadedNutrient.GetComponent <FaunaNutrient>(); // loadedNutrient.GetComponent<MeshRenderer>().material = (Resources.Load("Materials/FaunaNutrient", typeof(Material)) as Material); // loadedNutrient.tag = "faunaNutrient"; // loadedNutrient.transform.localScale = new Vector3(1f, 1f, 1f); Vector3 pos = new Vector3(nutrientSave.xCoord, nutrientSave.yCoord, nutrientSave.zCoord); loadedNutrient.transform.position = pos; nutrientscriptRef.remainingNutrients = nutrientSave.remainingNutrients; return(loadedNutrient); }
// This function nukes the entire ecosystem and reinstantiates everything based // on the SavedEcosystem passed in public static void loadEntireEcosystem(SavedEcosystem saveToLoad) { // Clear the old, to make way for the new destroyEcosystem(); Debug.Log("Loading " + saveToLoad.waterSources.Count + " water sources!"); // Now we loop through the lists in the SavedEcosystem to instantiate them into the simulation for (int i = 0; i < saveToLoad.prey.Count; i++) { GameObject tempPrey = Instantiate(SavedPrey.loadPrey(saveToLoad.prey[i])); tempPrey.transform.parent = ecosystem.transform; } for (int i = 0; i < saveToLoad.predators.Count; i++) { GameObject tempPred = Instantiate(SavedPredator.loadPredator(saveToLoad.predators[i])); tempPred.transform.parent = ecosystem.transform; } for (int i = 0; i < saveToLoad.flora.Count; i++) { GameObject tempFlora = Instantiate(SavedFlora.loadFlora(saveToLoad.flora[i])); tempFlora.transform.parent = ecosystem.transform; } for (int i = 0; i < saveToLoad.floraNutrients.Count; i++) { GameObject tempNutrients = Instantiate(SavedFloraNutrient.loadNutrient(saveToLoad.floraNutrients[i])); tempNutrients.transform.parent = ecosystem.transform; } for (int i = 0; i < saveToLoad.faunaNutrients.Count; i++) { GameObject tempNutrients = Instantiate(SavedFaunaNutrient.loadNutrient(saveToLoad.faunaNutrients[i])); tempNutrients.transform.parent = ecosystem.transform; } for (int i = 0; i < saveToLoad.waterSources.Count; i++) { GameObject tempWater = Instantiate(Resources.Load("Prefabs/WaterSource") as GameObject, SavedWater.loadWaterPos(saveToLoad.waterSources[i]), Quaternion.identity); tempWater.transform.parent = ecosystem.transform; tempWater.tag = "waterSource"; } }
public void addFaunaNutrient(SavedFaunaNutrient nutrient) { faunaNutrients.Add(nutrient); }