void OnPreprocessModel()
        {
            string filePath = System.IO.Path.GetDirectoryName(assetPath.ToLower());

            ModelImporterSettings settings = AssetDatabase.LoadAssetAtPath(filePath + "/ModelImporterSettings.asset", typeof(ModelImporterSettings)) as ModelImporterSettings;

            if (settings == null)
            {
                return;
            }
            ModelImporter modelImporter = (ModelImporter)assetImporter;

            modelImporter.globalScale          = settings.fileScale;
            modelImporter.useFileUnits         = settings.useFileScale;
            modelImporter.meshCompression      = settings.meshCompressionType;
            modelImporter.isReadable           = settings.readWriteEnabled;
            modelImporter.optimizeMesh         = settings.optimizeMesh;
            modelImporter.importBlendShapes    = settings.importBlendshapes;
            modelImporter.addCollider          = settings.generateColliders;
            modelImporter.swapUVChannels       = settings.swapUvs;
            modelImporter.generateSecondaryUV  = settings.lightmapUvs;
            modelImporter.importNormals        = settings.importerNormals;
            modelImporter.normalSmoothingAngle = settings.smoothingAngle;
            modelImporter.importTangents       = settings.importerTangents;
            modelImporter.importMaterials      = settings.importMaterials;
            modelImporter.materialName         = settings.materialNameMode;
            modelImporter.materialSearch       = settings.materialSearch;
            modelImporter.animationType        = settings.animationType;
            modelImporter.optimizeGameObjects  = settings.optimzeGameObjects;
            modelImporter.importAnimation      = settings.importAnimation;
        }
Пример #2
0
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();
            if (!isValid)
            {
                return;
            }
            GUI.enabled = true;

            DisplayGUI();

            string createButtonText = "Create Settings";

            if (settingsExist)
            {
                if (!settingsLoaded)
                {
                    LoadSettings();
                }
                createButtonText = "Update Settings";
                settingsLoaded   = true;
            }

            if (GUILayout.Button(createButtonText))
            {
                ModelImporterSettings asset = ScriptableObject.CreateInstance <ModelImporterSettings>();
                GenerateScriptableObject(asset);
                asset.hideFlags = HideFlags.NotEditable;
                AssetDatabase.CreateAsset(asset, assetPath + "/ModelImporterSettings.asset");
            }
            if (settingsExist)
            {
                if (GUILayout.Button("Delete Settings"))
                {
                    AssetDatabase.DeleteAsset(assetPath + "/ModelImporterSettings.asset");
                    settingsExist = false;
                }
            }
            if (GUILayout.Button("Reload All"))
            {
                DirectoryInfo info  = new DirectoryInfo(assetPath);
                FileInfo[]    files = info.GetFiles();
                foreach (FileInfo file in files)
                {
                    if (file.Extension != ".meta")
                    {
                        AssetDatabase.ImportAsset(assetPath + "/" + file.Name, ImportAssetOptions.ForceUpdate | ImportAssetOptions.ImportRecursive);
                    }
                }
            }
        }
Пример #3
0
 void GenerateScriptableObject(ModelImporterSettings asset)
 {
     asset.fileScale           = globalScale;
     asset.useFileScale        = useFileScale;
     asset.meshCompressionType = meshCompressionType;
     asset.readWriteEnabled    = readWriteEnabled;
     asset.optimizeMesh        = optimizeMesh;
     asset.importBlendshapes   = importBlendshapes;
     asset.generateColliders   = generateColliders;
     asset.swapUvs             = swapUVs;
     asset.lightmapUvs         = lightmapUVs;
     asset.importerNormals     = importerNormals;
     asset.smoothingAngle      = smoothingAngle;
     asset.importerTangents    = importerTangents;
     asset.importMaterials     = importMaterials;
     asset.materialNameMode    = materialNameMode;
     asset.materialSearch      = materialSearch;
     asset.animationType       = animationType;
     asset.optimzeGameObjects  = optimzeGameObjects;
     asset.importAnimation     = importAnimation;
 }
Пример #4
0
        private void LoadSettings()
        {
            ModelImporterSettings settings = (ModelImporterSettings)AssetDatabase.LoadAssetAtPath(assetPath + "/ModelImporterSettings.asset", typeof(ModelImporterSettings));

            globalScale         = settings.fileScale;
            useFileScale        = settings.useFileScale;
            meshCompressionType = settings.meshCompressionType;
            readWriteEnabled    = settings.readWriteEnabled;
            optimizeMesh        = settings.optimizeMesh;
            importBlendshapes   = settings.importBlendshapes;
            generateColliders   = settings.generateColliders;
            swapUVs             = settings.swapUvs;
            lightmapUVs         = settings.lightmapUvs;
            importerNormals     = settings.importerNormals;
            smoothingAngle      = settings.smoothingAngle;
            importerTangents    = settings.importerTangents;
            importMaterials     = settings.importMaterials;
            materialNameMode    = settings.materialNameMode;
            materialSearch      = settings.materialSearch;
            animationType       = settings.animationType;
            optimzeGameObjects  = settings.optimzeGameObjects;
            importAnimation     = settings.importAnimation;
        }