@@ -725,7 +725,10 @@ public static bool OnValidateMenuItem ()
725
725
}
726
726
727
727
// Add a menu item called "Export Model..." to a GameObject's context menu.
728
- [ MenuItem ( "GameObject/Export Model... %e" , false , 30 ) ]
728
+ // NOTE: The ellipsis at the end of the Menu Item name prevents the context
729
+ // from being passed to command, thus resulting in OnContextItem()
730
+ // being called only once regardless of what is selected.
731
+ [ MenuItem ( "GameObject/Export Model..." , false , 30 ) ]
729
732
static void OnContextItem ( MenuCommand command )
730
733
{
731
734
OnExport ( ) ;
@@ -956,13 +959,19 @@ private static void OnExport ()
956
959
? Application . dataPath
957
960
: System . IO . Path . GetDirectoryName ( LastFilePath ) ;
958
961
959
- var filename = string . IsNullOrEmpty ( LastFilePath )
960
- ? MakeFileName ( basename : FileBaseName , extension : Extension )
961
- : System . IO . Path . GetFileName ( LastFilePath ) ;
962
+ GameObject [ ] selectedGOs = Selection . GetFiltered < GameObject > ( SelectionMode . TopLevel ) ;
963
+ string filename = null ;
964
+ if ( selectedGOs . Length == 1 ) {
965
+ filename = ConvertToValidFilename ( selectedGOs [ 0 ] . name + ".fbx" ) ;
966
+ } else {
967
+ filename = string . IsNullOrEmpty ( LastFilePath )
968
+ ? MakeFileName ( basename : FileBaseName , extension : Extension )
969
+ : System . IO . Path . GetFileName ( LastFilePath ) ;
970
+ }
962
971
963
972
var title = string . Format ( "Export Model FBX ({0})" , FileBaseName ) ;
964
973
965
- var filePath = EditorUtility . SaveFilePanel ( title , directory , filename , "" ) ;
974
+ var filePath = EditorUtility . SaveFilePanel ( title , directory , filename , "fbx " ) ;
966
975
967
976
if ( string . IsNullOrEmpty ( filePath ) ) {
968
977
return ;
@@ -1011,6 +1020,11 @@ private static void EnsureDirectory (string path)
1011
1020
Directory . CreateDirectory ( fileInfo . Directory . FullName ) ;
1012
1021
}
1013
1022
}
1023
+
1024
+ public static string ConvertToValidFilename ( string filename )
1025
+ {
1026
+ return System . Text . RegularExpressions . Regex . Replace ( filename , "[" + new string ( Path . GetInvalidFileNameChars ( ) ) + "]" , "_" ) ;
1027
+ }
1014
1028
}
1015
1029
}
1016
1030
}
0 commit comments