protected void SetGameObjectsToConvert(IEnumerable <GameObject> toConvert) { SetToExport(toConvert.OrderBy(go => go.name).ToArray()); TransferAnimationSource = null; TransferAnimationDest = null; if (GetToExport().Length == 1) { var go = ModelExporter.GetGameObject(GetToExport()[0]); // check if the GameObject is a model instance, use as default filename and path if it is var mainAsset = ConvertToModel.GetFbxAssetOrNull(go); if (!mainAsset) { // Use the game object's name m_prefabFileName = go.name; } else { // Use the asset's name var mainAssetRelPath = AssetDatabase.GetAssetPath(mainAsset); // remove Assets/ from beginning of path mainAssetRelPath = mainAssetRelPath.Substring("Assets".Length); m_prefabFileName = System.IO.Path.GetFileNameWithoutExtension(mainAssetRelPath); ExportSettings.AddFbxSavePath(System.IO.Path.GetDirectoryName(mainAssetRelPath)); } // if only one object selected, set transfer source/dest to this object if (go) { TransferAnimationSource = go.transform; TransferAnimationDest = go.transform; } } else if (GetToExport().Length > 1) { m_prefabFileName = "(automatic)"; } this.SetFilename(m_prefabFileName); }
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); } 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 (ConvertToModel.WillCreatePrefab(go)) { if (!OverwriteExistingFile(prefabPath)) { return(false); } } if (ConvertToModel.WillExportFbx(go)) { if (!OverwriteExistingFile(fbxPath)) { return(false); } } ConvertToModel.Convert( go, fbxFullPath: fbxPath, prefabFullPath: prefabPath, exportOptions: ExportSettings.instance.ConvertToPrefabSettings.info ); return(true); } foreach (var obj in GetToExport()) { // Convert, automatically choosing a file path that won't clobber any existing files. var go = ModelExporter.GetGameObject(obj); ConvertToModel.Convert( go, fbxDirectoryFullPath: fbxDirPath, prefabDirectoryFullPath: prefabDirPath, exportOptions: ExportSettings.instance.ConvertToPrefabSettings.info ); } return(true); }