Unity3d 批量设置导入图片的属性工具
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Unity3d 批量设置导入图片的属性工具,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3329字,纯文字阅读大概需要5分钟。
内容图文
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")] privatestaticvoid Init() { Rect wr = new Rect(0, 0,200, 200); window = (TextureImportChanging)EditorWindow.GetWindowWithRect(typeof(TextureImportChanging), wr, false, "图片格式设置"); window.Show(); } privatevoid 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); } } staticvoid 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; } publicstaticvoid 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(); } }
原文:http://www.cnblogs.com/leesymbol/p/7600452.html
内容总结
以上是互联网集市为您收集整理的Unity3d 批量设置导入图片的属性工具全部内容,希望文章能够帮你解决Unity3d 批量设置导入图片的属性工具所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。