private static void ModifyTexture(this Material material, string propertyName, Texture2D newTexture)
{
var currentTexture = material.GetTexture(propertyName) as Texture2D;
if (currentTexture == null)
{
return;
}
var needCompression = currentTexture.format == TextureFormat.DXT1 ||
currentTexture.format == TextureFormat.DXT5;
if (!needCompression)
{
needCompression = newTexture.format != TextureFormat.DXT1 &&
newTexture.format != TextureFormat.DXT5;
}
if (needCompression)
{
newTexture.Compress(false);
}
material.SetTexture(propertyName, newTexture);
}