[SetUp] //called at the start of each test public void Setup() { pmanager = GameObject.Find("GameManager").GetComponent <PlantManager>(); pmanager.prefabMappings.Clear(); pmanager.allPrefabs.Clear(); pmanager.activePlants = new GameObject[pmanager.maxActivePlants]; pmanager.allPrefabs.Add("Aloe"); pmanager.allPrefabs.Add("Jade"); pmanager.allPrefabs.Add("Echeveria"); pmanager.allPrefabs.Add("Basic Plant"); int i = 0; foreach (string prefab in pmanager.allPrefabs) { GameObject plant = (GameObject)Resources.Load(PlantManager.prefabPath + prefab); pmanager.prefabMappings.Add(prefab, plant); GameObject testPlant = pmanager.MakePlant("tester" + i.ToString(), prefab); if (i < pmanager.maxActivePlants) { pmanager.SetPlantStatus(testPlant, true); } plantRates.Add(testPlant.GetComponent <PlantRates>()); i++; } }
public void ActivatePlant() { GameObject gameManager = pManager.gameObject; try //adding plant to labspace { pManager.SetPlantStatus(pManager.plantCollection[indexNum], true); gameManager.GetComponent <PopUpManager>().PopUpMessage(String.Format("'{0}' has been added to the labspace", pManager.plantCollection[indexNum].name)); } catch (ArgumentException) //no space or is active already { if (pManager.PlantActive(pManager.plantCollection[indexNum])) //remove from labspace { pManager.SetPlantStatus(pManager.plantCollection[indexNum], false); gameManager.GetComponent <PopUpManager>().PopUpMessage(String.Format("'{0}' has been removed from the labspace", pManager.plantCollection[indexNum].name)); } else //if labspace already full, prompt to swap plants { gameManager.GetComponent <PopUpManager>().SwapPlant(indexNum); } } prevIndexNum = -1; //trigger new clone of plant }
public void ActivatePlantTest() { string name = "TestPlant"; GameObject newPlant = pmanager.MakePlant(name, "Echeveria"); GameObject newPlant2 = pmanager.MakePlant(name + "(2)", "Aloe"); MonoBehaviour.print(pmanager.activePlants.Length); pmanager.SetPlantStatus(newPlant2, true); Assert.IsTrue(pmanager.PlantActive(newPlant2), String.Format("Plant '{0}' was activated. Should be true but got false", newPlant2.name)); Assert.IsFalse(pmanager.PlantActive(newPlant), String.Format("Plant '{0}' wasn't activated. Should be false but got true", newPlant.name)); }