// when game started, set workers to working(upgrading)buildings public void SetWorkingBuildingWorker() { for (int i = 0; i < 10; ++i) { for (int j = 0; j < Buildings[i].Count; ++j) { // exclude if building is not working if (!Buildings[i][j].InUpgrading()) { continue; } // get free worker BEWorker Worker = BEWorkerManager.instance.GetAvailableWorker(); if (Worker != null) { AStarTile tile = GetBuidingAStarTile(Buildings[i][j]); // set worker position to building Worker.SetPosition(tile.x, tile.y); // set worker state to work Worker.SetWork(Buildings[i][j]); } } } }
void Update() { // if path calc list has item // call worker's GetPath and remove from the list if (PathCalcList.Count != 0) { BEWorker worker = PathCalcList[0]; worker.GetPath(); PathCalcList.RemoveAt(0); } }
// add worker one by one public void AddWorker() { GameObject go = (GameObject)Instantiate(prefWorker, Vector3.zero, Quaternion.identity); go.transform.SetParent(trUnitRoot); go.transform.localScale = Vector3.one; int tileX = Random.Range(0, AStar.width); int tileZ = Random.Range(0, AStar.height); BEWorker script = go.GetComponent <BEWorker>(); script.Init(this, tileX, tileZ); Workers.Add(script); //Debug.Log ("AddWorker "+go.transform.localPosition.ToString()); }
// if worker need new destination // add worker to path calc list // to avoid call astar's path find function simultaneously public void RequestPath(BEWorker worker) { PathCalcList.Add(worker); }