Unity小工具一 自动改变导入图片类型为sprite模式

背景

Unity中导入图片图片大都需要使用手动改为spirit模式,尤其是制作二维游戏时,所以制作一个小工具,将导入Unity的所有图片模式都改变为sprite模式

编写过程

1、新建文件夹Editor
2、创建脚本TextureSettings

using UnityEditor;

//继承导入过程类
public class TextureSettings :AssetPostprocessor
{
    private void OnPreprocessTexture()
    {
        //获取导入的对象
        TextureImporter importer = (TextureImporter)assetImporter;
        //改变图片的类型
        importer.textureType = TextureImporterType.Sprite;
    }
}

虽然功能很小,但是不用手动去改变了,很耐斯!!!!!!

升级版

只改变导入到sprites文件夹下的图片,判断文件路径就行了:

using UnityEditor;
using UnityEngine;

public class SpriteProcessor : AssetPostprocessor
{
    private void OnPostprocessTexture(Texture2D texture)
    {
        if (assetPath.ToLower().IndexOf("/sprites/") != -1)
        {
            TextureImporter textureImporter = (TextureImporter)assetImporter;
            textureImporter.textureType = TextureImporterType.Sprite;
            textureImporter.spriteImportMode = SpriteImportMode.Single;
            textureImporter.alphaIsTransparency = true;
            textureImporter.mipmapEnabled = false;
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值