public static GameObject[] CreateInstantiatedModelPrefab( GameObject[] unityGameObjectsToConvert) { var toExport = ModelExporter.RemoveRedundantObjects(unityGameObjectsToConvert); if (ExportSettings.instance.DisplayOptionsWindow) { if (toExport.Count == 1) { var go = toExport.First(); if (PrefabUtility.IsPartOfNonAssetPrefabInstance(go) && !PrefabUtility.IsOutermostPrefabInstanceRoot(go)) { DisplayInvalidSelectionDialog(go, "Children of a Prefab instance cannot be converted.\nYou can open the Prefab in Prefab Mode or unpack the Prefab instance to convert it's children"); return(null); } if (PrefabUtility.IsPartOfPrefabAsset(go) && go.transform.parent != null) { DisplayInvalidSelectionDialog(go, "Children of a Prefab Asset cannot be converted.\nYou can open the Prefab in Prefab Mode or unpack the Prefab instance to convert it's children"); return(null); } // can't currently handle converting root of prefab in prefab preview scene if (SceneManagement.EditorSceneManager.IsPreviewSceneObject(go) && go.transform.parent == null) { DisplayInvalidSelectionDialog(go, "Cannot convert Prefab root in the Prefab Preview Scene.\nYou can convert a Prefab Instance or convert the Prefab Asset directly in the Project view"); return(null); } } ConvertToPrefabEditorWindow.Init(toExport); return(toExport.ToArray()); } bool onlyPrefabAssets = ConvertToNestedPrefab.SetContainsOnlyPrefabAssets(unityGameObjectsToConvert); int groupIndex = -1; // If only Prefab Assets on disk are selected (nothing in the scene), then do not // try to undo as modifications on disk cannot be undone. if (!onlyPrefabAssets) { Undo.IncrementCurrentGroup(); groupIndex = Undo.GetCurrentGroup(); Undo.SetCurrentGroupName(UndoConversionCreateObject); } var converted = new List <GameObject>(); var exportOptions = ExportSettings.instance.ConvertToPrefabSettings.info; foreach (var go in toExport) { var convertedGO = Convert(go, exportOptions: exportOptions); if (convertedGO != null) { converted.Add(convertedGO); } } if (!onlyPrefabAssets && groupIndex >= 0) { Undo.CollapseUndoOperations(groupIndex); Undo.IncrementCurrentGroup(); } return(converted.ToArray()); }
protected override bool Export() { if (string.IsNullOrEmpty(ExportFileName)) { Debug.LogError("FbxExporter: Please specify an fbx filename"); return(false); } if (string.IsNullOrEmpty(m_prefabFileName)) { Debug.LogError("FbxExporter: Please specify a prefab filename"); return(false); } var fbxDirPath = ExportSettings.FbxAbsoluteSavePath; var fbxPath = System.IO.Path.Combine(fbxDirPath, ExportFileName + ".fbx"); var prefabDirPath = ExportSettings.PrefabAbsoluteSavePath; var prefabPath = System.IO.Path.Combine(prefabDirPath, m_prefabFileName + ".prefab"); if (GetToExport() == null) { Debug.LogError("FbxExporter: missing object for conversion"); return(false); } int rectTransformCount = GetUIElementsInExportSetCount(); if (rectTransformCount > 0) { // Warn that UI elements will break if converted string warning = string.Format("Warning: UI Components (ie, RectTransform) are not saved when converting to FBX.\n{0} item(s) in the selection will lose their UI components.", rectTransformCount); bool result = UnityEditor.EditorUtility.DisplayDialog( string.Format("{0} Warning", ModelExporter.PACKAGE_UI_NAME), warning, "Convert and Lose UI", "Cancel"); if (!result) { return(false); } } if (SettingsObject.UseMayaCompatibleNames && SettingsObject.AllowSceneModification) { string warning = "Names of objects in the hierarchy may change with the Compatible Naming option turned on"; if (ExportSetContainsAnimation()) { warning = "Compatible Naming option turned on. Names of objects in hierarchy may change and break animations."; } // give a warning dialog that indicates that names in the scene may change int result = UnityEditor.EditorUtility.DisplayDialogComplex( string.Format("{0} Warning", ModelExporter.PACKAGE_UI_NAME), warning, "OK", "Turn off and continue", "Cancel" ); if (result == 1) { // turn compatible naming off SettingsObject.SetUseMayaCompatibleNames(false); } else if (result == 2) { return(false); } } if (GetToExport().Length == 1) { var go = ModelExporter.GetGameObject(GetToExport()[0]); // Check if we'll be clobbering files. If so, warn the user // first and let them cancel out. if (!OverwriteExistingFile(prefabPath)) { return(false); } if (ConvertToNestedPrefab.WillExportFbx(go)) { if (!OverwriteExistingFile(fbxPath)) { return(false); } } ConvertToNestedPrefab.Convert( go, fbxFullPath: fbxPath, prefabFullPath: prefabPath, exportOptions: ExportSettings.instance.ConvertToPrefabSettings.info ); return(true); } bool onlyPrefabAssets = ConvertToNestedPrefab.SetContainsOnlyPrefabAssets(GetToExport()); int groupIndex = -1; // no need to undo if we aren't converting anything that's in the scene if (!onlyPrefabAssets) { Undo.IncrementCurrentGroup(); groupIndex = Undo.GetCurrentGroup(); Undo.SetCurrentGroupName(ConvertToNestedPrefab.UndoConversionCreateObject); } foreach (var obj in GetToExport()) { // Convert, automatically choosing a file path that won't clobber any existing files. var go = ModelExporter.GetGameObject(obj); ConvertToNestedPrefab.Convert( go, fbxDirectoryFullPath: fbxDirPath, prefabDirectoryFullPath: prefabDirPath, exportOptions: ExportSettings.instance.ConvertToPrefabSettings.info ); } if (!onlyPrefabAssets && groupIndex >= 0) { Undo.CollapseUndoOperations(groupIndex); Undo.IncrementCurrentGroup(); } return(true); }