// initializes run stage void InitRun() { if (stage == Stage.defend) { return; } stage = Stage.defend; nodes = GenerateNodeMap(false); // ToDo: generate second nodemap using first for better performance nodes_CanBreak = GenerateNodeMap(true); Node objectiveNode, objectiveNode_CanBreak; objectiveNode = objectiveNode_CanBreak = null; Turret.turrets.Clear(); Wall.walls.Clear(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (tiles[y, x].type == TileType.objective) { objectiveNode = nodes[y, x]; objectiveNode_CanBreak = nodes_CanBreak[y, x]; break; } } } TileType type; GameObject obj; Vector3 pos; Tile tile; // instantiate all for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { tile = tiles[y, x]; type = tile.type; obj = null; Tile.objs.TryGetValue(type, out obj); if (null == obj) { continue; } // do not instantiate obj = Instantiate(obj, tile.transform.position, Quaternion.identity); switch (type) { case TileType.ground: break; case TileType.wall: obj.GetComponent <Wall>().Set(new Index(x, y)); Wall.walls.Add(tile.transform); break; case TileType.turret: Turret.turrets.Add(obj.transform); break; case TileType.spawn: // THIS IS GROSS List <Index> tryNodeMap = pathfinder.Pathfind(nodes[y, x], objectiveNode, nodes); if (null == tryNodeMap) { tryNodeMap = pathfinder.Pathfind(nodes_CanBreak[y, x], objectiveNode_CanBreak, nodes_CanBreak); if (null == tryNodeMap) { Debug.LogError("null sec time"); } } obj.GetComponent <Spawner>().SetValues(tryNodeMap); break; case TileType.objective: break; default: return; } tile.gameObject.SetActive(false); } } }