/// <summary> /// Bakes a combined mesh. /// </summary> /// <param name="mom"></param> /// <param name="so">This is needed to work around a Unity bug where UnpackPrefabInstance corrupts /// a SerializedObject. Only needed for bake into prefab.</param> public static bool bake(MeshBakerCommon mom, ref SerializedObject so) { bool createdDummyTextureBakeResults = false; bool success = false; try { if (mom.meshCombiner.outputOption == OutputOptions.bakeIntoSceneObject || mom.meshCombiner.outputOption == OutputOptions.bakeIntoPrefab) { success = MeshCombinerEditorFunctions.BakeIntoCombined(mom, out createdDummyTextureBakeResults, ref so); } else { //bake meshes in place if (mom is MeshCombinerEntrance) { ValidationLevel vl = Application.isPlaying ? ValidationLevel.quick : ValidationLevel.robust; if (!MeshBakerRoot.DoCombinedValidate(mom, ObjsToCombineTypes.prefabOnly, new EditorMethods(), vl)) { return(false); } List <GameObject> objsToMesh = mom.GetObjectsToCombine(); ////success = MB3_BakeInPlace.BakeMeshesInPlace((MeshCombineHandler)((MeshCombinerEntrance)mom).meshCombiner, objsToMesh, mom.bakeAssetsInPlaceFolderPath, mom.clearBuffersAfterBake, updateProgressBar); } else { //多网格合并无法 Bake In Place Debug.LogError("Multi-mesh Baker components cannot be used for Bake In Place. Use an ordinary Mesh Baker object instead."); } } mom.meshCombiner.CheckIntegrity(); } catch (Exception e) { Debug.LogError(e); } finally { if (createdDummyTextureBakeResults && mom.textureBakeResults != null) { MeshBakerUtility.Destroy(mom.textureBakeResults); mom.textureBakeResults = null; } EditorUtility.ClearProgressBar(); } return(success); }