public Polygon2D GetRoomTemplateOutline() { var tilemaps = RoomTemplateUtilsGrid2D.GetTilemaps(gameObject); var outlineTilemaps = RoomTemplateUtilsGrid2D.GetTilemapsForOutline(tilemaps); var usedTiles = RoomTemplateUtilsGrid2D.GetUsedTiles(outlineTilemaps); if (usedTiles.Count == 0) { return(null); } var minX = usedTiles.Min(x => x.x); var maxX = usedTiles.Max(x => x.x); var minY = usedTiles.Min(x => x.y); var maxY = usedTiles.Max(x => x.y) + PaddingTop; var polygonPoints = new List <Vector2Int>() { new Vector2Int(minX, minY), new Vector2Int(minX, maxY), new Vector2Int(maxX, maxY), new Vector2Int(maxX, minY), }; return(new Polygon2D(polygonPoints)); }
/// <summary> /// Gets all tiles that are not null in given tilemaps. /// </summary> /// <param name="tilemaps"></param> /// <returns></returns> public static HashSet <Vector2Int> GetUsedTiles(IEnumerable <Tilemap> tilemaps) { return(RoomTemplateUtilsGrid2D.GetUsedTiles(tilemaps)); }