Unity 利用TextureImport 批量修改Texture中的图片属性

很多时候,我们需要批量修改导入的图片属性,比如批量将图片的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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值