public static ColorMap ColorMapForSatelliteImage(MapData mapData) { SatelliteImage satelliteImage = SatelliteImageService.getSatelliteImage(); double scale = satelliteImage.getScale(); int textureWidth = (int)(mapData.GetWidth() * scale); int textureHeight = (int)(mapData.GetHeight() * scale); Color[] colorArray = new Color[textureWidth * textureHeight]; if (!satelliteImage.hasSatelliteImage()) { return(new ColorMap(colorArray, textureWidth, textureHeight)); } MapDataSlice slice = mapData.AsSlice(); for (int y = 0; y < textureHeight; y++) { int sliceY = (int)(slice.GetY() * scale); int flippedY = satelliteImage.texture.height - (int)(sliceY + y) - 1; Array.ConstrainedCopy(satelliteImage.texture.GetPixels((int)(slice.GetX() * scale), flippedY, textureWidth, 1), 0, colorArray, (y * textureWidth), textureWidth); } return(new ColorMap(colorArray, textureWidth, textureHeight)); }
public static ColorMap ColorMapForHeightAndAreas(MapData mapData, int lod = 0) { lod = lod == 0 ? 1 : lod * 2; int width = mapData.GetWidth(); int height = mapData.GetHeight(); MapDataSlice slice = mapData.AsSlice(); Color[] colorArray = new Color[width * height]; if (areaDisplay == null) { areaDisplay = GameObject.FindObjectOfType <AreaDisplay>(); } for (int y = 0; y < height; y += lod) { for (int x = 0; x < width; x += lod) { float currentHeight = mapData.GetSquished(x, y); float scaledPosX = (slice.GetX() + x); float scaledPosY = (slice.GetY() + y); Color areaColor = areaDisplay.GetPointColor(scaledPosX, scaledPosY); Color regionColor = GetRegionColour(currentHeight); if (areaColor != Color.clear) { regionColor = Color.Lerp(areaColor, regionColor, colorLerpValue); } for (int actualY = y; actualY < y + lod && actualY < height; actualY++) { for (int actualX = x; actualX < x + lod && actualX < width; actualX++) { colorArray[actualY * width + actualX] = regionColor; } } } } return(new ColorMap(colorArray, width, height)); }