private void PlaceAnimalOnPasture(int pastureIndex, AnimalSpecimen typeOfAnimal) { GameObject animal = GetAnimal(pastureIndex, typeOfAnimal); if (animal == null) { return; } animal.transform.position = GetRandomPositionInsideTransformBounds(pastureIndex); }
private void PopulatePasture(int pastureIndex) { AnimalSpecimen animalType = _pasturesTypes[pastureIndex]; int herdSize = _herdSizes[pastureIndex] == 0 ? Random.Range(0, _pasturesCapacities[pastureIndex]) : _herdSizes[pastureIndex]; _herdSizes[pastureIndex] = herdSize; for (int i = 0; i < herdSize; i++) { PlaceAnimalOnPasture(pastureIndex, animalType); } _herdedPastures[pastureIndex] = true; }
private GameObject GetAnimal(int pastureIndex, AnimalSpecimen typeOfAnimal) { GameObject[] pool = GetAnimalsPoolType(typeOfAnimal); for (int i = 0; i < pool.Length; i++) { if (!pool[i].activeInHierarchy) { GameObject animal = pool[i]; animal.SetActive(true); _animalsToPasturesDict[pastureIndex].Add(i); return(animal); } } return(null); }
private void DepopulatePasture(int pastureIndex) { //Debug.Log("Depopulating pasture" + pastureIndex); AnimalSpecimen typeOfAnimal = _pasturesTypes[pastureIndex]; GameObject[] pool = GetAnimalsPoolType(typeOfAnimal); for (int index = 0; index < _animalsToPasturesDict[pastureIndex].Count; index++) { int animalIndex = _animalsToPasturesDict[pastureIndex][index]; pool[animalIndex].SetActive(false); } _animalsToPasturesDict[pastureIndex].Clear(); _herdedPastures[pastureIndex] = false; }
private GameObject[] GetAnimalsPoolType(AnimalSpecimen typeOfAnimal) { switch (typeOfAnimal) { case AnimalSpecimen.Pig: { return(_pigsPool); } case AnimalSpecimen.Sheep: { return(_sheepPool); } default: { return(_cowsPool); } } }