@@ -90,8 +90,6 @@ static void OnPostprocessAllAssets(string[] imported, string[] deleted, string[]
90
90
// Do not start if Auto Updater is disabled in FBX Exporter Settings
91
91
if ( ! FbxExporters . EditorTools . ExportSettings . instance . autoUpdaterEnabled )
92
92
{
93
- // Store imported assets to reuse them later
94
- importedAssets = imported ;
95
93
return ;
96
94
}
97
95
@@ -102,7 +100,10 @@ static void OnPostprocessAllAssets(string[] imported, string[] deleted, string[]
102
100
HashSet < string > fbxImported = null ;
103
101
foreach ( var fbxModel in imported ) {
104
102
if ( IsFbxAsset ( fbxModel ) ) {
105
- if ( fbxImported == null ) { fbxImported = new HashSet < string > ( ) ; }
103
+ if ( fbxImported == null )
104
+ {
105
+ fbxImported = new HashSet < string > ( ) ;
106
+ }
106
107
fbxImported . Add ( fbxModel ) ;
107
108
//Debug.Log("Tracking fbx asset " + fbxModel);
108
109
} else {
@@ -165,16 +166,15 @@ static void OnPostprocessAllAssets(string[] imported, string[] deleted, string[]
165
166
}
166
167
}
167
168
168
- [ MenuItem ( MenuItemName , false , 30 ) ]
169
- public static void OnContextItem ( MenuCommand command )
169
+ [ MenuItem ( MenuItemName , false , 31 ) ]
170
+ static void OnContextItem ( MenuCommand command )
170
171
{
171
172
GameObject [ ] selection = null ;
172
173
173
174
if ( command == null || command . context == null )
174
175
{
175
176
// We were actually invoked from the top GameObject menu, so use the selection.
176
- //selection = Selection.GetFiltered<GameObject>(SelectionMode.Unfiltered);
177
- selection = Selection . gameObjects ;
177
+ selection = Selection . GetFiltered < GameObject > ( SelectionMode . Editable | SelectionMode . TopLevel ) ;
178
178
}
179
179
else
180
180
{
@@ -192,98 +192,43 @@ public static void OnContextItem(MenuCommand command)
192
192
return ;
193
193
}
194
194
195
-
196
- // Did we import an fbx file at all?
197
- // Optimize to not allocate in the common case of 'no'
198
- HashSet < string > fbxImported = null ;
199
- if ( importedAssets != null )
200
- {
201
- foreach ( var fbxModel in importedAssets )
202
- {
203
- if ( IsFbxAsset ( fbxModel ) )
204
- {
205
- if ( fbxImported == null ) { fbxImported = new HashSet < string > ( ) ; }
206
- fbxImported . Add ( fbxModel ) ;
207
- //Debug.Log("Tracking fbx asset " + fbxModel);
208
- }
209
- else
210
- {
211
- //Debug.Log("Not an fbx asset " + fbxModel);
212
- }
213
- }
214
- }
215
-
216
- if ( fbxImported != null )
217
- {
218
- //Selection.objects = UpdateLinkedPrefab(selection);
219
- UpdateLinkedPrefab ( selection , fbxImported ) ;
220
- }
195
+ //Selection.objects = UpdateLinkedPrefab(selection);
196
+ UpdateLinkedPrefab ( selection ) ;
221
197
}
222
198
223
199
/// <summary>
224
200
// Validate the menu item defined by the function above.
225
201
/// </summary>
226
- [ MenuItem ( MenuItemName , true , 30 ) ]
227
- public static bool OnValidateMenuItem ( )
202
+ [ MenuItem ( MenuItemName , true , 31 ) ]
203
+ static bool OnValidateMenuItem ( )
228
204
{
229
- //GameObject[] selection = Selection.GetFiltered<GameObject>(SelectionMode.Unfiltered);
230
- GameObject [ ] selection = Selection . gameObjects ;
231
-
232
- if ( selection == null || selection . Length == 0 )
233
- {
234
- ModelExporter . DisplayNoSelectionDialog ( ) ;
235
- return false ;
236
- }
237
-
238
- bool allObjectsPrefab = true ;
239
- // Check if it's a prefab
205
+ GameObject [ ] selection = Selection . GetFiltered < GameObject > ( SelectionMode . Editable | SelectionMode . TopLevel ) ;
206
+ bool allObjectsPrefab = false ;
240
207
foreach ( GameObject selectedObject in selection )
241
208
{
242
- if ( selectedObject . GetComponent < FbxPrefab > ( ) != null || PrefabUtility . FindPrefabRoot ( selectedObject ) . GetComponent < FbxPrefab > ( ) != null )
209
+ if ( selectedObject . GetComponentInChildren < FbxPrefab > ( ) )
243
210
{
244
211
allObjectsPrefab = true ;
245
- }
246
- else
247
- {
248
- allObjectsPrefab = false ;
249
212
break ;
250
213
}
251
214
}
252
215
253
- return allObjectsPrefab ;
216
+ var isPrefab = PrefabUtility . GetPrefabParent ( Selection . activeGameObject ) != null ;
217
+ return isPrefab && allObjectsPrefab ;
254
218
}
255
219
256
- static void UpdateLinkedPrefab ( GameObject [ ] selection , HashSet < string > fbxImported )
220
+ public static void UpdateLinkedPrefab ( GameObject [ ] selection )
257
221
{
258
- // Iterate over all the prefabs that have an FbxPrefab component that
259
- // points to an FBX file that got (re)-imported.
260
- //
261
- // There's no one-line query to get those, so we search for a much
262
- // larger set and whittle it down, hopefully without needing to
263
- // load the asset into memory if it's not necessary.
264
- //
265
- foreach ( GameObject prefab in selection )
222
+ var fbxPrefabScriptPath = FindFbxPrefabAssetPath ( ) ;
223
+ foreach ( GameObject selectedObject in selection )
266
224
{
267
- if ( ! prefab )
268
- {
269
- //Debug.LogWarning("FbxPrefab reimport: failed to update prefab " + prefabPath);
270
- continue ;
271
- }
225
+ GameObject prefabInstance = selectedObject ;
226
+
227
+ GameObject prefab = UnityEditor . PrefabUtility . GetPrefabParent ( prefabInstance ) as GameObject ;
228
+
272
229
foreach ( var fbxPrefabComponent in prefab . GetComponentsInChildren < FbxPrefab > ( ) )
273
230
{
274
231
var fbxPrefabUtility = new FbxPrefabUtility ( fbxPrefabComponent ) ;
275
- if ( ! fbxPrefabUtility . WantsAutoUpdate ( ) )
276
- {
277
- //Debug.Log("Not auto-updating " + prefabPath);
278
- continue ;
279
- }
280
- var fbxAssetPath = fbxPrefabUtility . GetFbxAssetPath ( ) ;
281
- if ( ! fbxImported . Contains ( fbxAssetPath ) )
282
- {
283
- //Debug.Log("False-positive dependence: " + prefabPath + " via " + fbxAssetPath);
284
- continue ;
285
- }
286
- //Debug.Log("Updating " + prefabPath + "...");
287
232
fbxPrefabUtility . SyncPrefab ( ) ;
288
233
}
289
234
}
0 commit comments