void CreateGrid() { for (int x = 0; x < MapSize.x; x++) { for (int y = 0; y < MapSize.y; y++) { var tile = (GameObject)Instantiate(GetTile(MapTerrain[x, y]), new Vector3((x + 0.5f), 0, (y + 0.5f)), Quaternion.identity); tile.transform.parent = this.transform.FindChild("Tiles").transform; TileSelect tileSpec = (tile.GetComponent <TileSelect>()); RoadDraw thisroadDrawer = (tile.GetComponent <RoadDraw>()); tileSpec.coordinate = new Vector2(x, y); MapTiles[x, y] = tile; if (x > 0) { hideBorderY(y, x, x - 1); RoadDraw neighborsroadDrawer = (MapTiles[x - 1, y].GetComponent <RoadDraw>()); if (thisroadDrawer != null) { thisroadDrawer.UpdateConnect(MapTiles[x - 1, y].GetComponent <TileSelect>()); } if (neighborsroadDrawer != null) { neighborsroadDrawer.UpdateConnect(tileSpec); } } if (y > 0) { hideBorderX(y, y - 1, x); RoadDraw neighborsroadDrawer = (MapTiles[x, y - 1].GetComponent <RoadDraw>()); if (thisroadDrawer != null) { thisroadDrawer.UpdateConnect(MapTiles[x, y - 1].GetComponent <TileSelect>()); } if (neighborsroadDrawer != null) { neighborsroadDrawer.UpdateConnect(tileSpec); } } } } }
public void ChangeTile(int x, int y, byte id) { if (x >= 0 && x < (int)MapSize.x && y >= 0 && y < (int)MapSize.y) { Destroy(MapTiles [x, y]); MapTerrain[x, y] = id; var tile = (GameObject)Instantiate(GetTile(MapTerrain[x, y]), new Vector3((x + 0.5f), 0, (y + 0.5f)), Quaternion.identity); tile.transform.parent = this.transform.FindChild("Tiles").transform; TileSelect tileSpec = (tile.GetComponent <TileSelect>()); RoadDraw thisroadDrawer = (tile.GetComponent <RoadDraw>()); tileSpec.coordinate = new Vector2(x, y); MapTiles[x, y] = tile; if (x > 0) { hideBorderY(y, x, x - 1); RoadDraw neighborsroadDrawer = (MapTiles[x - 1, y].GetComponent <RoadDraw>()); if (thisroadDrawer != null) { thisroadDrawer.UpdateConnect(MapTiles[x - 1, y].GetComponent <TileSelect>()); } if (neighborsroadDrawer != null) { neighborsroadDrawer.UpdateConnect(tileSpec); neighborsroadDrawer.DrawConnections(); } } if (y > 0) { hideBorderX(y, y - 1, x); RoadDraw neighborsroadDrawer = (MapTiles[x, y - 1].GetComponent <RoadDraw>()); if (thisroadDrawer != null) { thisroadDrawer.UpdateConnect(MapTiles[x, y - 1].GetComponent <TileSelect>()); } if (neighborsroadDrawer != null) { neighborsroadDrawer.UpdateConnect(tileSpec); neighborsroadDrawer.DrawConnections(); } } if (x + 1 < (int)MapSize.x) { hideBorderY(y, x, x + 1); RoadDraw neighborsroadDrawer = (MapTiles[x + 1, y].GetComponent <RoadDraw>()); if (thisroadDrawer != null) { thisroadDrawer.UpdateConnect(MapTiles[x + 1, y].GetComponent <TileSelect>()); } if (neighborsroadDrawer != null) { neighborsroadDrawer.UpdateConnect(tileSpec); neighborsroadDrawer.DrawConnections(); } } if (y + 1 < (int)MapSize.y) { hideBorderX(y, y + 1, x); RoadDraw neighborsroadDrawer = (MapTiles[x, y + 1].GetComponent <RoadDraw>()); if (thisroadDrawer != null) { thisroadDrawer.UpdateConnect(MapTiles[x, y + 1].GetComponent <TileSelect>()); } if (neighborsroadDrawer != null) { neighborsroadDrawer.UpdateConnect(tileSpec); neighborsroadDrawer.DrawConnections(); } } } }