private bool ExtractMaterialsGUI() { using (new EditorGUILayout.HorizontalScope()) { EditorGUILayout.PrefixLabel(Styles.Materials); using (new EditorGUI.DisabledScope(!CanExtractEmbeddedMaterials())) { if (GUILayout.Button(Styles.ExtractEmbeddedMaterials)) { // use the first target for selecting the destination folder, but apply that path for all targets string destinationPath = (target as ModelImporter).assetPath; destinationPath = EditorUtility.SaveFolderPanel("Select Materials Folder", FileUtil.DeleteLastPathNameComponent(destinationPath), ""); if (string.IsNullOrEmpty(destinationPath)) { // cancel the extraction if the user did not select a folder return(false); } destinationPath = FileUtil.GetProjectRelativePath(destinationPath); //Where all the required embedded materials are not in the asset database, we need to reimport them if (!AllEmbeddedMaterialsAreImported()) { if (EditorUtility.DisplayDialog(L10n.Tr("Are you sure you want to re-extract the Materials?"), L10n.Tr("In order to re-extract the Materials we'll need to reimport the mesh, this might take a while. Do you want to continue?"), L10n.Tr("Yes"), L10n.Tr("No"))) { ReimportEmbeddedMaterials(); } else { return(false); } } try { // batch the extraction of the textures AssetDatabase.StartAssetEditing(); PrefabUtility.ExtractMaterialsFromAsset(targets, destinationPath); } finally { AssetDatabase.StopAssetEditing(); } // AssetDatabase.StopAssetEditing() invokes OnEnable(), which invalidates all the serialized properties, so we must return. return(true); } } } return(false); }
private bool ExtractMaterialsGUI() { using (new EditorGUILayout.HorizontalScope()) { EditorGUILayout.PrefixLabel(Styles.Materials); using (new EditorGUI.DisabledScope(!HasEmbeddedMaterials())) { if (GUILayout.Button(Styles.ExtractEmbeddedMaterials)) { // use the first target for selecting the destination folder, but apply that path for all targets string destinationPath = (target as ModelImporter).assetPath; destinationPath = EditorUtility.SaveFolderPanel("Select Materials Folder", FileUtil.DeleteLastPathNameComponent(destinationPath), ""); if (string.IsNullOrEmpty(destinationPath)) { // cancel the extraction if the user did not select a folder return(false); } destinationPath = FileUtil.GetProjectRelativePath(destinationPath); try { // batch the extraction of the textures AssetDatabase.StartAssetEditing(); PrefabUtility.ExtractMaterialsFromAsset(targets, destinationPath); } finally { AssetDatabase.StopAssetEditing(); } // AssetDatabase.StopAssetEditing() invokes OnEnable(), which invalidates all the serialized properties, so we must return. return(true); } } } return(false); }
private bool ExtractMaterialsGUI() { bool result; using (new EditorGUILayout.HorizontalScope(new GUILayoutOption[0])) { EditorGUILayout.PrefixLabel(ModelImporterMaterialEditor.Styles.Materials); using (new EditorGUI.DisabledScope(!this.HasEmbeddedMaterials())) { if (GUILayout.Button(ModelImporterMaterialEditor.Styles.ExtractEmbeddedMaterials, new GUILayoutOption[0])) { string text = (base.target as ModelImporter).assetPath; text = EditorUtility.SaveFolderPanel("Select Materials Folder", FileUtil.DeleteLastPathNameComponent(text), ""); if (string.IsNullOrEmpty(text)) { result = false; return(result); } text = FileUtil.GetProjectRelativePath(text); try { AssetDatabase.StartAssetEditing(); PrefabUtility.ExtractMaterialsFromAsset(base.targets, text); } finally { AssetDatabase.StopAssetEditing(); } result = true; return(result); } } } result = false; return(result); }