@@ -86,6 +86,17 @@ public static GameObject[] CreateInstantiatedModelPrefab (
86
86
var wasExported = new List < GameObject > ( ) ;
87
87
foreach ( var go in toExport ) {
88
88
try {
89
+ if ( go . transform . parent == null ) {
90
+ PrefabType unityPrefabType = PrefabUtility . GetPrefabType ( go ) ;
91
+ if ( unityPrefabType == PrefabType . ModelPrefabInstance ) {
92
+ // don't re-export fbx
93
+ // create prefab out of model instance in scene, link to existing fbx
94
+ var mainAsset = PrefabUtility . GetPrefabParent ( go ) as GameObject ;
95
+ SetupFbxPrefab ( go , mainAsset , AssetDatabase . GetAssetOrScenePath ( mainAsset ) , AssetDatabase . GetAssetOrScenePath ( mainAsset ) ) ;
96
+ continue ;
97
+ }
98
+ }
99
+
89
100
wasExported . Add ( Convert ( go ,
90
101
directoryFullPath : directoryFullPath ) ) ;
91
102
} catch ( System . Exception xcp ) {
@@ -161,6 +172,14 @@ public static GameObject Convert (
161
172
// Copy the mesh/materials from the FBX
162
173
UpdateFromSourceRecursive ( toConvert , unityMainAsset ) ;
163
174
175
+ SetupFbxPrefab ( toConvert , unityMainAsset , projectRelativePath , fbxFullPath ) ;
176
+
177
+ toConvert . name = Path . GetFileNameWithoutExtension ( fbxFullPath ) ;
178
+ return toConvert ;
179
+ }
180
+
181
+
182
+ public static void SetupFbxPrefab ( GameObject toConvert , GameObject unityMainAsset , string projectRelativePath , string fbxFullPath ) {
164
183
// Set up the FbxPrefab component so it will auto-update.
165
184
// Make sure to delete whatever FbxPrefab history we had.
166
185
var fbxPrefab = toConvert . GetComponent < FbxPrefab > ( ) ;
@@ -179,9 +198,6 @@ public static GameObject Convert (
179
198
string . Format ( "Failed to create prefab asset in [{0}] from fbx [{1}]" ,
180
199
prefabFileName , fbxFullPath ) ) ;
181
200
}
182
-
183
- toConvert . name = Path . GetFileNameWithoutExtension ( fbxFullPath ) ;
184
- return toConvert ;
185
201
}
186
202
187
203
/// <summary>
0 commit comments