AssetPostprocessor.OnPostprocessTexturefunction OnPostprocessTexture (texture : Texture2D) : voidDescriptionAdd this function in a subclass to get a notification when a texture has completed importing just before the texture is saved to disk.
// Postprocesses all textures that are placed in a folder
// "invert color" to have their colors inverted. class InvertColor extends AssetPostprocessor { // Use this for initialization function OnPostprocessTexture (texture : Texture2D) { // Only post process textures if they are in a folder // "invert color" or a sub folder of it. // var lowerCaseAssetPath = assetPath.ToLower(); // if (lowerCaseAssetPath.IndexOf ("/invert color/") == -1) // return; for (var m=0;m<texture.mipmapCount;m++) { var c : Color[] = texture.GetPixels(m); for (var 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 mip map levels, you can also // modify only the pixels in the highest mip level. And then simply use // texture.Apply(true); to generate lower mip levels. } } |
