[unity]批量处理图片资源
来源:互联网 发布:知乎 匿名用户 编辑:程序博客网 时间:2024/05/30 02:24
原理比较简单, 原理比较简单textureImporter,直接上代码 效果为
点确定就可以
using System.Collections.Generic;using System.Linq;using UnityEngine;using UnityEditor;using System.IO;using UnityEngine.EventSystems;public class TextureImportPlatFormInfo{ public string Name; public TextureImporterFormat TextureFormat; public TextureImporterFormat HasAlphaChannelFormat; public int MaxSize; public bool isSetToggled;}public class TextureImportSetter : EditorWindow{ private string modelRootDir = Application.dataPath; public static TextureImporterFormat format = TextureImporterFormat.ETC2_RGB4; private TextureImportPlatFormInfo androidFormatInfo = new TextureImportPlatFormInfo() { MaxSize = 512, Name = "Android", TextureFormat = TextureImporterFormat.ETC2_RGB4, HasAlphaChannelFormat = TextureImporterFormat.ETC2_RGBA8 }; /// <summary> /// ios导入格式 /// </summary> private TextureImportPlatFormInfo IosFormatInfo = new TextureImportPlatFormInfo() { MaxSize = 512, Name = "iPhone", TextureFormat = TextureImporterFormat.DXT5, HasAlphaChannelFormat = TextureImporterFormat.DXT5 }; private string searchFilters = "*.tga"; private int[] formatSize = new int[]{32,64,128,256,512,1024,2048,4096}; private string[] formatDes = new[] { "32", "64", "128", "256", "512", "1024", "2048", "4096" }; /// <summary> /// 当前选中平台编号 /// </summary> private int curSelectPlatformIndex = 0 ; private bool isSelectAndroid { get { return curSelectPlatformIndex == 0; } } private bool isSelectIos { get { return curSelectPlatformIndex == 1; } } [MenuItem("Custom/SetTextureFormat")] public static void Init() { EditorWindow.GetWindow<TextureImportSetter>(); } public void OnGUI() { EditorGUILayout.BeginVertical(); if (GUILayout.Button("选择资源文件夹")) { modelRootDir = EditorUtility.OpenFolderPanel("模型根目录", modelRootDir, modelRootDir); } EditorGUILayout.LabelField("资源文件夹 : " + modelRootDir); GUILayout.BeginHorizontal(); if (GUILayout.Toggle(isSelectAndroid, androidFormatInfo.Name )) { curSelectPlatformIndex = 0; } if (GUILayout.Toggle(isSelectIos, IosFormatInfo.Name)) { curSelectPlatformIndex = 1; } GUILayout.EndHorizontal(); if (isSelectAndroid) { DrawItemUI(androidFormatInfo); } if (isSelectIos) { DrawItemUI(IosFormatInfo); } if(GUILayout.Button("确定")) { SetFormat(); } EditorGUILayout.EndVertical(); } private void DrawItemUI(TextureImportPlatFormInfo platFormInfo) { platFormInfo.MaxSize = EditorGUILayout.IntPopup("图片大小", platFormInfo.MaxSize, formatDes, formatSize); platFormInfo.TextureFormat = (TextureImporterFormat)EditorGUILayout.EnumPopup("选择格式(不含alpht通道的格式)", platFormInfo.TextureFormat); platFormInfo.HasAlphaChannelFormat = (TextureImporterFormat)EditorGUILayout.EnumPopup("选择格式(含有alpht通道的格式)", platFormInfo.HasAlphaChannelFormat); platFormInfo.isSetToggled = EditorGUILayout.Toggle("选中该平台", platFormInfo.isSetToggled); } private void SetFormat() { if (!androidFormatInfo.isSetToggled && !IosFormatInfo.isSetToggled) { Debug.LogError("无设置打包平台"); return; } var paths = Directory.GetFiles(modelRootDir,"*.*", SearchOption.AllDirectories).Where( s =>s.EndsWith(".png")|| s.EndsWith(".tga")|| s.EndsWith(".jpg") ) .ToArray(); float progress = 0; for (int i = 0;i<paths.Length;i++) { string absultepath = paths[i].Replace(Application.dataPath, "Assets"); progress =((float)i) /paths.Length; EditorUtility.DisplayProgressBar("修改图片中..", absultepath, progress); TextureImporter import = AssetImporter.GetAtPath(absultepath) as TextureImporter; if(import == null)continue; Texture2D textureFile = AssetDatabase.LoadAssetAtPath(absultepath, typeof(Texture2D)) as Texture2D; Debug.LogError(textureFile.width); import.textureType = TextureImporterType.Advanced; bool isHaveAlphaChannel = import.DoesSourceTextureHaveAlpha(); if (androidFormatInfo.isSetToggled) { import.SetPlatformTextureSettings(androidFormatInfo.Name, androidFormatInfo.MaxSize, isHaveAlphaChannel ? androidFormatInfo.HasAlphaChannelFormat : androidFormatInfo.TextureFormat); } if (IosFormatInfo.isSetToggled) { import.SetPlatformTextureSettings(IosFormatInfo.Name, IosFormatInfo.MaxSize, isHaveAlphaChannel ? IosFormatInfo.HasAlphaChannelFormat : IosFormatInfo.TextureFormat); } import.anisoLevel = 1; AssetDatabase.ImportAsset(absultepath); } EditorUtility.ClearProgressBar(); EditorUtility.DisplayDialog("设置完毕", "设置完毕", "OK"); } public void OnEnable() { this.modelRootDir = Application.dataPath; this.title = "模型贴图格式设置"; }}
0 0
- [unity]批量处理图片资源
- 【Unity】批量处理Unity中的图片资源
- 批量处理图片
- Photoshop 批量处理图片
- 图片批量处理
- matlab 批量处理图片
- python批量图片处理
- matlab 图片批量处理
- 图片批量处理
- java -- 批量处理图片
- unity图片模糊处理
- Unity读取本地图片资源
- unity 图片资源导入优化
- Unity读取本地图片资源
- Unity读取本地图片资源
- android 处理图片资源
- QT 图片资源处理
- Android图片资源处理
- appium
- webpack成功引入d3 v4的两种方式
- MyBatis一对多映射实现方式
- 双飞翼布局
- sed使用
- [unity]批量处理图片资源
- 使用jQuery的data读取标签缓存数据 ( 二 )
- 软件下载地址
- JAVA总结系列(一)JVM概要
- python下ssh及sftp登录
- 2016.12.21C语言概述+linux下的C语言编程
- java中数据结构
- 在canvas中应用font-awesome字体
- javascript字典数据结构Dictionary实现