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 SetupFbxPrefab(GameObject toSetUp, GameObject unityMainAsset) { if (toSetUp == null) { throw new System.ArgumentNullException("toSetUp"); } // Set up the FbxPrefab component so it will auto-update. // Make sure to delete whatever FbxPrefab history we had. var fbxPrefab = toSetUp.GetComponent <FbxPrefab>(); if (fbxPrefab) { Object.DestroyImmediate(fbxPrefab); } fbxPrefab = toSetUp.AddComponent <FbxPrefab>(); var fbxPrefabUtility = new FbxPrefabUtility(fbxPrefab); fbxPrefabUtility.SetSourceModel(unityMainAsset); }