public void AddRoomsToMap(List <RoomsList> rooms) { // Get tilebase tiles for the room and the corridor TileBase roomTile = TilemapHelper.GetTileByType(TileType.ROOM); TileBase corridorTile = TilemapHelper.GetTileByType(TileType.CORRIDOR); BoundsInt corridorBounds; int roomY = 2; foreach (var roomList in rooms) { int roomX = 2; foreach (var room in roomList.Rooms) { var roomBounds = new BoundsInt(roomX, roomY, 0, room.Width, room.Height, 1); FillAreaWithTile(roomBounds, roomTile); corridorBounds = new BoundsInt(roomX + room.Width, roomY, 0, 1, roomList.MaxHeight, 1); FillAreaWithTile(corridorBounds, corridorTile); roomX += room.Width + 1; } roomY += roomList.MaxHeight; corridorBounds = new BoundsInt(2, roomY, 0, roomList.MaxWidth, 1, 0); roomY++; FillAreaWithTile(corridorBounds, corridorTile); } }
public void CreateTilemapFromLeafs(Tilemap tilemap) { if (Children.Count == 0) { TileBase tile = TilemapHelper.GetTileByType(Type); TilemapHelper.FillAreaWithTile(this.LeafBounds, tile, tilemap); } else { foreach (var child in Children) { child.CreateTilemapFromLeafs(tilemap); } } }
/// <summary> /// Apply a specific transformation rule to a specific tile /// </summary> /// <param name="rule">The TRANFROM_RULE to be applied to this tile</param> /// <param name="position">The position of the tile on the tilemap</param> /// <param name="neighbors">the tile's neighborhood, the 3x3 area around the tile as a 1D array</param> /// <returns></returns> public TileBase ApplyRule(TransformRule rule, Vector3Int position, TileBase[] neighbors, BoundsInt bounds) { if (rule == TransformRule.WALL_FROM_BOUNDS) { var newTileType = rules[TransformRule.WALL_FROM_BOUNDS].Apply(position, bounds); if (newTileType != null) { return(TilemapHelper.GetTileByType(newTileType)); } } if (rule == TransformRule.WALL_FROM_ADJACENTS) { var newTileType = rules[TransformRule.WALL_FROM_ADJACENTS].Apply(neighbors); if (newTileType != null) { return(TilemapHelper.GetTileByType(newTileType)); } } if (rule == TransformRule.WALL_FOR_ROOM) { var newTileType = rules[TransformRule.WALL_FOR_ROOM].Apply(neighbors); if (newTileType != null) { return(TilemapHelper.GetTileByType(newTileType)); } } if (rule == TransformRule.ROOM_FROM_ADJACENTS) { var newTileType = rules[TransformRule.ROOM_FROM_ADJACENTS].Apply(neighbors); if (newTileType != null) { return(TilemapHelper.GetTileByType(newTileType)); } } if (rule == TransformRule.FLOOR_FROM_BOUNDS) { var newTileType = rules[TransformRule.FLOOR_FROM_BOUNDS].Apply(position, bounds); if (newTileType != null) { return(TilemapHelper.GetTileByType(newTileType)); } } return(null); }
public void CreatePaths() { var rooms = evaluator.rooms; RoomArea currentRoom; RoomArea nextRoom; TileBase roomTile = TilemapHelper.GetTileByType(TileType.ROOM); for (int i = 0; i < rooms.Count; i++) { currentRoom = rooms[i]; if (i + 1 < rooms.Count) { nextRoom = rooms[i + 1]; var path = CalculatePathBetweenRooms(currentRoom, nextRoom); foreach (var position in path) { tilemap.SetTile(position, roomTile); } } } }