public void DrawGUI(SerializedObject meshBaker, MB3_MeshBakerCommon target, System.Type editorWindowType) { if (meshBaker == null) { return; } meshBaker.Update(); showInstructions = EditorGUILayout.Foldout(showInstructions, "Instructions:"); if (showInstructions) { EditorGUILayout.HelpBox("1. Bake combined material(s).\n\n" + "2. If necessary set the 'Texture Bake Results' field.\n\n" + "3. Add scene objects or prefabs to combine or check 'Same As Texture Baker'. For best results these should use the same shader as result material.\n\n" + "4. Select options and 'Bake'.\n\n" + "6. Look at warnings/errors in console. Decide if action needs to be taken.\n\n" + "7. (optional) Disable renderers in source objects.", UnityEditor.MessageType.None); EditorGUILayout.Separator(); } MB3_MeshBakerCommon momm = (MB3_MeshBakerCommon)target; EditorGUILayout.PropertyField(logLevel, gc_logLevelContent); EditorGUILayout.PropertyField(textureBakeResults, gc_textureBakeResultsGUIContent); bool doingTextureArray = false; if (textureBakeResults.objectReferenceValue != null) { doingTextureArray = ((MB2_TextureBakeResults)textureBakeResults.objectReferenceValue).resultType == MB2_TextureBakeResults.ResultType.textureArray; showContainsReport = EditorGUILayout.Foldout(showContainsReport, "Shaders & Materials Contained"); if (showContainsReport) { EditorGUILayout.HelpBox(((MB2_TextureBakeResults)textureBakeResults.objectReferenceValue).GetDescription(), MessageType.Info); } } EditorGUILayout.BeginVertical(editorStyles.editorBoxBackgroundStyle); EditorGUILayout.LabelField("Objects To Be Combined", EditorStyles.boldLabel); if (momm.GetTextureBaker() != null) { EditorGUILayout.PropertyField(useObjsToMeshFromTexBaker, gc_useTextureBakerObjsGUIContent); } else { useObjsToMeshFromTexBaker.boolValue = false; momm.useObjsToMeshFromTexBaker = false; GUI.enabled = false; EditorGUILayout.PropertyField(useObjsToMeshFromTexBaker, gc_useTextureBakerObjsGUIContent); GUI.enabled = true; } if (!momm.useObjsToMeshFromTexBaker) { if (GUILayout.Button(gc_openToolsWindowLabelContent)) { MB3_MeshBakerEditorWindowInterface mmWin = (MB3_MeshBakerEditorWindowInterface)EditorWindow.GetWindow(editorWindowType); mmWin.target = (MB3_MeshBakerRoot)target; } object[] objs = MB3_EditorMethods.DropZone("Drag & Drop Renderers Or Parents Here To Add Objects To Be Combined", 300, 50); MB3_EditorMethods.AddDroppedObjects(objs, momm); EditorGUILayout.PropertyField(objsToMesh, gc_objectsToCombineGUIContent, true); EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Select Objects In Scene")) { Selection.objects = momm.GetObjectsToCombine().ToArray(); if (momm.GetObjectsToCombine().Count > 0) { SceneView.lastActiveSceneView.pivot = momm.GetObjectsToCombine()[0].transform.position; } } if (GUILayout.Button(gc_SortAlongAxis)) { MB3_MeshBakerRoot.ZSortObjects sorter = new MB3_MeshBakerRoot.ZSortObjects(); sorter.sortAxis = sortOrderAxis.vector3Value; sorter.SortByDistanceAlongAxis(momm.GetObjectsToCombine()); } EditorGUILayout.PropertyField(sortOrderAxis, GUIContent.none); EditorGUILayout.EndHorizontal(); } else { GUI.enabled = false; EditorGUILayout.PropertyField(objsToMesh, gc_objectsToCombineGUIContent, true); GUI.enabled = true; } EditorGUILayout.EndVertical(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Output", EditorStyles.boldLabel); EditorGUILayout.PropertyField(outputOptions, gc_outputOptoinsGUIContent); if (momm.meshCombiner.outputOption == MB2_OutputOptions.bakeIntoSceneObject) { //todo switch to renderer momm.meshCombiner.resultSceneObject = (GameObject)EditorGUILayout.ObjectField("Combined Mesh Object", momm.meshCombiner.resultSceneObject, typeof(GameObject), true); if (momm is MB3_MeshBaker) { string l = "Mesh"; Mesh m = (Mesh)mesh.objectReferenceValue; if (m != null) { l += " (" + m.GetInstanceID() + ")"; } Mesh nm = (Mesh)EditorGUILayout.ObjectField(new GUIContent(l), m, typeof(Mesh), true); if (nm != m) { Undo.RecordObject(momm, "Assign Mesh"); ((MB3_MeshCombinerSingle)momm.meshCombiner).SetMesh(nm); mesh.objectReferenceValue = nm; } } } else if (momm.meshCombiner.outputOption == MB2_OutputOptions.bakeIntoPrefab) { momm.resultPrefab = (GameObject)EditorGUILayout.ObjectField(gc_combinedMeshPrefabGUIContent, momm.resultPrefab, typeof(GameObject), true); if (momm is MB3_MeshBaker) { string l = "Mesh"; Mesh m = (Mesh)mesh.objectReferenceValue; if (m != null) { l += " (" + m.GetInstanceID() + ")"; } Mesh nm = (Mesh)EditorGUILayout.ObjectField(new GUIContent(l), m, typeof(Mesh), true); if (nm != m) { Undo.RecordObject(momm, "Assign Mesh"); ((MB3_MeshCombinerSingle)momm.meshCombiner).SetMesh(nm); mesh.objectReferenceValue = nm; } } } else if (momm.meshCombiner.outputOption == MB2_OutputOptions.bakeMeshAssetsInPlace) { EditorGUILayout.HelpBox("NEW! Try the BatchPrefabBaker component. It makes preparing a batch of prefabs for static/ dynamic batching much easier.", MessageType.Info); if (GUILayout.Button("Choose Folder For Bake In Place Meshes")) { string newFolder = EditorUtility.SaveFolderPanel("Folder For Bake In Place Meshes", Application.dataPath, ""); if (!newFolder.Contains(Application.dataPath)) { Debug.LogWarning("The chosen folder must be in your assets folder."); } momm.bakeAssetsInPlaceFolderPath = "Assets" + newFolder.Replace(Application.dataPath, ""); } EditorGUILayout.LabelField("Folder For Meshes: " + momm.bakeAssetsInPlaceFolderPath); } if (momm is MB3_MultiMeshBaker) { MB3_MultiMeshCombiner mmc = (MB3_MultiMeshCombiner)momm.meshCombiner; mmc.maxVertsInMesh = EditorGUILayout.IntField("Max Verts In Mesh", mmc.maxVertsInMesh); } //----------------------------------- EditorGUILayout.Space(); EditorGUILayout.LabelField("Settings", EditorStyles.boldLabel); bool settingsEnabled = true; //------------- Mesh Baker Settings is a bit tricky because it is an interface. EditorGUILayout.Space(); UnityEngine.Object obj = settingsHolder.objectReferenceValue; // Don't use a PropertyField because we may not be able to use the assigned object. It may not implement requried interface. obj = EditorGUILayout.ObjectField(gc_Settings, obj, typeof(UnityEngine.Object), true); if (obj == null) { settingsEnabled = true; settingsHolder.objectReferenceValue = null; if (meshBakerSettingsExternal != null) { meshBakerSettingsExternal.OnDisable(); meshBakerSettingsExternal = null; } } else if (obj is GameObject) { // Check to see if there is a component on this game object that implements MB_IMeshBakerSettingsHolder MB_IMeshBakerSettingsHolder itf = (MB_IMeshBakerSettingsHolder)((GameObject)obj).GetComponent(typeof(MB_IMeshBakerSettingsHolder)); if (itf != null) { settingsEnabled = false; Component settingsHolderComponent = (Component)itf; if (settingsHolder.objectReferenceValue != settingsHolderComponent) { settingsHolder.objectReferenceValue = settingsHolderComponent; meshBakerSettingsExternal = new MB_MeshBakerSettingsEditor(); meshBakerSettingsExternal.OnEnable(itf.GetMeshBakerSettingsAsSerializedProperty()); } } else { settingsEnabled = true; settingsHolder = null; if (meshBakerSettingsExternal != null) { meshBakerSettingsExternal.OnDisable(); meshBakerSettingsExternal = null; } } } else if (obj is MB_IMeshBakerSettingsHolder) { settingsEnabled = false; if (settingsHolder.objectReferenceValue != obj) { settingsHolder.objectReferenceValue = obj; meshBakerSettingsExternal = new MB_MeshBakerSettingsEditor(); meshBakerSettingsExternal.OnEnable(((MB_IMeshBakerSettingsHolder)obj).GetMeshBakerSettingsAsSerializedProperty()); } } else { Debug.LogError("Object was not a Mesh Baker Settings object."); } EditorGUILayout.Space(); if (settingsHolder.objectReferenceValue == null) { // Use the meshCombiner settings meshBakerSettingsThis.DrawGUI(momm.meshCombiner, settingsEnabled, doingTextureArray); } else { if (meshBakerSettingsExternal == null) { meshBakerSettingsExternal = new MB_MeshBakerSettingsEditor(); meshBakerSettingsExternal.OnEnable(((MB_IMeshBakerSettingsHolder)obj).GetMeshBakerSettingsAsSerializedProperty()); } meshBakerSettingsExternal.DrawGUI(((MB_IMeshBakerSettingsHolder)settingsHolder.objectReferenceValue).GetMeshBakerSettings(), settingsEnabled, doingTextureArray); } Color oldColor = GUI.backgroundColor; GUI.backgroundColor = buttonColor; if (GUILayout.Button("Bake")) { bake(momm, ref meshBaker); } GUI.backgroundColor = oldColor; string enableRenderersLabel; bool disableRendererInSource = false; if (momm.GetObjectsToCombine().Count > 0) { Renderer r = MB_Utility.GetRenderer(momm.GetObjectsToCombine()[0]); if (r != null && r.enabled) { disableRendererInSource = true; } } if (disableRendererInSource) { enableRenderersLabel = "Disable Renderers On Source Objects"; } else { enableRenderersLabel = "Enable Renderers On Source Objects"; } if (GUILayout.Button(enableRenderersLabel)) { momm.EnableDisableSourceObjectRenderers(!disableRendererInSource); } meshBaker.ApplyModifiedProperties(); meshBaker.SetIsDifferentCacheDirty(); }
public void DrawGUI(SerializedObject textureBaker, MB3_TextureBaker momm, UnityEngine.Object[] targets, System.Type editorWindow) { if (textureBaker == null) { return; } textureBaker.Update(); showInstructions = EditorGUILayout.Foldout(showInstructions, "Instructions:"); if (showInstructions) { EditorGUILayout.HelpBox("1. Add scene objects or prefabs to combine. For best results these should use the same shader as Combined Mesh Material.\n\n" + "2. Create Empty Assets for Combined Mesh Material(s)\n\n" + "3. Check that shader on Combined Mesh Material(s) are correct.\n\n" + "4. Bake materials into Combined Mesh Material(s).\n\n" + "5. Look at warnings/errors in console. Decide if action needs to be taken.\n\n" + "6. You are now ready to bake combined meshes or batch bake prefabs.", UnityEditor.MessageType.None); } EditorGUILayout.PropertyField(logLevel, logLevelContent); EditorGUILayout.Separator(); // Selected objects EditorGUILayout.BeginVertical(editorStyles.editorBoxBackgroundStyle); EditorGUILayout.LabelField("Objects To Be Combined", EditorStyles.boldLabel); if (GUILayout.Button(openToolsWindowLabelContent)) { MB3_MeshBakerEditorWindow mmWin = (MB3_MeshBakerEditorWindow)EditorWindow.GetWindow(editorWindow); mmWin.SetTarget((MB3_MeshBakerRoot)momm); } object[] objs = MB3_EditorMethods.DropZone("Drag & Drop Renderers or Parents\n" + "HERE\n" + "to add objects to be combined", 300, 50); MB3_EditorMethods.AddDroppedObjects(objs, momm); EditorGUILayout.PropertyField(objsToMesh, objectsToCombineGUIContent, true); EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Select Objects In Scene")) { List <MB3_TextureBaker> selectedBakers = _getBakersFromTargets(targets); List <GameObject> obsToCombine = new List <GameObject>(); foreach (MB3_TextureBaker baker in selectedBakers) { obsToCombine.AddRange(baker.GetObjectsToCombine()); } Selection.objects = obsToCombine.ToArray(); if (momm.GetObjectsToCombine().Count > 0) { SceneView.lastActiveSceneView.pivot = momm.GetObjectsToCombine()[0].transform.position; } } if (GUILayout.Button(gc_SortAlongAxis)) { MB3_MeshBakerRoot.ZSortObjects sorter = new MB3_MeshBakerRoot.ZSortObjects(); sorter.sortAxis = sortOrderAxis.vector3Value; sorter.SortByDistanceAlongAxis(momm.GetObjectsToCombine()); } EditorGUILayout.PropertyField(sortOrderAxis, GUIContent.none); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); // output EditorGUILayout.Separator(); EditorGUILayout.LabelField("Output", EditorStyles.boldLabel); EditorGUILayout.PropertyField(resultType); if (GUILayout.Button(createPrefabAndMaterialLabelContent)) { List <MB3_TextureBaker> selectedBakers = _getBakersFromTargets(targets); string newPrefabPath = EditorUtility.SaveFilePanelInProject("Asset name", "", "asset", "Enter a name for the baked texture results"); if (newPrefabPath != null) { for (int i = 0; i < selectedBakers.Count; i++) { CreateCombinedMaterialAssets(selectedBakers[i], newPrefabPath, i == 0 ? true : false); } } } EditorGUILayout.PropertyField(textureBakeResults, textureBakeResultsGUIContent); if (textureBakeResults.objectReferenceValue != null) { showContainsReport = EditorGUILayout.Foldout(showContainsReport, "Shaders & Materials Contained"); if (showContainsReport) { EditorGUILayout.HelpBox(((MB2_TextureBakeResults)textureBakeResults.objectReferenceValue).GetDescription(), MessageType.Info); } } if (resultType.enumValueIndex == (int)MB2_TextureBakeResults.ResultType.textureArray) { MB_TextureBakerConfigureTextureArrays.DrawTextureArrayConfiguration(momm, textureBaker, this); } else { EditorGUILayout.PropertyField(doMultiMaterial, new GUIContent("Multiple Combined Materials")); if (momm.doMultiMaterial) { MB_TextureBakerEditorConfigureMultiMaterials.DrawMultipleMaterialsMappings(momm, textureBaker, this); } else { EditorGUILayout.PropertyField(resultMaterial, new GUIContent("Combined Mesh Material")); } } // settings int labelWidth = 200; EditorGUILayout.Separator(); EditorGUILayout.BeginVertical(editorStyles.editorBoxBackgroundStyle); EditorGUILayout.LabelField("Material Bake Options", EditorStyles.boldLabel); DrawPropertyFieldWithLabelWidth(atlasPadding, gc_atlasPadding, labelWidth); DrawPropertyFieldWithLabelWidth(maxAtlasSize, maxAtlasSizeGUIContent, labelWidth); DrawPropertyFieldWithLabelWidth(resizePowerOfTwoTextures, resizePowerOfTwoGUIContent, labelWidth); DrawPropertyFieldWithLabelWidth(maxTilingBakeSize, maxTilingBakeSizeGUIContent, labelWidth); EditorGUI.BeginDisabledGroup(momm.doMultiMaterial); DrawPropertyFieldWithLabelWidth(considerMeshUVs, fixOutOfBoundsGUIContent, labelWidth); EditorGUI.EndDisabledGroup(); if (texturePackingAlgorithm.intValue == (int)MB2_PackingAlgorithmEnum.MeshBakerTexturePacker || texturePackingAlgorithm.intValue == (int)MB2_PackingAlgorithmEnum.MeshBakerTexturePacker_Fast || texturePackingAlgorithm.intValue == (int)MB2_PackingAlgorithmEnum.MeshBakerTexturePaker_Fast_V2_Beta) { DrawPropertyFieldWithLabelWidth(forcePowerOfTwoAtlas, forcePowerOfTwoAtlasContent, labelWidth); } DrawPropertyFieldWithLabelWidth(considerNonTextureProperties, considerNonTexturePropertiesContent, labelWidth); if (texturePackingAlgorithm.intValue == (int)MB2_PackingAlgorithmEnum.UnitysPackTextures) { EditorGUILayout.HelpBox("Unity's texture packer has memory problems and frequently crashes the editor.", MessageType.Warning); } EditorGUILayout.PropertyField(texturePackingAlgorithm, texturePackingAgorithmGUIContent); if (MB3_TextureCombinerPipeline.USE_EXPERIMENTAL_HOIZONTALVERTICAL) { if (texturePackingAlgorithm.enumValueIndex == (int)MB2_PackingAlgorithmEnum.MeshBakerTexturePacker_Horizontal) { EditorGUILayout.PropertyField(useMaxAtlasWidthOverride, gc_useMaxAtlasWidthOverride); if (!useMaxAtlasWidthOverride.boolValue) { EditorGUI.BeginDisabledGroup(true); } EditorGUILayout.PropertyField(maxAtlasWidthOverride, gc_overrideMaxAtlasWidth); if (!useMaxAtlasWidthOverride.boolValue) { EditorGUI.EndDisabledGroup(); } } else if (texturePackingAlgorithm.enumValueIndex == (int)MB2_PackingAlgorithmEnum.MeshBakerTexturePacker_Vertical) { EditorGUILayout.PropertyField(useMaxAtlasHeightOverride, gc_useMaxAtlasHeightOverride); if (!useMaxAtlasHeightOverride.boolValue) { EditorGUI.BeginDisabledGroup(true); } EditorGUILayout.PropertyField(maxAtlasHeightOverride, gc_overrideMaxAtlasHeight); if (!useMaxAtlasHeightOverride.boolValue) { EditorGUI.EndDisabledGroup(); } } } if (texturePackingAlgorithm.intValue == (int)MB2_PackingAlgorithmEnum.MeshBakerTexturePaker_Fast_V2_Beta) { // layer field int newValueLayerTexturePackerFastMesh = EditorGUILayout.LayerField(layerTexturePackerFastMeshGUIContent, layerTexturePackerFastMesh.intValue); bool isNewValue = newValueLayerTexturePackerFastMesh == layerTexturePackerFastMesh.intValue; layerTexturePackerFastMesh.intValue = newValueLayerTexturePackerFastMesh; if (isNewValue) { Renderer[] rs = GameObject.FindObjectsOfType <Renderer>(); int numRenderersOnLayer = 0; for (int i = 0; i < rs.Length; i++) { if (rs[i].gameObject.layer == newValueLayerTexturePackerFastMesh) { numRenderersOnLayer++; } } string layerName = LayerMask.LayerToName(layerTexturePackerFastMesh.intValue); if (layerName != null && layerName.Length > 0 && numRenderersOnLayer == 0) { layerTexturePackerFastMeshMessage = null; } else { layerTexturePackerFastMeshMessage = layerTexturePackerFastMeshGUIContent.tooltip; } } string scriptDefinesErrMessage = ValidatePlayerSettingsDefineSymbols(); if (layerTexturePackerFastMesh.intValue == -1 || (layerTexturePackerFastMeshMessage != null && layerTexturePackerFastMeshMessage.Length > 0) || (scriptDefinesErrMessage != null)) { EditorGUILayout.HelpBox(layerTexturePackerFastMeshMessage + "\n\n" + scriptDefinesErrMessage, MessageType.Error); } } EditorGUILayout.PropertyField(customShaderProperties, customShaderPropertyNamesGUIContent, true); EditorGUILayout.EndVertical(); EditorGUILayout.Separator(); Color oldColor = GUI.backgroundColor; GUI.color = buttonColor; if (GUILayout.Button("Bake Materials Into Combined Material")) { List <MB3_TextureBaker> selectedBakers = _getBakersFromTargets(targets); foreach (MB3_TextureBaker tb in selectedBakers) { tb.CreateAtlases(updateProgressBar, true, new MB3_EditorMethods()); EditorUtility.ClearProgressBar(); if (tb.textureBakeResults != null) { EditorUtility.SetDirty(momm.textureBakeResults); } } } GUI.backgroundColor = oldColor; textureBaker.ApplyModifiedProperties(); if (GUI.changed) { textureBaker.SetIsDifferentCacheDirty(); } }
public void DrawGUI(SerializedObject textureBaker, MB3_TextureBaker momm, System.Type editorWindow) { if (textureBaker == null) { return; } textureBaker.Update(); showInstructions = EditorGUILayout.Foldout(showInstructions, "Instructions:"); if (showInstructions) { EditorGUILayout.HelpBox("1. Add scene objects or prefabs to combine. For best results these should use the same shader as result material.\n\n" + "2. Create Empty Assets For Combined Material(s)\n\n" + "3. Check that shader on result material(s) are correct.\n\n" + "4. Bake materials into combined material(s).\n\n" + "5. Look at warnings/errors in console. Decide if action needs to be taken.\n\n" + "6. You are now ready to build combined meshs or adjust meshes to use the combined material(s).", UnityEditor.MessageType.None); } EditorGUILayout.PropertyField(logLevel, logLevelContent); EditorGUILayout.Separator(); // Selected objects EditorGUILayout.BeginVertical(editorStyles.editorBoxBackgroundStyle); EditorGUILayout.LabelField("Objects To Be Combined", EditorStyles.boldLabel); if (GUILayout.Button(openToolsWindowLabelContent)) { MB3_MeshBakerEditorWindowInterface mmWin = (MB3_MeshBakerEditorWindowInterface)EditorWindow.GetWindow(editorWindow); mmWin.target = (MB3_MeshBakerRoot)momm; } object[] objs = MB3_EditorMethods.DropZone("Drag & Drop Renderers Or Parents Here To Add Objects To Be Combined", 300, 50); MB3_EditorMethods.AddDroppedObjects(objs, momm); EditorGUILayout.PropertyField(objsToMesh, objectsToCombineGUIContent, true); EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Select Objects In Scene")) { Selection.objects = momm.GetObjectsToCombine().ToArray(); if (momm.GetObjectsToCombine().Count > 0) { SceneView.lastActiveSceneView.pivot = momm.GetObjectsToCombine()[0].transform.position; } } if (GUILayout.Button(gc_SortAlongAxis)) { MB3_MeshBakerRoot.ZSortObjects sorter = new MB3_MeshBakerRoot.ZSortObjects(); sorter.sortAxis = sortOrderAxis.vector3Value; sorter.SortByDistanceAlongAxis(momm.GetObjectsToCombine()); } EditorGUILayout.PropertyField(sortOrderAxis, GUIContent.none); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); // output EditorGUILayout.Separator(); EditorGUILayout.LabelField("Output", EditorStyles.boldLabel); EditorGUILayout.PropertyField(resultType); if (GUILayout.Button(createPrefabAndMaterialLabelContent)) { string newPrefabPath = EditorUtility.SaveFilePanelInProject("Asset name", "", "asset", "Enter a name for the baked texture results"); if (newPrefabPath != null) { CreateCombinedMaterialAssets(momm, newPrefabPath); } } EditorGUILayout.PropertyField(textureBakeResults, textureBakeResultsGUIContent); if (textureBakeResults.objectReferenceValue != null) { showContainsReport = EditorGUILayout.Foldout(showContainsReport, "Shaders & Materials Contained"); if (showContainsReport) { EditorGUILayout.HelpBox(((MB2_TextureBakeResults)textureBakeResults.objectReferenceValue).GetDescription(), MessageType.Info); } } if (resultType.enumValueIndex == (int)MB2_TextureBakeResults.ResultType.textureArray) { MB_TextureBakerConfigureTextureArrays.DrawTextureArrayConfiguration(momm, textureBaker, this); } else { EditorGUILayout.PropertyField(doMultiMaterial, new GUIContent("Multiple Combined Materials")); if (momm.doMultiMaterial) { MB_TextureBakerEditorConfigureMultiMaterials.DrawMultipleMaterialsMappings(momm, textureBaker, this); } else { EditorGUILayout.PropertyField(resultMaterial, new GUIContent("Combined Mesh Material")); } } // settings int labelWidth = 200; EditorGUILayout.Separator(); EditorGUILayout.BeginVertical(editorStyles.editorBoxBackgroundStyle); EditorGUILayout.LabelField("Material Bake Options", EditorStyles.boldLabel); DrawPropertyFieldWithLabelWidth(atlasPadding, gc_atlasPadding, labelWidth); DrawPropertyFieldWithLabelWidth(maxAtlasSize, maxAtlasSizeGUIContent, labelWidth); DrawPropertyFieldWithLabelWidth(resizePowerOfTwoTextures, resizePowerOfTwoGUIContent, labelWidth); DrawPropertyFieldWithLabelWidth(maxTilingBakeSize, maxTilingBakeSizeGUIContent, labelWidth); EditorGUI.BeginDisabledGroup(momm.doMultiMaterial); DrawPropertyFieldWithLabelWidth(considerMeshUVs, fixOutOfBoundsGUIContent, labelWidth); EditorGUI.EndDisabledGroup(); if (texturePackingAlgorithm.intValue == (int)MB2_PackingAlgorithmEnum.MeshBakerTexturePacker || texturePackingAlgorithm.intValue == (int)MB2_PackingAlgorithmEnum.MeshBakerTexturePacker_Fast) { DrawPropertyFieldWithLabelWidth(forcePowerOfTwoAtlas, forcePowerOfTwoAtlasContent, labelWidth); } DrawPropertyFieldWithLabelWidth(considerNonTextureProperties, considerNonTexturePropertiesContent, labelWidth); if (texturePackingAlgorithm.intValue == (int)MB2_PackingAlgorithmEnum.UnitysPackTextures) { EditorGUILayout.HelpBox("Unity's texture packer has memory problems and frequently crashes the editor.", MessageType.Warning); } EditorGUILayout.PropertyField(texturePackingAlgorithm, texturePackingAgorithmGUIContent); if (MB3_TextureCombinerPipeline.USE_EXPERIMENTAL_HOIZONTALVERTICAL) { if (texturePackingAlgorithm.enumValueIndex == (int)MB2_PackingAlgorithmEnum.MeshBakerTexturePacker_Horizontal) { EditorGUILayout.PropertyField(useMaxAtlasWidthOverride, gc_useMaxAtlasWidthOverride); if (!useMaxAtlasWidthOverride.boolValue) { EditorGUI.BeginDisabledGroup(true); } EditorGUILayout.PropertyField(maxAtlasWidthOverride, gc_overrideMaxAtlasWidth); if (!useMaxAtlasWidthOverride.boolValue) { EditorGUI.EndDisabledGroup(); } } else if (texturePackingAlgorithm.enumValueIndex == (int)MB2_PackingAlgorithmEnum.MeshBakerTexturePacker_Vertical) { EditorGUILayout.PropertyField(useMaxAtlasHeightOverride, gc_useMaxAtlasHeightOverride); if (!useMaxAtlasHeightOverride.boolValue) { EditorGUI.BeginDisabledGroup(true); } EditorGUILayout.PropertyField(maxAtlasHeightOverride, gc_overrideMaxAtlasHeight); if (!useMaxAtlasHeightOverride.boolValue) { EditorGUI.EndDisabledGroup(); } } } EditorGUILayout.PropertyField(customShaderProperties, customShaderPropertyNamesGUIContent, true); EditorGUILayout.EndVertical(); EditorGUILayout.Separator(); Color oldColor = GUI.backgroundColor; GUI.color = buttonColor; if (GUILayout.Button("Bake Materials Into Combined Material")) { momm.CreateAtlases(updateProgressBar, true, new MB3_EditorMethods()); EditorUtility.ClearProgressBar(); if (momm.textureBakeResults != null) { EditorUtility.SetDirty(momm.textureBakeResults); } } GUI.backgroundColor = oldColor; textureBaker.ApplyModifiedProperties(); if (GUI.changed) { textureBaker.SetIsDifferentCacheDirty(); } }
private static bool _BakeIntoCombinedPrefab(MB3_MeshBakerCommon mom, bool createdDummyTextureBakeResults, ref SerializedObject so) { bool success = false; List <Transform> tempPrefabInstanceRoots = null; GameObject[] objsToCombine = mom.GetObjectsToCombine().ToArray(); if (mom.meshCombiner.settings.renderType == MB_RenderType.skinnedMeshRenderer) { tempPrefabInstanceRoots = new List <Transform>(); // We are going to move bones of source objs and transforms into our combined mesh prefab so make some duplicates // so that we don't destroy a setup. _DuplicateSrcObjectInstancesAndUnpack(mom.meshCombiner.settings.renderType, objsToCombine, tempPrefabInstanceRoots); } try { MB3_EditorMethods editorMethods = new MB3_EditorMethods(); mom.ClearMesh(editorMethods); if (mom.AddDeleteGameObjects(objsToCombine, null, false)) { success = true; mom.Apply(UnwrapUV2); if (mom.parentSceneObject != null) { mom.meshCombiner.resultSceneObject.transform.parent = mom.parentSceneObject; } if (createdDummyTextureBakeResults) { Debug.Log(String.Format("Successfully baked {0} meshes each material is mapped to its own submesh.", mom.GetObjectsToCombine().Count)); } else { Debug.Log(String.Format("Successfully baked {0} meshes", mom.GetObjectsToCombine().Count)); } string prefabPth = AssetDatabase.GetAssetPath(mom.resultPrefab); if (prefabPth == null || prefabPth.Length == 0) { Debug.LogError("Could not save result to prefab. Result Prefab value is not an Asset."); success = false; } else { string baseName = Path.GetFileNameWithoutExtension(prefabPth); string folderPath = prefabPth.Substring(0, prefabPth.Length - baseName.Length - 7); string newFilename = folderPath + baseName + "-mesh"; SaveMeshsToAssetDatabase(mom, folderPath, newFilename); GameObject rootGO = RebuildPrefab(mom, ref so, mom.resultPrefabLeaveInstanceInSceneAfterBake, tempPrefabInstanceRoots, objsToCombine); } } else { success = false; } } #pragma warning disable 0169 catch (Exception ex) #pragma warning restore 0169 { throw; } finally { // Clean up temporary created instances. If success was true then they should have been added to a prefab // and cleaned up for us. if (success == false) { if (tempPrefabInstanceRoots != null) { for (int i = 0; i < tempPrefabInstanceRoots.Count; i++) { MB_Utility.Destroy(tempPrefabInstanceRoots[i]); } } } } return(success); }