public static GameObject loadPrey(SavedPrey preySave)
    {
        // We are essentially building the Predator object from scratch here.
        // GameObject loadedPrey = GameObject.CreatePrimitive(PrimitiveType.Cube);
        GameObject loadedPrey = Resources.Load("Prefabs/Prey") as GameObject;

        // Prey preyScriptRef = loadedPrey.AddComponent<Prey>();
        Prey preyScriptRef = loadedPrey.GetComponent <Prey>();

        // loadedPrey.GetComponent<MeshRenderer>().material = (Resources.Load("Materials/Orange", typeof(Material)) as Material);
        // loadedPrey.tag = "prey";
        // loadedPrey.transform.localScale = new Vector3(1f, 1f, 1f);

        Vector3 pos = new Vector3(preySave.xCoord, preySave.yCoord, preySave.zCoord);

        loadedPrey.transform.position = pos;

        preyScriptRef.waterLevel         = preySave.waterLevel;
        preyScriptRef.nutrientValue      = preySave.nutrientValue;
        preyScriptRef.reproductiveChance = preySave.reproductiveChance;
        preyScriptRef.reproductiveRate   = preySave.reproductiveRate;
        preyScriptRef.awareness          = preySave.awareness;


        preyScriptRef.movementSpeed           = preySave.movementSpeed;
        preyScriptRef.controlSpeed            = preySave.controlSpeed;
        preyScriptRef.consumptionRate         = preySave.consumptionRate;
        preyScriptRef.movementConsumptionRate = preySave.movementConsumptionRate;
        preyScriptRef.nutrientLevel           = preySave.nutrientLevel;

        return(loadedPrey);
    }
Exemple #2
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);
    }
Exemple #3
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";
        }
    }
    public static SavedPrey savePrey(GameObject preyObject)
    {
        Prey      preyScriptRef = preyObject.GetComponent <Prey>();
        SavedPrey preySave      = new SavedPrey();

        preySave.xCoord = preyObject.transform.position.x;
        preySave.yCoord = preyObject.transform.position.y;
        preySave.zCoord = preyObject.transform.position.z;

        preySave.waterLevel         = preyScriptRef.waterLevel;
        preySave.nutrientValue      = preyScriptRef.nutrientValue;
        preySave.reproductiveChance = preyScriptRef.reproductiveChance;
        preySave.reproductiveRate   = preyScriptRef.reproductiveRate;
        preySave.awareness          = preyScriptRef.awareness;

        preySave.movementSpeed           = preyScriptRef.movementSpeed;
        preySave.controlSpeed            = preyScriptRef.controlSpeed;
        preySave.consumptionRate         = preyScriptRef.consumptionRate;
        preySave.movementConsumptionRate = preyScriptRef.movementConsumptionRate;
        preySave.nutrientLevel           = preyScriptRef.nutrientLevel;

        return(preySave);
    }
Exemple #5
0
 public void addPrey(SavedPrey preyToAdd)
 {
     prey.Add(preyToAdd);
 }