/// <summary> /// Gets terrain metallic gloss map texture array containing each terrain tile in a seperate array slice. /// </summary> /// <param name="archive">Archive index.</param> /// <param name="stayReadable">Texture should stay readable.</param> /// <param name="nonAlphaFormat">Non-alpha TextureFormat.</param> /// <returns>Texture2DArray or null</returns> public Texture2DArray GetTerrainMetallicGlossMapTextureArray( int archive, bool stayReadable = false, SupportedNonAlphaTextureFormats nonAlphaFormat = SupportedNonAlphaTextureFormats.RGB24) { Color32[] defaultMetallicGlossMap; // Load texture file and check count matches terrain tiles TextureFile textureFile = new TextureFile(Path.Combine(Arena2Path, TextureFile.IndexToFileName(archive)), FileUsage.UseMemory, true); int numSlices = 0; if (textureFile.RecordCount == 56) { numSlices = textureFile.RecordCount; } else { return(null); } Texture2DArray textureArray; int width; int height; // try to import first replacement texture for tile archive to determine width and height of replacement texture set (must be the same for all replacement textures for Texture2DArray) if (TextureReplacement.CustomMetallicGlossExist(archive, 0, 0)) { Texture2D metallicGlossMap = TextureReplacement.LoadCustomMetallicGloss(archive, 0, 0); width = metallicGlossMap.width; height = metallicGlossMap.height; } else { // create default texture array (1x1 texture) width = 1; height = 1; } textureArray = new Texture2DArray(width, height, numSlices, TextureFormat.ARGB32, MipMaps); defaultMetallicGlossMap = new Color32[width * height]; for (int i = 0; i < width * height; i++) { defaultMetallicGlossMap[i] = new Color32(0, 0, 0, 255); } // Rollout tiles into texture array for (int record = 0; record < textureFile.RecordCount; record++) { Texture2D metallicGlossMap; // Import custom texture(s) if (TextureReplacement.CustomMetallicGlossExist(archive, record, 0)) { metallicGlossMap = TextureReplacement.LoadCustomMetallicGloss(archive, record, 0); } else { //continue; metallicGlossMap = new Texture2D(width, height, TextureFormat.ARGB32, MipMaps); metallicGlossMap.SetPixels32(defaultMetallicGlossMap); } // enforce that all custom metallicgloss map textures have the same dimension (requirement of Texture2DArray) if ((metallicGlossMap.width != width) || (metallicGlossMap.height != height)) { Debug.LogErrorFormat("Terrain: failed to inject metallicgloss maps for archive {0}, incorrect size at record {1}.", archive, record); return(null); } // Insert into texture array textureArray.SetPixels32(metallicGlossMap.GetPixels32(), record, 0); } textureArray.Apply(true, !stayReadable); // Change settings for these textures textureArray.wrapMode = TextureWrapMode.Clamp; textureArray.anisoLevel = 8; return(textureArray); }