SaveFileDialog

This commit is contained in:
ousttrue
2021-04-19 18:36:03 +09:00
parent 195abfa645
commit 25ea39cd87
5 changed files with 70 additions and 90 deletions

View File

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

View File

@@ -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;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 35dc28badc82c5e4a8aa813ddd3369fe
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

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

View File

@@ -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