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

批量修改|导入Unity3d资源属性,帮助那些遗忘勾、选项的美术同学们 (其实我做美术的时候也一样有健忘症)

2016-07-07 16:20 531 查看
设计师的小工具|批量修改导入资源属性,帮助那些遗忘勾、选项的美术同学们 (其实我做美术的时候也一样有健忘症)

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");
}
}
}


粘贴复制固然简单,重在理解哦!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: