淘先锋技术网

首页 1 2 3 4 5 6 7

 批量解压模型格式!

尊重原著:(1条消息) Unity 编辑器开发实战【Model Importer】- 如何多选设置模型导入设置中的Material Location_unity modelimporter_CoderZ1010的博客-CSDN博客

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