public Polygon2D GetRoomTemplateOutline() { var tilemaps = RoomTemplateUtils.GetTilemaps(gameObject); var outlineTilemaps = RoomTemplateUtils.GetTilemapsForOutline(tilemaps); var usedTiles = RoomTemplateUtils.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> /// Computes a polygon from points on given tilemaps. /// </summary> /// <param name="roomTemplate"></param> /// <returns></returns> public static PolygonGrid2D GetPolygonFromRoomTemplate(GameObject roomTemplate) { var outlineHandler = roomTemplate.GetComponent <IRoomTemplateOutlineHandler>(); if (outlineHandler != null) { var polygon2d = outlineHandler.GetRoomTemplateOutline(); return(polygon2d?.GetGridPolygon()); } var tilemaps = RoomTemplateUtils.GetTilemaps(roomTemplate); var outline = RoomTemplateUtils.GetTilemapsForOutline(tilemaps); return(GetPolygonFromTilemaps(outline)); }
/// <summary> /// Computes a polygon from points on given tilemaps. /// </summary> /// <param name="tilemaps"></param> /// <returns></returns> public static PolygonGrid2D GetPolygonFromTilemaps(ICollection <Tilemap> tilemaps) { var usedTiles = GetUsedTiles(RoomTemplateUtils.GetTilemapsForOutline(tilemaps)); return(GetPolygonFromTiles(usedTiles)); }