Unity3d 批量设置导入图片的属性工具

using UnityEngine;
using UnityEditor;
public class TextureImportChanging : EditorWindow
{
    enum MaxSize
    {
        Size_32 = 32,
        Size_64 = 64,
        Size_128 = 128,
        Size_256 = 256,
        Size_512 = 512,
        Size_1024 = 1024,
        Size_2048 = 2048,
        Size_4096 = 4096,
        Size_8192 = 8192,

    }

    // ----------------------------------------------------------------------------
    TextureImporterType textureType = TextureImporterType.Sprite;
    TextureImporterFormat textureFormat = TextureImporterFormat.Automatic;
    MaxSize textureSize = MaxSize.Size_512;
    TextureImporterCompression textureCompression = TextureImporterCompression.Uncompressed;

    bool ifAllowsAlphaSplitting = true;
    bool ifMipmapEnabled = false;

    float secs = 10.0f;
    double startVal = 0;
    float progress = 0f;

    static TextureImportChanging window;
    [@MenuItem("Custom/Texture Settings")]
    private static void Init()
    {
        Rect wr = new Rect(0, 0,200, 200);
        window = (TextureImportChanging)EditorWindow.GetWindowWithRect(typeof(TextureImportChanging), wr, false, "图片格式设置");
        window.Show();
    }

    private void OnGUI()
    {
        EditorGUILayout.Space();
        EditorGUILayout.HelpBox("设置选中图片或选中路径下的图片属性",MessageType.Info);
        EditorGUILayout.Space();

        textureType = (TextureImporterType)EditorGUILayout.EnumPopup("类型:", textureType);
        textureFormat = (TextureImporterFormat)EditorGUILayout.EnumPopup("格式:", textureFormat);
        textureSize = (MaxSize)EditorGUILayout.EnumPopup("尺寸:", textureSize);
        textureCompression = (TextureImporterCompression)EditorGUILayout.EnumPopup("压缩:", textureCompression);
        ifAllowsAlphaSplitting = EditorGUILayout.Toggle("是否允许透明分离:",ifAllowsAlphaSplitting);
        ifMipmapEnabled = EditorGUILayout.Toggle("是否允许Mipmap:", ifMipmapEnabled);

        EditorGUILayout.Space();

        if (GUILayout.Button("设置"))
        {
            TextureImporterPlatformSettings t = new TextureImporterPlatformSettings();

            t.allowsAlphaSplitting = ifAllowsAlphaSplitting;
            t.format = textureFormat;

            t.maxTextureSize = (int)textureSize;
            t.textureCompression = textureCompression;

            SelectedChangeTextureFormatSettings(t, textureType);
        }

    }

    static void SelectedChangeTextureFormatSettings(TextureImporterPlatformSettings _t, TextureImporterType  _type)
    {

        Object[] textures = GetSelectedTextures();
        if (window == null)
            Init();
        if (textures != null)
        {
            if(textures.Length < 1)
            {
                window.ShowNotification(new GUIContent("找不到图片!"));
                return;
            }
        }
        else
        {
            window.ShowNotification(new GUIContent("请选中图片或路径!"));
            return;
        }
        Selection.objects = new Object[0];
        int i = 0;
        foreach (Texture2D texture in textures)
        {
            string path = AssetDatabase.GetAssetPath(texture);
            //Debug.Log("path: " + path);
            TextureImporter textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;
            textureImporter.textureType = _type;
            textureImporter.SetPlatformTextureSettings("Android",_t.maxTextureSize,_t.format,_t.allowsAlphaSplitting);

            ShowProgress((float)i / (float)textures.Length, textures.Length, i);
            i++;
            AssetDatabase.ImportAsset(path);

        }
        AssetDatabase.Refresh();
        EditorUtility.ClearProgressBar();
        textures = null;
    }
    public static void ShowProgress(float val, int total, int cur)
    {
        EditorUtility.DisplayProgressBar("设置图片中...",string.Format("请稍等({0}/{1}) ", cur, total), val);
    }

    static Object[] GetSelectedTextures()
    {
        return Selection.GetFiltered(typeof(Texture2D), SelectionMode.DeepAssets);
    }
    void OnInspectorUpdate()
    {
        Repaint();
    }
}
  

时间: 2024-08-23 05:36:43

Unity3d 批量设置导入图片的属性工具的相关文章

[转]iOS:批量导入图片和视频到模拟器的相册

IOS开发中我们经常会用到模拟器调试,模拟器有个主要的好处就是程序启动块,最重要的是如果没有证书的话,我们就只能在模拟器上调试了.使用模拟器调试时我们可能碰到需要从系统相册选择图片的情况,特别是做图片处理类相关的程序时,更是经常用到. 初始化情况下模拟器中的相册中是空的,所以要想选择,我们就得先导入一些图片.通常的做法是将图片直接拖拽到模拟器上,然后模拟器就会用safari打开,这个时候我们再长按图片就会弹出保存到系统相册的菜单了,这样一个完整的图片保存流程就完成了.但是这中方法有一个明显的缺点

css网页中设置背景图片的方法详解

css网页中设置背景图片的方法详解 在css代码中设置背景图片的方法,包括背景图片.背景重复.背景固定.背景定位等 用css设置网页中的背景图片,主要有如下几个属性: 1,背景颜色 {background-color:数值}2,背景图片 {background-image: url(URL)|none}3,背景重复 {background-repeat:inherit|no-repeat|repeat|repeat-x|repeat-y}4,背景固定 {background-attachment

Unity3D 批量修改贴图导入设置工具脚本

这个Unity3D 批量修改贴图导入设置工具脚本十分小巧,但是威力大.特别针对大批量贴图要调整尺寸等等的时候作用尤为明显.在菜单中添加"Custom→Texture"的方式来批量改变所选的贴图导入设置.Unity本身只能一次打开一张图片进行导入设置,目前这个脚本可以批量更改贴图格式,是否开启MipMap,调整纹理最大尺寸,是否可读等等. 用法是把脚本放在你项目的资源目录的Editor文件夹下.然后选择你要批处理的纹理.到菜单中选择要处理的类型就可以了.ChangeTextureImpo

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

Unity3d 的新版 UI 系统在给我们带来很大便利的同时,也添加了一些小麻烦.每次从电脑中导入图片到 Unity3d 中都需要手动设置Texture Type为Sprite (2D and UI) 及设置 Packing Tag.对于需要打包为一个图集的图片,我们一般把它们放到一个文件夹中. 基于以上,我们可以让图片的 Packing Tag 自动设置为 文件夹的名字. 转自http://blog.csdn.net/huutu http://www.thisisgame.com.cn Uni

文件处理工具 gif合成工具 文件后缀批量添加工具 文件夹搜索工具 重复文件查找工具 网页图片解析下载工具等

以下都是一些简单的免费分享的工具,技术支持群:592132877,提供定制化服务开发. Gif动图合成工具 主要功能是扫描指定的文件夹里的所有zip文件,然后提取Zip文件中的图片,并合成一张gif图片,存储到新的路径下,支持设置gif的时间,演示效果如下: 下载地址:gif合成工具 文件批量移动工具 主要功能是将指定文件夹及子文件夹里所有文件,复制到新的文件夹下,可以指定是否删除源文件.以下动图演示效果. 下载地址:文件批量移动工具.exe 文件批量移动工具 主要功能是将指定目录下所有文件按照

图片转文字工具怎样进行批量识别?

图片转换文字相信大家都不陌生,往往的图片转文字工具都可以进行识别图片文字,如果我们有大批量的图片需要识别的话,是否还是一张一张的进行识别呢?这样的话,也会有些麻烦的呀!今天小编为大家分享一下怎样在图片转文字工具中进行图片的批量识别. 第一步:打开我们的图片转文字工具,在该工具的页面中显示有多种功能供我们选择,今天我们需要点击"批量识别"功能. 第二步:在进入批量识别的页面中后,就可以点击"添加文件夹".把准备识别的许多图片整理到一个文件夹里,进行添加后就可显示多张图

WPF设置VistualBrush的Visual属性制作图片放大镜效果

原文:WPF设置VistualBrush的Visual属性制作图片放大镜效果 效果图片: 原理:设置VistualBrush的Visual属性,利用它的Viewbox属性进行缩放. XAML代码:// Window1.xaml<Window x:Class="MagnifyingGlass.Window1"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns

json批量设置DIV属性

<!doctype html> <html> <head> <meta charset="utf-8"> <title>批量设置</title> <style> #div1 { width:200px; height:200px; border:5px solid red; } </style> <script> window.onload=function (){ var oD

PHP 图片上传工具类(支持多文件上传)

====================ImageUploadTool======================== <?php class ImageUploadTool { private $file; //文件信息 private $fileList; //文件列表 private $inputName; //标签名称 private $uploadPath; //上传路径 private $fileMaxSize; //最大尺寸 private $uploadFiles; //上传文件