将此函数添加到子类中,以便在 Unity 压缩 3D 纹理之前,在纹理 3D 完成导入后收到通知。
您目前无法选择压缩格式。如果您想根据纹理的文件名或其他属性更改压缩格式,请使用 AssetPostprocessor.OnPreprocessTexture。
但是,如果您以这种方式修改 TextureImporter 设置,它不会对 Unity 当前正在导入的纹理产生影响,但它会在 Unity 下次导入此纹理时应用。这会导致不可预测的结果。
using UnityEditor; using UnityEngine; using System.Collections;
// Postprocesses all 3D textures that are placed in a folder // "invert color" to have their colors inverted. public class InvertColor : AssetPostprocessor { void OnPostprocessTexture3D(Texture3D texture) { // Only post process 3D textures if they are in a folder // "invert color" or a sub folder of it. string lowerCaseAssetPath = assetPath.ToLower(); if (lowerCaseAssetPath.IndexOf("/invert color/") == -1) return;
for (int m = 0; m < texture.mipmapCount; m++) { Color[] c = texture.GetPixels(m);
for (int i = 0; i < c.Length; i++) { c[i].r = 1 - c[i].r; c[i].g = 1 - c[i].g; c[i].b = 1 - c[i].b; } texture.SetPixels(c, m); } // Instead of setting pixels for each mipmap level, you can modify // the pixels in the highest mipmap then use texture.Apply(true); // to generate lower mip levels. } }