public override void OnInspectorGUI() { SerializedProperty m_GameObjectProp = serializedObject.FindProperty("m_nameMapping"); FbxPrefab fbxPrefab = (FbxPrefab)target; // We can only change these settings when applied to a prefab. bool isDisabled = string.IsNullOrEmpty(AssetDatabase.GetAssetPath(fbxPrefab)); if (isDisabled) { EditorGUILayout.HelpBox("Please select a prefab. You can't edit an instance in the scene.", MessageType.Info); } EditorGUI.BeginDisabledGroup(isDisabled); FbxPrefabUtility fbxPrefabUtility = new FbxPrefabUtility(fbxPrefab); var oldFbxAsset = fbxPrefabUtility.FbxAsset; var newFbxAsset = EditorGUILayout.ObjectField(new GUIContent("Source FBX Asset", "The FBX file that is linked to this Prefab"), oldFbxAsset, typeof(GameObject), allowSceneObjects: false) as GameObject; if (newFbxAsset && !FbxPrefabAutoUpdater.IsFbxAsset(UnityEditor.AssetDatabase.GetAssetPath(newFbxAsset))) { Debug.LogError("FbxPrefab must point to an FBX asset (or none)."); } else if (newFbxAsset != oldFbxAsset) { fbxPrefabUtility.SetSourceModel(newFbxAsset); } EditorGUI.EndDisabledGroup(); EditorGUILayout.PropertyField(m_GameObjectProp, true); #if FBXEXPORTER_DEBUG if (GUILayout.Button("Update prefab manually...")) { // Get existing open window or if none, make a new one: ManualUpdateEditorWindow window = (ManualUpdateEditorWindow)EditorWindow.GetWindow(typeof(ManualUpdateEditorWindow)); window.Init(fbxPrefabUtility, fbxPrefab); window.Show(); } EditorGUILayout.LabelField("Debug info:"); try { fbxPrefabUtility.GetFbxHistory().ToJson(); } catch (System.Exception xcp) { Debug.LogException(xcp); } EditorGUILayout.SelectableLabel(fbxPrefabUtility.GetFbxHistoryString()); #endif serializedObject.ApplyModifiedProperties(); }
public static void UpdateLinkedPrefab(GameObject prefabOrInstance) { // Find the prefab, bail if this is neither a prefab nor an instance. GameObject prefab; switch (PrefabUtility.GetPrefabType(prefabOrInstance)) { case PrefabType.Prefab: prefab = prefabOrInstance; break; case PrefabType.PrefabInstance: prefab = PrefabUtility.GetCorrespondingObjectFromSource(prefabOrInstance) as GameObject; break; default: return; } foreach (var fbxPrefabComponent in prefab.GetComponentsInChildren <FbxPrefab>()) { // Launch the manual update UI to allow the user to fix // renamed nodes (or auto-update if there's nothing to rename). var fbxPrefabUtility = new FbxPrefabUtility(fbxPrefabComponent); if (UnityEditor.Formats.Fbx.Exporter.ExportSettings.instance.AutoUpdaterEnabled || runningUnitTest) { fbxPrefabUtility.SyncPrefab(); } else { ManualUpdateEditorWindow window = (ManualUpdateEditorWindow)EditorWindow.GetWindow(typeof(ManualUpdateEditorWindow)); window.Init(fbxPrefabUtility, fbxPrefabComponent); window.Show(); } } }