@@ -108,18 +108,7 @@ public static GameObject Convert (
108
108
)
109
109
{
110
110
// Only create the prefab (no FBX export) if we have selected the root of a model prefab instance.
111
- // Children of model prefab instances will also have "model prefab instance"
112
- // as their prefab type, so it is important that it is the root that is selected.
113
- //
114
- // e.g. If I have the following hierarchy:
115
- // Cube
116
- // -- Sphere
117
- //
118
- // Both the Cube and Sphere will have ModelPrefabInstance as their prefab type.
119
- // However, when selecting the Sphere to convert, we don't want to connect it to the
120
- // existing FBX but create a new FBX containing just the sphere.
121
- PrefabType unityPrefabType = PrefabUtility . GetPrefabType ( toConvert ) ;
122
- if ( unityPrefabType == PrefabType . ModelPrefabInstance && toConvert . Equals ( PrefabUtility . FindPrefabRoot ( toConvert ) ) ) {
111
+ if ( IsModelInstance ( toConvert ) ) {
123
112
// don't re-export fbx
124
113
// create prefab out of model instance in scene, link to existing fbx
125
114
var mainAsset = PrefabUtility . GetPrefabParent ( toConvert ) as GameObject ;
@@ -223,6 +212,26 @@ public static void SetupFbxPrefab(GameObject toConvert, GameObject unityMainAsse
223
212
}
224
213
}
225
214
215
+ /// <summary>
216
+ /// Determines if the given GameObject is a model instance.
217
+ /// </summary>
218
+ /// <returns><c>true</c> if go is a model instance; otherwise, <c>false</c>.</returns>
219
+ /// <param name="go">Go.</param>
220
+ public static bool IsModelInstance ( GameObject go ) {
221
+ // Children of model prefab instances will also have "model prefab instance"
222
+ // as their prefab type, so it is important that it is the root that is selected.
223
+ //
224
+ // e.g. If I have the following hierarchy:
225
+ // Cube
226
+ // -- Sphere
227
+ //
228
+ // Both the Cube and Sphere will have ModelPrefabInstance as their prefab type.
229
+ // However, when selecting the Sphere to convert, we don't want to connect it to the
230
+ // existing FBX but create a new FBX containing just the sphere.
231
+ PrefabType unityPrefabType = PrefabUtility . GetPrefabType ( go ) ;
232
+ return unityPrefabType == PrefabType . ModelPrefabInstance && go . Equals ( PrefabUtility . FindPrefabRoot ( go ) ) ;
233
+ }
234
+
226
235
/// <summary>
227
236
/// Check if the file exists, and if it does, then increment the name.
228
237
/// e.g. if filename is Sphere.fbx and it already exists, change it to Sphere 1.fbx.
0 commit comments