@@ -137,18 +137,27 @@ public static GameObject Convert (
137
137
string prefabFullPath = null ,
138
138
EditorTools . ConvertToPrefabSettingsSerialize exportOptions = null )
139
139
{
140
- // If we selected the something that's already backed by an FBX, don't export.
140
+ // If we selected the something that's already backed by an
141
+ // FBX, don't export.
141
142
var mainAsset = GetOrCreateFbxAsset ( toConvert , fbxDirectoryFullPath , fbxFullPath , exportOptions ) ;
142
143
144
+ // If we selected a prefab *instance* then break the
145
+ // connection. We only want to update an existing prefab if
146
+ // we're converting an existing prefab (not an instance).
147
+ if ( PrefabUtility . GetPrefabType ( toConvert ) == PrefabType . PrefabInstance ) {
148
+ PrefabUtility . DisconnectPrefabInstance ( toConvert ) ;
149
+ }
150
+
143
151
// Get 'toConvert' into an editable state. We can't edit
144
152
// assets, and toConvert might be an asset.
145
153
var toConvertInstance = GetOrCreateInstance ( toConvert ) ;
146
154
147
155
// Set it up to track the FbxPrefab.
148
156
SetupFbxPrefab ( toConvertInstance , mainAsset ) ;
149
157
150
- // Now get 'toConvertInstance' into a prefab. If toConvert is already a prefab,
151
- // this is equivalent to an 'apply' ; if it's not, we're creating a new prefab.
158
+ // Now get 'toConvertInstance' into a prefab. If toConvert is
159
+ // already a prefab, this is equivalent to an 'apply' ; if it's
160
+ // not, we're creating a new prefab.
152
161
var prefab = ApplyOrCreatePrefab ( toConvertInstance , prefabDirectoryFullPath , prefabFullPath ) ;
153
162
154
163
if ( toConvertInstance == toConvert ) {
@@ -166,10 +175,11 @@ public static GameObject Convert (
166
175
}
167
176
168
177
/// <summary>
169
- /// Check whether GetOrCreateFbxAsset will be exporting an fbx file, or reusing one.
178
+ /// Check whether <see>Convert</see> will be exporting an fbx file,
179
+ /// or reusing one.
170
180
/// </summary>
171
- public static bool WillExportFbx ( GameObject go ) {
172
- return GetFbxAssetOrNull ( go ) == null ;
181
+ public static bool WillExportFbx ( GameObject toConvert ) {
182
+ return GetFbxAssetOrNull ( toConvert ) == null ;
173
183
}
174
184
175
185
/// <summary>
@@ -266,24 +276,46 @@ public static GameObject GetOrCreateInstance(GameObject toConvert)
266
276
}
267
277
268
278
/// <summary>
269
- /// Check whether ApplyOrCreatePrefab will be creating a new prefab, or updating one.
279
+ /// Check whether <see>Convert</see> will be creating a new prefab, or
280
+ /// updating one.
281
+ ///
282
+ /// Note that ApplyOrCreatePrefab will create in different
283
+ /// circumstances than Convert will.
270
284
/// </summary>
271
- public static bool WillCreatePrefab ( GameObject go ) {
272
- return PrefabUtility . GetPrefabType ( go ) != PrefabType . PrefabInstance ;
285
+ public static bool WillCreatePrefab ( GameObject toConvert ) {
286
+ return PrefabUtility . GetPrefabType ( toConvert ) != PrefabType . Prefab ;
273
287
}
274
288
275
289
/// <summary>
276
290
/// Create a prefab from 'instance', or apply 'instance' to its
277
291
/// prefab if it's already an instance of a prefab.
278
292
///
279
- /// Return the new or updated prefab.
293
+ /// If it's an instance of a model prefab (an fbx file) we will
294
+ /// lose that connection and point to a new prefab file.
295
+ ///
296
+ /// To avoid applying to an existing prefab, break the prefab
297
+ /// connection with <c>PrefabUtility.DisconnectPrefabInstance</c>.
298
+ ///
299
+ /// Returns the new or updated prefab.
280
300
/// </summary>
301
+ /// <param name="instance">A GameObject in the scene. After this
302
+ /// call, it will be a prefab instance (it might already be
303
+ /// one).</param>
304
+ /// <param name="prefabFullPath">The full path to a prefab file we
305
+ /// will create. Ignored if <paramref name="instance"/> is a
306
+ /// prefab instance already. May be null, in which case we'll use <paramref
307
+ /// name="prefabDirectoryFullPath"/> to generate a new name</param>
308
+ /// <param name="prefabDirectoryFullPath">The full path to a
309
+ /// directory that will hold the new prefab. Ignored if <paramref
310
+ /// name="instance"/> is a prefab instance already. Ignored if
311
+ /// <paramref name="prefabFullPath"/> is provided. May be null, in
312
+ /// which case we'll use the project export settings.</param>
313
+ /// <returns>The new or existing prefab.</returns>
281
314
public static GameObject ApplyOrCreatePrefab ( GameObject instance ,
282
315
string prefabDirectoryFullPath = null ,
283
316
string prefabFullPath = null )
284
317
{
285
318
if ( PrefabUtility . GetPrefabType ( instance ) == PrefabType . PrefabInstance ) {
286
- // Apply: there's already a prefab.
287
319
return PrefabUtility . ReplacePrefab ( instance , PrefabUtility . GetPrefabParent ( instance ) ) ;
288
320
}
289
321
0 commit comments