您的位置:首页 > 移动开发 > Unity3D

【Unity】像素图片导入批处理

2017-01-06 15:58 417 查看
具体可以参照 Unity3d 官方文档。

http://docs.unity3d.com/ScriptReference/AssetPostprocessor.OnPreprocessTexture.html

代码出处:http://blog.csdn.net/huutu

在此基础上添加了设置Filter Mode为Point模式,可以适用于像素图片的处理

当然同样可以处理,如下图所示的所有设置



/**************************

 * 文件名:AutoSetTextureUISprite.cs;

 * 文件描述:导入图片资源到Unity时,自动修改为UI 2D Sprite,自动设置打包tag 为文件夹名字;

 * 创建日期:2015/05/04;

 * Author:陈鹏;

 ***************************/

using UnityEngine;

using System.Collections;

using UnityEditor;

public class AutoSetTextureUISprite :AssetPostprocessor

{

    void OnPreprocessTexture()

    {

        //自动设置类型;

        TextureImporter textureImporter = (TextureImporter)assetImporter;

        textureImporter.textureType=TextureImporterType.Sprite;

        //自动设置打包tag;

        string dirName = System.IO.Path.GetDirectoryName(assetPath);

        Debug.Log("Import ---  "+dirName);

        string folderStr = System.IO.Path.GetFileName(dirName);

        Debug.Log("Set Packing Tag ---  "+folderStr);

        textureImporter.spritePackingTag = folderStr;

        //filtermode 自动设置为 point

        textureImporter.filterMode = FilterMode.Point;//在这里添加就可以了

    }

}

把这个.cs文件放入任意一个文件夹都是可以执行的

参考资料3的文章里面还描述了图片批处理,或者是UNITY添加快捷键的设置

文件分流:

Unity图片导入批处理  

参考资料:

1.Unity3d 导入图片 自动修改Texture Type为Sprite (2D and UI) 及设置 Packing Tag为文件夹名



2.Unity3d
导入图片 自动修改Texture Type  

3.unity使用代码修改Texture属性,一键生成精灵

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: