using UnityEngine; using UnityEditor; namespace SK.Framework { public class ModelImportSettings : EditorWindow { //Location类型 private ModelImporterMaterialLocation location; //菜单 [MenuItem("工具/ 批量解压模型")] private static void Open() { GetWindow("Model Import Settings").Show(); } private void OnGUI() { //水平布局 GUILayout.BeginHorizontal(); { GUILayout.Label("Location"); //EnumPopup显示选择的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); //根据路径Asset Importer并转化为Model Importer ModelImporter importer = AssetImporter.GetAtPath(path) as ModelImporter; //判断选中的物体是否为模型 if (importer != null) { //将materialLocation设为目标值 importer.materialLocation = location; } } } } //选中的物体变更时调用Repaint函数重新绘制 private void OnSelectionChange() { Repaint(); } } }