@@ -48,18 +48,19 @@ protected void SetGameObjectsToConvert(IEnumerable<GameObject> toConvert){
48
48
if ( ToExport . Length == 1 ) {
49
49
var go = ModelExporter . GetGameObject ( ToExport [ 0 ] ) ;
50
50
// check if the GameObject is a model instance, use as default filename and path if it is
51
- if ( ConvertToModel . IsModelInstance ( go ) ) {
52
- var mainAsset = PrefabUtility . GetPrefabParent ( go ) as GameObject ;
51
+ var mainAsset = ConvertToModel . GetFbxAssetOrNull ( go ) ;
52
+ if ( ! mainAsset ) {
53
+ // Use the game object's name
54
+ m_prefabFileName = go . name ;
55
+ } else {
56
+ // Use the asset's name
53
57
var mainAssetRelPath = AssetDatabase . GetAssetPath ( mainAsset ) ;
54
58
// remove Assets/ from beginning of path
55
59
mainAssetRelPath = mainAssetRelPath . Substring ( "Assets" . Length ) ;
56
60
57
61
m_prefabFileName = System . IO . Path . GetFileNameWithoutExtension ( mainAssetRelPath ) ;
58
62
ExportSettings . AddFbxSavePath ( System . IO . Path . GetDirectoryName ( mainAssetRelPath ) ) ;
59
63
}
60
- else {
61
- m_prefabFileName = ToExport [ 0 ] . name ;
62
- }
63
64
64
65
// if only one object selected, set transfer source/dest to this object
65
66
if ( go ) {
@@ -144,28 +145,17 @@ protected override bool Export ()
144
145
if ( ToExport . Length == 1 ) {
145
146
var go = ModelExporter . GetGameObject ( ToExport [ 0 ] ) ;
146
147
147
- if ( ! OverwriteExistingFile ( prefabPath ) ) {
148
- return false ;
149
- }
150
-
151
- // Only create the prefab (no FBX export) if we have selected the root of a model prefab instance.
152
- if ( ConvertToModel . IsModelInstance ( go ) ) {
153
- // don't re-export fbx
154
- // create prefab out of model instance in scene, link to existing fbx
155
- var mainAsset = PrefabUtility . GetPrefabParent ( go ) as GameObject ;
156
- var mainAssetRelPath = AssetDatabase . GetAssetPath ( mainAsset ) ;
157
- var mainAssetAbsPath = System . IO . Directory . GetParent ( Application . dataPath ) + "/" + mainAssetRelPath ;
158
- var relPrefabPath = ExportSettings . GetProjectRelativePath ( prefabPath ) ;
159
-
160
- if ( string . Equals ( System . IO . Path . GetFullPath ( fbxPath ) , System . IO . Path . GetFullPath ( mainAssetAbsPath ) ) ) {
161
- ConvertToModel . SetupFbxPrefab ( go , mainAsset , relPrefabPath , mainAssetAbsPath ) ;
162
- return true ;
148
+ // Check if we'll be clobbering files. If so, warn the user
149
+ // first and let them cancel out.
150
+ if ( ConvertToModel . WillCreatePrefab ( go ) ) {
151
+ if ( ! OverwriteExistingFile ( prefabPath ) ) {
152
+ return false ;
163
153
}
164
154
}
165
-
166
- // check if file already exists, give a warning if it does
167
- if ( ! OverwriteExistingFile ( fbxPath ) ) {
168
- return false ;
155
+ if ( ConvertToModel . WillExportFbx ( go ) ) {
156
+ if ( ! OverwriteExistingFile ( fbxPath ) ) {
157
+ return false ;
158
+ }
169
159
}
170
160
171
161
ConvertToModel . Convert (
@@ -175,6 +165,7 @@ protected override bool Export ()
175
165
}
176
166
177
167
foreach ( var obj in ToExport ) {
168
+ // Convert, automatically choosing a file path that won't clobber any existing files.
178
169
var go = ModelExporter . GetGameObject ( obj ) ;
179
170
ConvertToModel . Convert (
180
171
go , fbxDirectoryFullPath : fbxDirPath , prefabDirectoryFullPath : prefabDirPath , exportOptions : ExportSettings . instance . convertToPrefabSettings . info
0 commit comments