public void CheckNeighBour(Vector2i coordinate) { lock (LoadedNormalTiles) { NormalTerrainTile terrainTile; if (!LoadedNormalTiles.TryGetValue(coordinate, out terrainTile)) { return; } NormalTerrainTile otherTerrain = null; Vector2i neightbourCoor; //Get Terran Left neightbourCoor = new Vector2i(coordinate.x - 1, coordinate.y); NeighBoursDirection direction = NeighBoursDirection.LEFT; if (LoadedNormalTiles.TryGetValue(neightbourCoor, out otherTerrain)) { direction = NeighBoursDirection.LEFT; //Create edge tile map EdgeTerrainTile neighbour = CreateEdgeTerrainTile(terrainTile.transform.position - transform.position); neighbour.CreateMesh(terrainTile, direction, otherTerrain); } //Get Terran Top neightbourCoor = new Vector2i(coordinate.x, coordinate.y - 1); if (LoadedNormalTiles.TryGetValue(neightbourCoor, out otherTerrain)) { direction = NeighBoursDirection.TOP; //Create edge tile map EdgeTerrainTile neighbour = CreateEdgeTerrainTile(terrainTile.transform.position - transform.position); neighbour.CreateMesh(terrainTile, direction, otherTerrain); } //Get Terran Right neightbourCoor = new Vector2i(coordinate.x + 1, coordinate.y); if (LoadedNormalTiles.TryGetValue(neightbourCoor, out otherTerrain)) { direction = NeighBoursDirection.RIGHT; //Create edge tile map EdgeTerrainTile neighbour = CreateEdgeTerrainTile(terrainTile.transform.position - transform.position); neighbour.CreateMesh(terrainTile, direction, otherTerrain); } //Get Terran Bottom neightbourCoor = new Vector2i(coordinate.x, coordinate.y + 1); if (LoadedNormalTiles.TryGetValue(neightbourCoor, out otherTerrain)) { direction = NeighBoursDirection.BOTTOM; //Create edge tile map EdgeTerrainTile neighbour = CreateEdgeTerrainTile(terrainTile.transform.position - transform.position); neighbour.CreateMesh(terrainTile, direction, otherTerrain); } } }
public EdgeTerrainTile CreateEdgeTerrainTile(Vector3 position) { GameObject aTerrain = Instantiate(tilePref, position, Quaternion.identity); aTerrain.transform.SetParent(transform, false); EdgeTerrainTile terrainTile = aTerrain.AddComponent <EdgeTerrainTile>(); terrainTile.TileGenerator = this; return(terrainTile); }