From 25ea39cd87b9f66813e383e602197bfe164fd22c Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 19 Apr 2021 18:36:03 +0900 Subject: [PATCH] SaveFileDialog --- .../UniGLTF/ExportDialog/GltfExportWindow.cs | 51 +++++-------------- .../UniGLTF/ExportDialog/SaveFileDialog.cs | 26 ++++++++++ .../ExportDialog/SaveFileDialog.cs.meta | 11 ++++ Assets/VRM/Editor/Format/VRMExporterWizard.cs | 38 ++++---------- Assets/VRM10/Editor/Vrm10ExportDialog.cs | 34 ++++--------- 5 files changed, 70 insertions(+), 90 deletions(-) create mode 100644 Assets/UniGLTF/Editor/UniGLTF/ExportDialog/SaveFileDialog.cs create mode 100644 Assets/UniGLTF/Editor/UniGLTF/ExportDialog/SaveFileDialog.cs.meta diff --git a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/GltfExportWindow.cs b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/GltfExportWindow.cs index 10ec1b905..471470e26 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/GltfExportWindow.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/GltfExportWindow.cs @@ -171,9 +171,20 @@ namespace UniGLTF if (GUILayout.Button("Export", GUILayout.MinWidth(100))) { - OnExportClicked(m_state.ExportRoot, m_settings); - Close(); - GUIUtility.ExitGUI(); + var path = SaveFileDialog.GetPath("Save gltf", $"{m_state.ExportRoot.name}.glb", "glb", "gltf"); + if (!string.IsNullOrEmpty(path)) + { + // export + Export(m_state.ExportRoot, path, new MeshExportSettings + { + ExportOnlyBlendShapePosition = m_settings.DropNormal, + UseSparseAccessorForMorphTarget = m_settings.Sparse, + DivideVertexBuffer = m_settings.DivideVertexBuffer, + }, m_settings.InverseAxis); + // close + Close(); + GUIUtility.ExitGUI(); + } } GUI.enabled = true; @@ -212,39 +223,5 @@ namespace UniGLTF m_settingsInspector.OnInspectorGUI(); return true; } - - private static string m_lastExportDir; - static void OnExportClicked(GameObject root, GltfExportSettings settings) - { - string directory; - if (string.IsNullOrEmpty(m_lastExportDir)) - { - directory = Directory.GetParent(Application.dataPath).ToString(); - } - else - { - directory = m_lastExportDir; - } - - // save dialog - var path = EditorUtility.SaveFilePanel( - "Save vrm", - directory, - root.name + ".glb", - "glb,gltf"); - if (string.IsNullOrEmpty(path)) - { - return; - } - m_lastExportDir = Path.GetDirectoryName(path).Replace("\\", "/"); - - // export - Export(root, path, new MeshExportSettings - { - ExportOnlyBlendShapePosition = settings.DropNormal, - UseSparseAccessorForMorphTarget = settings.Sparse, - DivideVertexBuffer = settings.DivideVertexBuffer, - }, settings.InverseAxis); - } } } diff --git a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/SaveFileDialog.cs b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/SaveFileDialog.cs new file mode 100644 index 000000000..b2ed86a7b --- /dev/null +++ b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/SaveFileDialog.cs @@ -0,0 +1,26 @@ +using System.IO; +using UnityEditor; +using UnityEngine; + +namespace UniGLTF +{ + public static class SaveFileDialog + { + static string m_lastExportDir; + public static string GetPath(string title, string name, params string[] extensions) + { + string directory = m_lastExportDir; + if (string.IsNullOrEmpty(directory)) + { + directory = Directory.GetParent(Application.dataPath).ToString(); + } + + var path = EditorUtility.SaveFilePanel(title, directory, name, string.Join(",", extensions)); + if (!string.IsNullOrEmpty(path)) + { + m_lastExportDir = Path.GetDirectoryName(path).Replace("\\", "/"); + } + return path; + } + } +} diff --git a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/SaveFileDialog.cs.meta b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/SaveFileDialog.cs.meta new file mode 100644 index 000000000..1135ac002 --- /dev/null +++ b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/SaveFileDialog.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 35dc28badc82c5e4a8aa813ddd3369fe +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM/Editor/Format/VRMExporterWizard.cs b/Assets/VRM/Editor/Format/VRMExporterWizard.cs index 756b75410..1e3c5b08f 100644 --- a/Assets/VRM/Editor/Format/VRMExporterWizard.cs +++ b/Assets/VRM/Editor/Format/VRMExporterWizard.cs @@ -226,9 +226,15 @@ namespace VRM if (GUILayout.Button("Export", GUILayout.MinWidth(100))) { - OnExportClicked(m_state.ExportRoot, Meta != null ? Meta : m_tmpMeta, m_settings, m_meshes); - Close(); - GUIUtility.ExitGUI(); + var path = SaveFileDialog.GetPath("Save vrm", $"{m_state.ExportRoot.name}.vrm", "vrm"); + if (!string.IsNullOrEmpty(path)) + { + // export + VRMEditorExporter.Export(path, m_state.ExportRoot, Meta != null ? Meta : m_tmpMeta, m_settings, m_meshes.Meshes); + // close + Close(); + GUIUtility.ExitGUI(); + } } GUI.enabled = true; @@ -386,31 +392,5 @@ namespace VRM m_merger.Apply(); } } - - const string EXTENSION = ".vrm"; - private static string m_lastExportDir; - static void OnExportClicked(GameObject root, VRMMetaObject meta, VRMExportSettings settings, VRMExportMeshes meshes) - { - string directory; - if (string.IsNullOrEmpty(m_lastExportDir)) - directory = Directory.GetParent(Application.dataPath).ToString(); - else - directory = m_lastExportDir; - - // save dialog - var path = EditorUtility.SaveFilePanel( - "Save vrm", - directory, - root.name + EXTENSION, - EXTENSION.Substring(1)); - if (string.IsNullOrEmpty(path)) - { - return; - } - m_lastExportDir = Path.GetDirectoryName(path).Replace("\\", "/"); - - // export - VRMEditorExporter.Export(path, root, meta, settings, meshes.Meshes); - } } } diff --git a/Assets/VRM10/Editor/Vrm10ExportDialog.cs b/Assets/VRM10/Editor/Vrm10ExportDialog.cs index 82eee3631..9b17e33ef 100644 --- a/Assets/VRM10/Editor/Vrm10ExportDialog.cs +++ b/Assets/VRM10/Editor/Vrm10ExportDialog.cs @@ -201,9 +201,15 @@ namespace UniVRM10 if (GUILayout.Button("Export", GUILayout.MinWidth(100))) { - OnExportClicked(m_state.ExportRoot); - Close(); - GUIUtility.ExitGUI(); + var path = SaveFileDialog.GetPath("Save vrm1", $"{m_state.ExportRoot.name}.vrm", "vrm"); + if (!string.IsNullOrEmpty(path)) + { + // export + Export(m_state.ExportRoot, path); + // close + Close(); + GUIUtility.ExitGUI(); + } } GUI.enabled = true; @@ -274,30 +280,10 @@ namespace UniVRM10 string m_logLabel; - const string EXTENSION = ".vrm"; - private static string m_lastExportDir; - void OnExportClicked(GameObject root) + void Export(GameObject root, string path) { m_logLabel = ""; - string directory; - if (string.IsNullOrEmpty(m_lastExportDir)) - directory = Directory.GetParent(Application.dataPath).ToString(); - else - directory = m_lastExportDir; - - // save dialog - var path = EditorUtility.SaveFilePanel( - "Save vrm", - directory, - root.name + EXTENSION, - EXTENSION.Substring(1)); - if (string.IsNullOrEmpty(path)) - { - return; - } - m_lastExportDir = Path.GetDirectoryName(path).Replace("\\", "/"); - m_logLabel += $"export...\n"; try