public override void EncodeToDisk(string filePath, Texture2D texture, int quality, int mipLevels) { #if UNITY_EDITOR_WIN || UNITY_EDITOR_OSX byte[] pixelByteData = texture != null?GetImageBytes(texture) : null; if (pixelByteData == null) { Debug.LogError("Input texture is null!"); return; } int width = texture.width; int height = texture.height; ASTCCompressionQuality textureQuality = (ASTCCompressionQuality)quality; CompressTextureToFile(filePath, pixelByteData, width, height, textureQuality.ToString(), textureRate); #endif }
void StartEncoding(PVRTCCompressionQuality pvrtcQuality, ASTCCompressionQuality astcQuality, bool isPremultiplied, bool isDithered, Texture2D texture) { string rootDirectory = new DirectoryInfo(Application.dataPath).Parent.FullName; string localPath = AssetDatabase.GetAssetPath(texture); string texturePath = Path.Combine(rootDirectory, localPath); //Build new path that sits at the same spot as the original file. string textureDirectory = Path.GetDirectoryName(texturePath); // PVR string pvrPath = Path.Combine(textureDirectory, Path.GetFileNameWithoutExtension(texturePath) + TextureEncoderBase.CACHE_SUFFIX + ".pvr"); if (File.Exists(pvrPath)) { File.Delete(pvrPath); } PVRTCEncoderWrapper pvrtcEncoder = new PVRTCEncoderWrapper(); PVRTCEncoderWrapper.ApplyDither(isDithered); PVRTCEncoderWrapper.ApplyPremultiplication(isPremultiplied); pvrtcEncoder.EncodeToDisk(pvrPath, texture, (int)pvrtcQuality, 1); // ASTC string astcPath = Path.Combine(textureDirectory, Path.GetFileNameWithoutExtension(texturePath) + TextureEncoderBase.CACHE_SUFFIX + ".astc"); if (File.Exists(astcPath)) { File.Delete(astcPath); } ASTCEncoderWrapper astcEncoder = new ASTCEncoderWrapper(); ASTCEncoderWrapper.SetRate(ASTCCompressionRate.Six_bpp); astcEncoder.EncodeToDisk(astcPath, texture, (int)astcQuality, 1); }