Skip to content

Commit 0e75020

Browse files
committed
delete the fbx file created if export was cancelled
1 parent cd18aeb commit 0e75020

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

Assets/Editor/FbxExporter.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,13 @@ public int ExportAll (IEnumerable<UnityEngine.Object> unityExportSet)
383383
fbxScene.Destroy ();
384384
fbxExporter.Destroy ();
385385

386+
if(exportCancelled){
387+
Debug.LogWarning ("Export Cancelled");
388+
// delete the file that got created
389+
EditorApplication.update += DeleteFile;
390+
return 0;
391+
}
392+
386393
return status == true ? NumNodes : 0;
387394
}
388395
}
@@ -394,14 +401,38 @@ public int ExportAll (IEnumerable<UnityEngine.Object> unityExportSet)
394401
}
395402
}
396403

404+
static bool exportCancelled = false;
405+
397406
static bool ExportProgressCallback(float percentage, string status) {
398407
// Convert from percentage to [0,1].
399408
// Then convert from that to [0.5,1] because the first half of
400409
// the progress bar was for creating the scene.
401410
var progress01 = 0.5f * (1f + (percentage / 100.0f));
402411

412+
bool cancel = EditorUtility.DisplayCancelableProgressBar(ProgressBarTitle, "Exporting Scene...", progress01);
413+
414+
if (cancel) {
415+
exportCancelled = true;
416+
}
417+
403418
// Unity says "true" for "cancel"; FBX wants "true" for "continue"
404-
return !EditorUtility.DisplayCancelableProgressBar(ProgressBarTitle, "Exporting Scene...", progress01);
419+
return !cancel;
420+
}
421+
422+
static void DeleteFile()
423+
{
424+
if (File.Exists (LastFilePath)) {
425+
try {
426+
File.Delete (LastFilePath);
427+
} catch (IOException) {}
428+
429+
if (File.Exists (LastFilePath)) {
430+
Debug.LogWarning ("Failed to delete file: " + LastFilePath);
431+
}
432+
} else {
433+
EditorApplication.update -= DeleteFile;
434+
AssetDatabase.Refresh ();
435+
}
405436
}
406437

407438
//

0 commit comments

Comments
 (0)