//make aseperate abilty out of this worker assigners? public int SetWorkerNumber(int newNumber) { //add more workers if (newNumber > currentWorkerNumber) { //first cap the number, if (PlayerManager.Instance.GetIdleWorkersNumber() < newNumber - currentWorkerNumber) { newNumber = currentWorkerNumber + PlayerManager.Instance.GetIdleWorkersNumber(); } for (int i = currentWorkerNumber; i < newNumber; i++) { B_Worker newWorker = PlayerManager.Instance.GetNearestIdleWorker(transform.position); newWorker.AssignToConstruction(this); assignedWorkers.Add(newWorker); } } else {//release them from work for (int i = currentWorkerNumber - 1; i >= newNumber; i--) { if (assignedWorkers[i] != null) { assignedWorkers[i].AssignToIdle(); } assignedWorkers.RemoveAt(i); } } currentWorkerNumber = newNumber; assignerUI.UpdateUI(newNumber); return(newNumber); }
public void OnWorkerDies(B_Worker worker) { Debug.Log("orker died"); int newWorkers = currentWorkerNumber - 1; SetWorkerNumber(newWorkers); assignedWorkers.Remove(worker); }
public B_Worker GetNearestIdleWorker(Vector3 position) { B_Worker nearestWorker = null; float nearestDistance = Mathf.Infinity; foreach (B_Worker worker in idleWorkers) { float currentDistance = (worker.entity.transform.position - position).sqrMagnitude; if (currentDistance < nearestDistance) { nearestDistance = currentDistance; nearestWorker = worker; } } return(nearestWorker); }
public void OnWorkerDies(B_Worker worker) { SetWorkerNumber(currentWorkerNumber--); assignedWorkers.Remove(worker); }
public void RemoveIdleWorker(B_Worker worker) { idleWorkers.Remove(worker); }
public void AddIdleWorker(B_Worker worker) { idleWorkers.Add(worker); }