Esempio n. 1
0
    // Takes a SavedFlora and returns a GameObject to be instantiated.
    public static GameObject loadFlora(SavedFlora floraSave)
    {
        // We are essentially building the Flora object from scratch here.
        // GameObject loadedFlora = GameObject.CreatePrimitive(PrimitiveType.Cube);
        GameObject loadedFlora = Resources.Load("Prefabs/Flora") as GameObject;

        // Flora floraScriptRef = loadedFlora.AddComponent<Flora>();
        Flora floraScriptRef = loadedFlora.GetComponent <Flora>();

        // loadedFlora.GetComponent<MeshRenderer>().material = (Resources.Load("Materials/Green", typeof(Material)) as Material);

        // loadedFlora.transform.localScale = new Vector3(.25f, 3f, .25f);
        Vector3 pos = new Vector3(floraSave.xCoord, floraSave.yCoord, floraSave.zCoord);

        loadedFlora.transform.position = pos;

        floraScriptRef.waterLevel         = floraSave.waterLevel;
        floraScriptRef.nutrientValue      = floraSave.nutrientValue;
        floraScriptRef.reproductiveChance = floraSave.reproductiveChance;
        floraScriptRef.reproductiveRate   = floraSave.reproductiveRate;
        floraScriptRef.awareness          = floraSave.awareness;
        floraScriptRef.remainingNutrients = floraSave.remainingNutrients;


        return(loadedFlora);
    }
Esempio n. 2
0
    // 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);
    }
Esempio n. 3
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);
    }
Esempio n. 4
0
    // Takes a GameObject in a scene and returns a SavedFlora storing it
    public static SavedFlora saveFlora(GameObject floraObject)
    {
        Flora      floraScriptRef = floraObject.GetComponent <Flora>();
        SavedFlora floraSave      = new SavedFlora();

        floraSave.xCoord = floraObject.transform.position.x;
        floraSave.yCoord = floraObject.transform.position.y;
        floraSave.zCoord = floraObject.transform.position.z;

        floraSave.waterLevel         = floraScriptRef.waterLevel;
        floraSave.nutrientValue      = floraScriptRef.nutrientValue;
        floraSave.reproductiveChance = floraScriptRef.reproductiveChance;
        floraSave.reproductiveRate   = floraScriptRef.reproductiveRate;
        floraSave.awareness          = floraScriptRef.awareness;
        floraSave.remainingNutrients = floraScriptRef.remainingNutrients;

        return(floraSave);
    }
Esempio n. 5
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";
        }
    }
Esempio n. 6
0
 public void addFlora(SavedFlora floraToAdd)
 {
     flora.Add(floraToAdd);
 }