1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| private Texture2D GenerateMapTexture(int[,] cellTextureIndexMap,Texture2D groundTexture, Texture2D[] marshTextures) { int mapWidth = cellTextureIndexMap.GetLength(0); int mapHeight = cellTextureIndexMap.GetLength(1); int textureCellSize = groundTexture.width; Texture2D mapTexture = new Texture2D(mapWidth*textureCellSize, mapHeight*textureCellSize); for (int y = 0; y < mapHeight; y++) { int offsetY = y * textureCellSize; for (int x = 0; x < mapWidth; x++) { int offsetX = x * textureCellSize; int textureIndex = cellTextureIndexMap[x, y]-1; for (int y1=0;y1<textureCellSize;y1++) { for(int x1=0; x1 < textureCellSize; x1++) { if (textureIndex <= 0) { Color color = groundTexture.GetPixel(x1, y1); mapTexture.SetPixel(x1 + offsetX, y1 + offsetY, color); } else { Color color = marshTextures[textureIndex].GetPixel(x1, y1); if (color.a==0) { mapTexture.SetPixel(x1 + offsetX, y1 + offsetY, groundTexture.GetPixel(x1,y1)); } else { mapTexture.SetPixel(x1 + offsetX, y1 + offsetY, color); } } } } } } mapTexture.filterMode = FilterMode.Point; mapTexture.wrapMode = TextureWrapMode.Clamp; mapTexture.Apply(); return mapTexture; }
|