AssetPostprocessor.OnPostprocessTexture 在导入纹理之后
function OnPostprocessTexture (texture : Texture2D) : void
Description描述
Add 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.
// 代替为mipmap各级设置像素,
// 你也可以只修改最高层mipmap的像素点.之后用
// texture.Apply(true);生成低层mip
}
}
最后修改:2011年1月8日 Saturday 22:15