Hi guys,
I tried to change the texture format of assetbundles to use proper textures for each graphic devices. (ETC, DXT, PVRTC, ATC). So I followed the steps in “Unity - Manual: Building AssetBundles”
However Binary data of texture(PVRTC)bundle is equal to others(RTC, ATC,DXT)
Here is the function I used to change the texture format during building assetbundle.
void OnPreprocessTexture()
{
if (TGDistributeSystemWindow.IsNowBuilding == false)
{
return;
}
TextureImporter textureImporter = assetImporter as TextureImporter;
TextureImporterFormat newFormat = TextureImporterFormat.Alpha8;
TextureImporterFormat OriTexFormat = TextureImporterFormat.Alpha8;
if (textureFormat == TextureImporterFormat.ETC_RGB4)
{
if (textureImporter.DoesSourceTextureHaveAlpha() == false)
{
newFormat = TextureImporterFormat.ETC_RGB4;
}
else
{
newFormat = TextureImporterFormat.RGBA16;
}
}
else if (textureFormat == TextureImporterFormat.PVRTC_RGB4)
{
if (textureImporter.DoesSourceTextureHaveAlpha() == false)
{
newFormat = TextureImporterFormat.PVRTC_RGB4;
}
else
{
newFormat = TextureImporterFormat.PVRTC_RGBA4;
}
}
else if (textureFormat == TextureImporterFormat.ATC_RGB4)
{
if (textureImporter.DoesSourceTextureHaveAlpha() == false)
{
newFormat = TextureImporterFormat.ATC_RGB4;
}
else
{
newFormat = TextureImporterFormat.RGBA16;
}
}
else if (textureFormat == TextureImporterFormat.DXT5)
{
if (textureImporter.DoesSourceTextureHaveAlpha() == false)
{
newFormat = TextureImporterFormat.DXT1;
}
else if(textureImporter.assetPath.Contains("ExportResources/UI/") && TGDistributeSystemWindow.CurBuildTarget == BuildTarget.StandaloneWindows)
{
newFormat = TextureImporterFormat.RGBA32;
}
else
{
newFormat = TextureImporterFormat.DXT5;
}
}
//textureImporter.textureFormat = newFormat;
int maxtexSize;
textureImporter.textureType = TextureImporterType.Advanced;
textureImporter.generateMipsInLinearSpace = false;
if (textureImporter.assetPath.Contains("UI/"))
{
textureImporter.filterMode = FilterMode.Bilinear;
}
else
{
textureImporter.filterMode = FilterMode.Bilinear;
}
textureImporter.GetPlatformTextureSettings(TGDistributeSystemWindow.BuildingTarget.ToString(), out maxtexSize, out OriTexFormat);
if (newFormat != OriTexFormat)
{
textureImporter.SetPlatformTextureSettings(TGDistributeSystemWindow.BuildingTarget.ToString(), maxtexSize, newFormat);
}
}