private List <ColoredBorders> ColorRegionBorders() { //Setup List <List <ColoredVector2Int> > regionList = GetRegions(); List <ColoredBorders> cBorders = new List <ColoredBorders>(); for (int i = 0; i < regionList.Count; i++) { List <ColoredVector2Int> l = regionList[i]; ColoredBorders cBorder = new ColoredBorders(regionList[i][0].color); for (int r = 0; r < l.Count; r++) { ColoredVector2Int currentCVec = l[r]; List <Vector2Int> n = currentCVec.vector2Int.GetDirectNeighbours(mapSize); //Check if it's next to mapborder if (n.Count < 4) { cBorder.outerBorder.Add(currentCVec.vector2Int); continue; } //Checks if it's next to another color for (int t = 0; t < n.Count; t++) { if (pix.Exists(x => (x.vector2Int == n[t]) && (x.color != currentCVec.color))) { cBorder.outerBorder.Add(currentCVec.vector2Int); break; } } } for (int r = 0; r < l.Count; r++) { ColoredVector2Int currentCVec = l[r]; List <Vector2Int> n = currentCVec.vector2Int.GetDirectNeighbours(mapSize); //Checks if it's next to another color for (int t = 0; t < n.Count; t++) { if (pix.Exists(x => (x.vector2Int == n[t]) && (x.color != currentCVec.color))) { cBorder.innerBorder.Add(currentCVec.vector2Int); break; } } } cBorders.Add(cBorder); } return(cBorders); }
/// <summary> /// Apply colors to regions image to visualize the generator /// </summary> private void ApplyPixColorsToTexture() { Color[] pixels = new Color[mapSize * mapSize]; regions = new Texture2D(mapSize, mapSize); for (int i = 0; i < pix.Count; i++) { ColoredVector2Int t = pix[i]; pixels[t.vector2Int.y * mapSize + t.vector2Int.x] = t.color; } regions.SetPixels(pixels); regions.Apply(); }
private void SetPixColor(Vector2Int vec, Color col) { int index = pix.FindIndex(x => x.vector2Int == vec); pix[index] = new ColoredVector2Int(vec, col); }