Example #1
0
    public DependenceAttribute GetDepComp(string name)
    {
        DependenceAttribute dep = null;

        foreach (GameObject obj in allDependencies)
        {
            if (obj.name == name)
            {
                dep = obj.GetComponent <DependenceAttribute>();
            }
        }
        return(dep);
    }
Example #2
0
    void Update()
    {
        if (!currPlant) //if no plant, set to n/a
        {
            if (nameText)
            {
                nameText.text = "N/A";
            }

            //attempt to make clone when new plant added to empty collection
            try
            {
                currPlant = makeClone();
            }
            catch (ArgumentOutOfRangeException)
            {
                navigate();         //if attempt fails, adjust index value
            }
        }

        else    //if plant collection not empty, display plant and details
        {
            if (nameText)
            {
                nameText.text = pManager.plantCollection[indexNum].name;
            }

            currPlant.transform.position = new Vector3(followPoint.transform.position.x, followPoint.transform.position.y, followPoint.transform.position.z); //set position to follow point
            currPlant.GetComponent <Timer>().timeElapsed = pManager.plantCollection[indexNum].GetComponent <Timer>().timeElapsed;                             ///time alive

            //update dependencies of clone
            string[] dependencies = { "Lighting", "Water", "Temperature", "Fertiliser" };
            foreach (string dep in dependencies)
            {
                DependenceAttribute depCompOrigin = pManager.plantCollection[indexNum].GetComponent <PlantRates>().GetDepComp(dep);
                DependenceAttribute depCompClone  = currPlant.GetComponent <PlantRates>().GetDepComp(dep);

                depCompClone.currValue = depCompOrigin.currValue;       //match dependencies between clone and origin
            }
        }

        if (prevIndexNum != indexNum)
        {
            navigate();     //adjust index
        }
    }
Example #3
0
    public void CurrentEfficiencyTest1()
    {
        string[] dependencies = { "Lighting", "Water", "Temperature", "Fertiliser" };
        foreach (PlantRates pr in plantRates)
        {
            foreach (string dep in dependencies)
            {
                DependenceAttribute depObj = pr.GetDepComp(dep);
                depObj.maxValue          = 2000f;
                depObj.minValue          = 1000f;
                depObj.optimumPercentage = 0.5f; //optimum is 1500
                depObj.currValue         = 1250f;
                depObj.dependencyAmount  = 0.25f;
                depObj.UpdateEfficiency();
            }
        }

        foreach (PlantRates pr in plantRates)
        {
            float effic = pr.GetCurrentEfficiency(pr.allDependencies);
            Assert.IsTrue(effic >= .5f && effic < .5009f, String.Format("Efficiency should be 0.5, got '{0}'", effic));
        }
    }
Example #4
0
    public void CurrentEfficiencyTest3()
    {
        string[] dependencies = { "Lighting", "Water", "Temperature", "Fertiliser" };
        foreach (PlantRates pr in plantRates)
        {
            foreach (string dep in dependencies)
            {
                DependenceAttribute depObj = pr.GetDepComp(dep);
                depObj.maxValue          = 0f;
                depObj.minValue          = 0f;
                depObj.optimumPercentage = 0.8f; //optimum is 4400
                depObj.currValue         = 1023.5f;
                depObj.dependencyAmount  = 0.25f;
                depObj.UpdateEfficiency();
                Debug.Log(pr.gameObject.name + ": " + dep + " " + depObj.dependencyEfficiency.ToString());
            }
        }

        foreach (PlantRates pr in plantRates)
        {
            float effic = pr.GetCurrentEfficiency(pr.allDependencies);
            Assert.IsTrue(effic == 0f, String.Format("Efficiency should be 0, got '{0}'", effic));
        }
    }
Example #5
0
    void Update()
    {
        if (!currPlant) //if no plant, set to n/a
        {
            timeAlive.text        = String.Format("Days Alive: {0}", "N/A");
            healthEfficiency.text = String.Format("Health: {0}", "N/A");
            nameText.text         = "N/A";

            //attempt to make clone when new plant added to empty collection
            try {
                currPlant = makeClone();
            } catch (ArgumentOutOfRangeException) {
                navigate();         //if attempt fails, adjust index value
            }
        }

        else    //if plant collection not empty, display plant and details
        {
            nameText.text = pManager.plantCollection[indexNum].name;

            var lighting   = getCurrVal("Lighting").ToString() + " lumen(s)";
            var temp       = getCurrVal("Temperature").ToString() + "°C";
            var water      = getCurrVal("Water").ToString() + " day(s)";
            var fertiliser = getCurrVal("Fertiliser").ToString() + " day(s)";

            //set text in environmental dependency fields
            lightInput.text      = lighting;
            tempInput.text       = temp;
            waterInput.text      = water;
            fertiliserInput.text = fertiliser;


            currPlant.transform.position = new Vector3(followPoint.transform.position.x, followPoint.transform.position.y, followPoint.transform.position.z); //set position to follow point
            currPlant.GetComponent <Timer>().timeElapsed = pManager.plantCollection[indexNum].GetComponent <Timer>().timeElapsed;                             ///time alive
            var numDays = pManager.plantCollection[indexNum].GetComponent <Timer>().timeElapsed;
            timeAlive.text        = String.Format("Days Alive: {0}", numDays);
            healthEfficiency.text = String.Format("Health: {0:0.00}%", pManager.plantCollection[indexNum].GetComponent <PlantRates>().currEfficiency * 100); //health efficiency

            //update dependencies of clone
            string[] dependencies = { "Lighting", "Water", "Temperature", "Fertiliser" };
            foreach (string dep in dependencies)
            {
                DependenceAttribute depCompOrigin = pManager.plantCollection[indexNum].GetComponent <PlantRates>().GetDepComp(dep);
                DependenceAttribute depCompClone  = currPlant.GetComponent <PlantRates>().GetDepComp(dep);

                depCompClone.currValue = depCompOrigin.currValue;       //match dependencies between clone and origin
            }
        }

        if (prevIndexNum != indexNum)
        {
            navigate();     //adjust index
        }

        if (indexText)      //update value in index box
        {
            if (pManager.plantCollection.Count == 0)
            {
                indexText.text = "0" + "/" + pManager.plantCollection.Count.ToString();
            }
            else
            {
                indexText.text = (indexNum + 1).ToString() + "/" + pManager.plantCollection.Count.ToString();
            }
        }

        if (currPlant && activateButton)    //update plant's activated/deactivated status
        {
            TMP_Text buttonText = activateButton.GetComponentInChildren <TMP_Text>();
            if (pManager.PlantActive(pManager.plantCollection[indexNum]))
            {
                buttonText.text = "Deactivate";
            }
            else
            {
                buttonText.text = "Activate";
            }
        }
    }