Ejemplo n.º 1
0
    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);
    }
Ejemplo n.º 2
0
    // 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";
        }
    }