Skip to content

Commit 0b4f048

Browse files
committed
use editor window when exporting model
- add filename text field + cancel/export buttons
1 parent 806ddc4 commit 0b4f048

File tree

2 files changed

+48
-21
lines changed

2 files changed

+48
-21
lines changed

Assets/FbxExporters/Editor/ExportModelEditorWindow.cs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,24 @@ public class ExportModelEditorWindow : EditorWindow
1616
private const float BrowseButtonWidth = 25;
1717
private const float LabelWidth = 144;
1818
private const float FieldOffset = 18;
19+
private string m_exportFileName = "";
20+
private ModelExporter.AnimationExportType m_animExportType = ModelExporter.AnimationExportType.all;
1921

20-
public static void Init ()
22+
public static void Init (string filename = "", ModelExporter.AnimationExportType exportType = ModelExporter.AnimationExportType.all)
2123
{
2224
ExportModelEditorWindow window = (ExportModelEditorWindow)EditorWindow.GetWindow <ExportModelEditorWindow>(WindowTitle, focus:true);
25+
window.SetFilename (filename);
26+
window.SetAnimationExportType (exportType);
27+
window.minSize = new Vector2 (SelectableLabelMinWidth + LabelWidth + BrowseButtonWidth, 100);
2328
window.Show ();
29+
}
2430

25-
window.minSize = new Vector2 (SelectableLabelMinWidth + LabelWidth + BrowseButtonWidth, 100);
31+
public void SetFilename(string filename){
32+
m_exportFileName = filename;
33+
}
34+
35+
public void SetAnimationExportType(ModelExporter.AnimationExportType exportType){
36+
m_animExportType = exportType;
2637
}
2738

2839
void OnGUI ()
@@ -80,6 +91,40 @@ void OnGUI ()
8091
}
8192

8293
GUILayout.EndHorizontal();
94+
95+
GUILayout.BeginHorizontal ();
96+
EditorGUILayout.LabelField(new GUIContent(
97+
"Export Name:",
98+
"Filename to save model to."),GUILayout.Width(LabelWidth - FieldOffset));
99+
100+
m_exportFileName = EditorGUILayout.TextField (m_exportFileName);
101+
if (!m_exportFileName.EndsWith (".fbx")) {
102+
m_exportFileName += ".fbx";
103+
}
104+
m_exportFileName = ModelExporter.ConvertToValidFilename(m_exportFileName);
105+
GUILayout.EndHorizontal ();
106+
107+
GUILayout.FlexibleSpace ();
108+
109+
GUILayout.BeginHorizontal ();
110+
GUILayout.FlexibleSpace ();
111+
if (GUILayout.Button ("Cancel")) {
112+
this.Close ();
113+
}
114+
115+
if (GUILayout.Button ("Export")) {
116+
var filePath = ExportSettings.GetAbsoluteSavePath();
117+
filePath = System.IO.Path.Combine (filePath, m_exportFileName);
118+
119+
//TODO: check if file already exists, give a warning if it does
120+
if (ModelExporter.ExportObjects (filePath, exportType: m_animExportType, lodExportType: ExportSettings.instance.lodExportType) != null) {
121+
// refresh the asset database so that the file appears in the
122+
// asset folder view.
123+
AssetDatabase.Refresh ();
124+
}
125+
this.Close ();
126+
}
127+
GUILayout.EndHorizontal ();
83128
}
84129
}
85130
}

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3564,12 +3564,6 @@ private static string MakeFileName (string basename = "test", string extension =
35643564

35653565
private static void OnExport (AnimationExportType exportType = AnimationExportType.all)
35663566
{
3567-
3568-
// Now that we know we have stuff to export, get the user-desired path.
3569-
var directory = string.IsNullOrEmpty (LastFilePath)
3570-
? Application.dataPath
3571-
: System.IO.Path.GetDirectoryName (LastFilePath);
3572-
35733567
GameObject [] selectedGOs = Selection.GetFiltered<GameObject> (SelectionMode.TopLevel);
35743568
string filename = null;
35753569
if (selectedGOs.Length == 1) {
@@ -3580,19 +3574,7 @@ private static void OnExport (AnimationExportType exportType = AnimationExportTy
35803574
: System.IO.Path.GetFileName (LastFilePath);
35813575
}
35823576

3583-
var title = string.Format ("Export Model FBX ({0})", FileBaseName);
3584-
3585-
var filePath = EditorUtility.SaveFilePanel (title, directory, filename, "fbx");
3586-
3587-
if (string.IsNullOrEmpty (filePath)) {
3588-
return;
3589-
}
3590-
3591-
if (ExportObjects (filePath, exportType: exportType, lodExportType: ExportSettings.instance.lodExportType) != null) {
3592-
// refresh the asset database so that the file appears in the
3593-
// asset folder view.
3594-
AssetDatabase.Refresh ();
3595-
}
3577+
ExportModelEditorWindow.Init (filename, exportType);
35963578
}
35973579

35983580
/// <summary>

0 commit comments

Comments
 (0)