批量修改|导入Unity3d资源属性,帮助那些遗忘勾、选项的美术同学们 (其实我做美术的时候也一样有健忘症)
2016-07-07 16:20
531 查看
设计师的小工具|批量修改导入资源属性,帮助那些遗忘勾、选项的美术同学们 (其实我做美术的时候也一样有健忘症)
Unity 5.3.4f1
美术导入引擎的角色、场景、特效贴图在不同的团队需要不同的unity设置属性
美术同学偶尔会遗忘某个设置,积攒多了就基本遗漏了
为了帮助美术同学能够将现有资源进行属性重置以及新增资源进行属性重置特有了此功能脚本。
一般这在后期优化时比较常见,程序大神一般忙各种编辑器哪有时间管咱这小需求,那俺就自己试试咯。
实现:
粘贴复制固然简单,重在理解哦!
Unity 5.3.4f1
美术导入引擎的角色、场景、特效贴图在不同的团队需要不同的unity设置属性
美术同学偶尔会遗忘某个设置,积攒多了就基本遗漏了
为了帮助美术同学能够将现有资源进行属性重置以及新增资源进行属性重置特有了此功能脚本。
一般这在后期优化时比较常见,程序大神一般忙各种编辑器哪有时间管咱这小需求,那俺就自己试试咯。
需求:角色模型导入的时候呢默认缩放值要1.0,不要勾选Read/Write项,默认动画类型是Generic, 开启optimizeGameObjects项(随时根据优化需求变更选项是未来主要诉求) 场景模型部分基本同上,但动画类型要默认是None(有时设计同学改忘了,就真忘了) 特效贴图部分暂时只要anisoLevel为0即可 最好能在菜单栏使用并且有快捷键(好吧快捷键是我要加的.....不似美术的需求 -.-...
以上需求可拓展,音效或者其他美术资源的属性批处理待添加 代码部分不做过多解析,基本都有注释
实现:
using UnityEngine; using UnityEditor; using System.Collections; using System.IO; /* 批量修改美术资源 功能: 1.批量修改已导入的角色、场景、特效资源属性(手动修改) 2.批量修改新增资源角色、场景、特效资源属性(自动修改) 使用:批量选中已经导入且需要修改的模型或贴图使用快捷键或者菜单栏ArtBatch即可 * 快捷键: Alt+R ---->修改角色模型 Alt+S ---->修改场景模型 Alt+F ---->修改特效贴图 */ public class ArtBatch : AssetPostprocessor { //角色模型手动设置 [MenuItem("ArtBatch/Model_Role &R")] static void ModelRole() { Debug.Log("ModelRole"); //循环查找 Object 深度资源模式 foreach (Object o in Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets)) { //非对象不继续 if (!(o is GameObject)) continue; //将o作为模型存储在mod中 GameObject mod = o as GameObject; //将mod模型路径存储在path中 string path = AssetDatabase.GetAssetPath(mod); //将路径中的模型资源导入 ModelImporter modelimporter = ModelImporter.GetAtPath(path) as ModelImporter; //模型导入后 贴图格式设置细节 modelimporter.globalScale = 1.0f; modelimporter.meshCompression = ModelImporterMeshCompression.Off; modelimporter.animationType = ModelImporterAnimationType.Generic; modelimporter.isReadable = false; modelimporter.optimizeMesh = true; modelimporter.optimizeGameObjects = true; Debug.Log("角色-重置值OK"); AssetDatabase.ImportAsset(path); } AssetDatabase.Refresh(); } //场景模型后置设置 [MenuItem("ArtBatch/Model_Scene &S")] static void ModelScene() { Debug.Log("ModelScene"); //循环查找 Object 深度资源模式 foreach (Object o in Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets)) { //非模型不继续 if (!(o is GameObject)) continue; //将o作为模型存储在Smod中 GameObject Smod = (GameObject)o; //将Smod模型路径存储在path中 string path = AssetDatabase.GetAssetPath(Smod); //将路径中的模型资源导入 ModelImporter modelimporter = (ModelImporter)ModelImporter.GetAtPath(path); //模型设置细节↓ modelimporter.globalScale = 1.0f; modelimporter.meshCompression = ModelImporterMeshCompression.Off; modelimporter.isReadable = false; modelimporter.animationType = ModelImporterAnimationType.None; Debug.Log("场景-重置值OK"); AssetDatabase.ImportAsset(path); } AssetDatabase.Refresh(); } //特效贴图后置设置 [MenuItem("ArtBatch/Texture_Fx &A")] static void Fx_Texture() { //循环查找 Object类型 深度资源模式 foreach (Object o in Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets)) { //非贴图不继续 if (!(o is Texture)) continue; //将o作为贴图存储在tex中 Texture tex = o as Texture; //将tex的贴图路径存储在path中 string path = AssetDatabase.GetAssetPath(tex); //将路径中的贴图资源导入 Debug.Log(path); TextureImporter textureImporter = AssetImporter.GetAtPath(path) as TextureImporter; //贴图格式设置细节↓ textureImporter.textureType = TextureImporterType.Advanced; textureImporter.anisoLevel = 0; Debug.Log("贴图-重置值OK"); AssetDatabase.ImportAsset(path); } AssetDatabase.Refresh(); } //新增导入资源自动设置↓ //Model-tex预设设置↓ void OnPreprocessModel() { ModelImporter modelimporter = (ModelImporter)assetImporter; //Role模型预设值↓ if (assetImporter.assetPath.Contains("/CharacterSource/")) { // 判定路径可随意修改 --->"/***/" modelimporter.globalScale = 1.0f; modelimporter.meshCompression = ModelImporterMeshCompression.Off; modelimporter.isReadable = false; modelimporter.animationType = ModelImporterAnimationType.Generic; modelimporter.optimizeGameObjects = true; Debug.Log("角色-预设值OK"); } else if (assetImporter.assetPath.Contains("/SceneSource/")) { //Scene模型预设值↓ modelimporter.globalScale = 1.0f; modelimporter.meshCompression = ModelImporterMeshCompression.Off; modelimporter.isReadable = false; modelimporter.animationType = ModelImporterAnimationType.None; Debug.Log("场景-预设值OK"); } } //特效贴图预设值↓ void OnPreprocessTexture() { if (assetPath.Contains("/GFXSource/")) { TextureImporter textureimport = (TextureImporter)assetImporter; textureimport.textureType = TextureImporterType.Advanced; textureimport.anisoLevel = 0; Debug.Log("贴图-预设值OK"); } } }
粘贴复制固然简单,重在理解哦!
相关文章推荐
- unity 调用C++库(android+jni+window dll平台实现)
- Unity支持GB2312编码的方式
- Unity 从服务器下载图片保存本地然后下次读取
- Unity游戏暂停之Update与FixedUpdate区别
- Unity判断在物体内部和相交
- Unity导出Andriod工程
- unity学习笔记~材质金属颜色对照表
- Shadow Map 原理和改进
- unity 接入移动MM (3.1.10)
- 回答“漠北黑夜”同学的问题——怎么实现切片shader?
- VS2012/2013 插件 For Unity3D Shaderlab
- 导入spine使用
- Unity:iOS可执行程序超过80MB问题及各版本IL2CPP对比
- 用Unity开发Flappy Bird
- 另类Unity热更新大法:代码注入式补丁热更新
- 构建ASP.NET MVC5+EF6+EasyUI 1.4.3+Unity4.x注入的后台管理系统(64)-WebApi与Unity注入
- unity插件开发——一个例子:简单的svn集成
- unity插件开发——AssetDatabase
- unity插件开发——Selection
- unity插件开发——MenuItem