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"; } } }
public void MakePlantTest1() { string name = "TestPlant1"; GameObject newPlant = pmanager.MakePlant(name, "Aloe"); Assert.IsFalse(pmanager.plantCollection.Count == 0, String.Format("Plant wass added, the length should be 1. Got {0}", pmanager.plantCollection.Count)); Assert.IsFalse(pmanager.PlantActive(newPlant), String.Format("Plant '{0}' was added. It should not be active but it was", newPlant.name)); Assert.IsTrue(newPlant.name == name, String.Format("Plant '{0}' was added. It should be called {0} but it was called {1}", name, newPlant.name)); }