private void SetRegions() { Dictionary <Vector2Int, Vertex> posToVertex = new Dictionary <Vector2Int, Vertex>(); List <Region> regions = new List <Region>(); foreach (Vector2 sitePos in voronoi.SiteCoords()) { List <Vertex> vertices = new List <Vertex>(); foreach (Vector2Int vertPos in MathVert.ToVector2Int(voronoi.Region(sitePos))) { //Drawer.DrawHLine(edgePos, Color.blue); if (!posToVertex.ContainsKey(vertPos)) { posToVertex.Add(vertPos, new Vertex(vertPos)); } vertices.Add(posToVertex[vertPos]); } Region region = new Region(sitePos, vertices.ToArray()); siteToRegion[sitePos] = region; regions.Add(region); } foreach (Vector2 site in voronoi.SiteCoords()) { foreach (Vector2 nSite in voronoi.NeighborSitesForSite(site)) { siteToRegion[site].neighbours.Add(siteToRegion[nSite]); } } this.regions = regions.ToArray(); RegionsInfo.regions = this.regions; RegionsInfo.UpdateRegionsMap(); }
private void SetGround() { // Set ground & water flags foreach (Region region in RegionsInfo.regions) { Vector2Int site = MathVert.ToVector2Int(region.site); if (waterMask[site.x, site.y] < 1) { region.type.MarkAsWater(); } else { region.type.MarkAsGround(); } } }