@@ -26,13 +26,13 @@ namespace FbxExporters
26
26
/// </summary>
27
27
public /*static*/ class FbxPrefabAutoUpdater : UnityEditor . AssetPostprocessor
28
28
{
29
- #if UNITY_EDITOR
29
+ #if UNITY_EDITOR
30
30
public const string FBX_PREFAB_FILE = "/FbxPrefab.cs" ;
31
- #else
31
+ #else
32
32
public const string FBX_PREFAB_FILE = "/UnityFbxPrefab.dll" ;
33
- #endif
33
+ #endif
34
34
35
- static string [ ] importedAssets ;
35
+ const string MenuItemName = "GameObject/Update from Fbx" ;
36
36
37
37
public static string FindFbxPrefabAssetPath ( )
38
38
{
@@ -57,8 +57,6 @@ public static bool IsPrefabAsset(string assetPath) {
57
57
return assetPath . EndsWith ( ".prefab" ) ;
58
58
}
59
59
60
- const string MenuItemName = "GameObject/Update from Fbx" ;
61
-
62
60
/// <summary>
63
61
/// Return false if the prefab definitely does not have an
64
62
/// FbxPrefab component that points to one of the Fbx assets
@@ -192,45 +190,47 @@ static void OnContextItem(MenuCommand command)
192
190
return ;
193
191
}
194
192
195
- //Selection.objects = UpdateLinkedPrefab(selection);
196
- UpdateLinkedPrefab ( selection ) ;
193
+ foreach ( GameObject selectedObject in selection )
194
+ {
195
+ UpdateLinkedPrefab ( selectedObject ) ;
196
+ }
197
197
}
198
198
199
199
/// <summary>
200
200
// Validate the menu item defined by the function above.
201
201
/// </summary>
202
202
[ MenuItem ( MenuItemName , true , 31 ) ]
203
- static bool OnValidateMenuItem ( )
203
+ public static bool OnValidateMenuItem ( )
204
204
{
205
205
GameObject [ ] selection = Selection . GetFiltered < GameObject > ( SelectionMode . Editable | SelectionMode . TopLevel ) ;
206
- bool allObjectsPrefab = false ;
207
206
foreach ( GameObject selectedObject in selection )
208
207
{
209
- if ( selectedObject . GetComponentInChildren < FbxPrefab > ( ) )
208
+ GameObject prefab = UnityEditor . PrefabUtility . GetPrefabParent ( selectedObject ) as GameObject ;
209
+ if ( ! prefab )
210
+ {
211
+ return false ;
212
+ }
213
+ if ( prefab . GetComponentInChildren < FbxPrefab > ( ) )
210
214
{
211
- allObjectsPrefab = true ;
212
- break ;
215
+ return true ;
213
216
}
214
217
}
215
218
216
- var isPrefab = PrefabUtility . GetPrefabParent ( Selection . activeGameObject ) != null ;
217
- return isPrefab && allObjectsPrefab ;
219
+ return false ;
218
220
}
219
221
220
- public static void UpdateLinkedPrefab ( GameObject [ ] selection )
222
+ public static void UpdateLinkedPrefab ( GameObject prefabInstance )
221
223
{
222
- var fbxPrefabScriptPath = FindFbxPrefabAssetPath ( ) ;
223
- foreach ( GameObject selectedObject in selection )
224
+ GameObject prefab = UnityEditor . PrefabUtility . GetPrefabParent ( prefabInstance ) as GameObject ;
225
+ if ( ! prefab )
224
226
{
225
- GameObject prefabInstance = selectedObject ;
226
-
227
- GameObject prefab = UnityEditor . PrefabUtility . GetPrefabParent ( prefabInstance ) as GameObject ;
227
+ return ;
228
+ }
228
229
229
- foreach ( var fbxPrefabComponent in prefab . GetComponentsInChildren < FbxPrefab > ( ) )
230
- {
231
- var fbxPrefabUtility = new FbxPrefabUtility ( fbxPrefabComponent ) ;
232
- fbxPrefabUtility . SyncPrefab ( ) ;
233
- }
230
+ foreach ( var fbxPrefabComponent in prefab . GetComponentsInChildren < FbxPrefab > ( ) )
231
+ {
232
+ var fbxPrefabUtility = new FbxPrefabUtility ( fbxPrefabComponent ) ;
233
+ fbxPrefabUtility . SyncPrefab ( ) ;
234
234
}
235
235
}
236
236
0 commit comments