public void Label() { foreach (List <Region> cluster in Clusters) { List <List <GraphNode> > clusterBorders = PolygonMapFunctions.FindOutsideNodes(cluster.Select(x => x.Polygon).ToList()); GameObject clusterLabel = CenterlineLabler.LabelPolygon(clusterBorders, Name, SecondaryColor); RegionLabels.Add(clusterLabel); } }
/// <summary> /// Creates a GameObject with a mesh that represents the bounds of multiple polygons. onOutside means the border will be drawn on the outside of the polygons. /// All given polygons must be connected by land for this function to work! If they are not, first split it into clusters with PolygonMapFunctions.FindClusters() /// </summary> public static List <GameObject> CreatePolygonGroupBorder(List <GraphPolygon> polygons, float width, Color c, bool onOutside, float yPos) { List <GameObject> borders = new List <GameObject>(); // Find outer mesh vertices List <List <GraphNode> > outerNodes = PolygonMapFunctions.FindOutsideNodes(polygons); List <GraphNode> outsideBorder = outerNodes.First(x => x.Count == outerNodes.Max(y => y.Count)); foreach (List <GraphNode> border in outerNodes) { List <Vector2> outerVertices = border.Select(x => x.Vertex).ToList(); bool isClockwise = GeometryFunctions.IsClockwise(outerVertices); if (border == outsideBorder) { borders.Add(CreateSinglePolygonBorder(border, width, c, yPos, onOutside ? !isClockwise : isClockwise)); } else { borders.Add(CreateSinglePolygonBorder(border, width, c, yPos, onOutside ? isClockwise : !isClockwise)); } } return(borders); }