Unity 编辑器开发实战【Model Importer】- 如何多选设置模型导入设置中的Material Location
【摘要】
模型的Import Settings中Materials部分是不支持多选进行编辑的,如图所示,如果我们选中多个模型,编辑器中会提示Material Editing is not supported on multiple selection.
假如我们往工程中导入了大量模型,其默认的Location设置为Use Embedded ...
模型的Import Settings中Materials部分是不支持多选进行编辑的,如图所示,如果我们选中多个模型,编辑器中会提示Material Editing is not supported on multiple selection.
假如我们往工程中导入了大量模型,其默认的Location设置为Use Embedded Materials,而我们想要将其设为Use External Materials(Legacy),就需要依次选中模型、设置Location,比较耗时耗力。
本文实现的工具可以支持多选模型进行Material Location设置,如图所示:
代码如下:
-
using UnityEngine;
-
using UnityEditor;
-
-
namespace SK.Framework
-
{
-
public class ModelImportSettings : EditorWindow
-
{
-
private ModelImporterMaterialLocation location;
-
-
[MenuItem("SKFramework/Tools/Model Import Settings")]
-
private static void Open()
-
{
-
GetWindow<ModelImportSettings>("Model Import Settings").Show();
-
}
-
-
private void OnGUI()
-
{
-
GUILayout.BeginHorizontal();
-
{
-
GUILayout.Label("Location");
-
location = (ModelImporterMaterialLocation)EditorGUILayout.EnumPopup(location);
-
}
-
GUILayout.EndHorizontal();
-
-
if (Selection.gameObjects.Length == 0) return;
-
GUILayout.FlexibleSpace();
-
-
if (GUILayout.Button("Apply"))
-
{
-
for (int i = 0; i < Selection.gameObjects.Length; i++)
-
{
-
var obj = Selection.gameObjects[i];
-
string path = AssetDatabase.GetAssetPath(obj);
-
ModelImporter importer = AssetImporter.GetAtPath(path) as ModelImporter;
-
if (importer != null)
-
{
-
importer.materialLocation = location;
-
}
-
}
-
}
-
}
-
-
private void OnSelectionChange()
-
{
-
Repaint();
-
}
-
}
-
}
文章来源: coderz.blog.csdn.net,作者:CoderZ1010,版权归原作者所有,如需转载,请联系作者。
原文链接:coderz.blog.csdn.net/article/details/123656770
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)