AssetPostprocessor.OnPreprocessTexture()

Switch to Manual

Description

Add this function in a subclass to get a notification just before the texture importer is run.

借助此函数,您可以设置导入设置的默认值。

如果要更改纹理数据以执行 Alpha 左乘之类的操作,请使用 textureImporter.isReadable 在 OnPostprocessTexture 中将纹理标记为可读。

如果要更改纹理的压缩格式,请在此处更改。


using UnityEngine;
using UnityEditor;

// Automatically convert any texture file with "_bumpmap" // in its file name into a normal map.

class MyTexturePostprocessor : AssetPostprocessor { void OnPreprocessTexture() { if (assetPath.Contains("_bumpmap")) { TextureImporter textureImporter = (TextureImporter)assetImporter; textureImporter.convertToNormalmap = true; } } }