Skip to content

Commit 499ddca

Browse files
authored
Merge pull request #348 from Unity-Technologies/UNI-41963-check-filename-not-empty
UNI-41963 give error if user tries to export without filename
2 parents 5cc18f9 + 54c0cb9 commit 499ddca

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

Assets/FbxExporters/Editor/ConvertToPrefabEditorWindow.cs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections;
1+
using System.Collections;
22
using System.Collections.Generic;
33
using UnityEngine;
44
using UnityEditor;
@@ -82,24 +82,39 @@ protected override void OnEnable ()
8282
m_prefabExtLabelWidth = m_fbxExtLabelStyle.CalcSize (new GUIContent (".prefab")).x;
8383
}
8484

85-
protected override void Export ()
85+
protected override bool Export ()
8686
{
87+
if (string.IsNullOrEmpty (m_exportFileName)) {
88+
Debug.LogError ("FbxExporter: Please specify an fbx filename");
89+
return false;
90+
}
91+
92+
if (string.IsNullOrEmpty (m_prefabFileName)) {
93+
Debug.LogError ("FbxExporter: Please specify a prefab filename");
94+
return false;
95+
}
96+
8797
var fbxDirPath = ExportSettings.GetFbxAbsoluteSavePath ();
8898
var fbxPath = System.IO.Path.Combine (fbxDirPath, m_exportFileName + ".fbx");
8999

90100
var prefabDirPath = ExportSettings.GetPrefabAbsoluteSavePath ();
91101
var prefabPath = System.IO.Path.Combine (prefabDirPath, m_prefabFileName + ".prefab");
92102

103+
// check if file already exists, give a warning if it does
104+
if (!OverwriteExistingFile (fbxPath) || !OverwriteExistingFile (prefabPath)) {
105+
return false;
106+
}
107+
93108
if (ToExport == null) {
94109
Debug.LogError ("FbxExporter: missing object for conversion");
95-
return;
110+
return false;
96111
}
97112

98113
if (ToExport.Length == 1) {
99114
var go = ModelExporter.GetGameObject (ToExport [0]);
100115

101116
if (!OverwriteExistingFile (prefabPath)) {
102-
return;
117+
return false;
103118
}
104119

105120
// Only create the prefab (no FBX export) if we have selected the root of a model prefab instance.
@@ -113,19 +128,19 @@ protected override void Export ()
113128

114129
if (string.Equals(System.IO.Path.GetFullPath(fbxPath), System.IO.Path.GetFullPath(mainAssetAbsPath))) {
115130
ConvertToModel.SetupFbxPrefab(go, mainAsset, relPrefabPath, mainAssetAbsPath);
116-
return;
131+
return true;
117132
}
118133
}
119134

120135
// check if file already exists, give a warning if it does
121136
if (!OverwriteExistingFile (fbxPath)) {
122-
return;
137+
return false;
123138
}
124139

125140
ConvertToModel.Convert (
126141
go, fbxFullPath: fbxPath, prefabFullPath: prefabPath, exportOptions: ExportSettings.instance.convertToPrefabSettings.info
127142
);
128-
return;
143+
return true;
129144
}
130145

131146
foreach (var obj in ToExport) {
@@ -134,6 +149,7 @@ protected override void Export ()
134149
go, fbxDirectoryFullPath: fbxDirPath, prefabDirectoryFullPath: prefabDirPath, exportOptions: ExportSettings.instance.convertToPrefabSettings.info
135150
);
136151
}
152+
return true;
137153
}
138154

139155
protected override ExportOptionsSettingsSerializeBase SettingsObject

Assets/FbxExporters/Editor/ExportModelEditorWindow.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public void OnPresetSelectionChanged()
116116
this.Repaint ();
117117
}
118118

119-
protected abstract void Export ();
119+
protected abstract bool Export ();
120120

121121
/// <summary>
122122
/// Function to be used by derived classes to add custom UI between the file path selector and export options.
@@ -356,8 +356,9 @@ protected void OnGUI ()
356356
}
357357

358358
if (GUILayout.Button (ExportButtonName, GUILayout.Width(ExportButtonWidth))) {
359-
Export ();
360-
this.Close ();
359+
if (Export ()) {
360+
this.Close ();
361+
}
361362
}
362363
GUILayout.EndHorizontal ();
363364

@@ -509,12 +510,17 @@ protected override void OnEnable ()
509510
}
510511
}
511512

512-
protected override void Export(){
513+
protected override bool Export(){
514+
if (string.IsNullOrEmpty (m_exportFileName)) {
515+
Debug.LogError ("FbxExporter: Please specify an fbx filename");
516+
return false;
517+
}
518+
513519
var folderPath = ExportSettings.GetFbxAbsoluteSavePath ();
514520
var filePath = System.IO.Path.Combine (folderPath, m_exportFileName + ".fbx");
515521

516522
if (!OverwriteExistingFile (filePath)) {
517-
return;
523+
return false;
518524
}
519525

520526
if (IsPlayableDirector) {
@@ -528,14 +534,15 @@ protected override void Export(){
528534
// refresh the asset database so that the file appears in the
529535
// asset folder view.
530536
AssetDatabase.Refresh ();
531-
return;
537+
return true;
532538
}
533539

534540
if (ModelExporter.ExportObjects (filePath, ToExport, SettingsObject, timelineAnim: m_isTimelineAnim) != null) {
535541
// refresh the asset database so that the file appears in the
536542
// asset folder view.
537543
AssetDatabase.Refresh ();
538544
}
545+
return true;
539546
}
540547

541548
#if UNITY_2018_1_OR_NEWER

0 commit comments

Comments
 (0)