很多时候,我们需要批量修改导入的图片属性,比如批量将图片的Texture Type修改为Spire,为了节省时间,我们可以用代码来完成这一操作。
首先我们需要图片的路径,比如下面这张图片的路径就是"Assets/1.png"
然后在需要用到这张图片的地方写上下面三行代码就可以了
TextureImporter importer = (TextureImporter)AssetImporter.GetAtPath("Assets/1.png"); // 获取文件
importer.textureType = TextureImporterType.Sprite; // 修改属性
importer.SaveAndReimport(); // 一定要记得写上这句
此外,还可以修改其他的属性,比如这样
importer.wrapMode = TextureWrapMode.Clamp;
importer.textureType = TextureImporterType.Advanced;
importer.mipmapEnabled = false;
importer.maxTextureSize = 2048;
importer.textureFormat = TextureImporterFormat.PVRTC_RGB4;
其他更多属性可以看官网的说明
https://docs.unity3d.com/ScriptReference/TextureImporter.html
也可以看中文版的(虽然很久没更新了)
https://docs.unity3d.com/cn/current/ScriptReference/TextureImporter.html