//Used by PlantDB to transfer in plant info public static void CreateAndAddPlant(string plantName, GameObject plantObj) { plantInfo newPlant = new plantInfo(); newPlant.plantName = plantName; newPlant.plantObject = plantObj; plants.Add(newPlant); }
//Plants a plant at location with name plantName (matching in the PlantDB) public static bool AddPlantedLocation(Vector3Int location, string plantName, float growthRate) { if (CheckPlantedLocation(location)) { //Can plant. Find which plant to place, and create a plantWorldInfo for it plantInfo plantToPlace = new plantInfo(); plantWorldInfo worldInfo = new plantWorldInfo(); bool foundPlant = false; worldInfo.plantLocation = location; //Find the right plant in the DB foreach (plantInfo plant in plants) { if (plant.plantName.Equals(plantName)) { plantToPlace = plant; foundPlant = true; } } //If the plant exists in the DB, spawn it, create and add a plantWorldInfo record for it if (foundPlant) { worldInfo.plant = Instantiate(plantToPlace.plantObject, WorldData2.plantableLayer.GetCellCenterWorld(location), Quaternion.identity); worldInfo.plant.GetComponent <GrowVegetable>().ID = currentID; worldInfo.plant.GetComponent <GrowVegetable>().StartGrowing(growthRate); worldInfo.ID = currentID; currentID += 1; plantedLocations.Add(worldInfo); Debug.Log("Created plant with ID: " + (currentID - 1).ToString()); return(true); } //Couldn't find plant Debug.Log("here"); return(false); } else { //Couldn't place plant (Location already in use) return(false); } }