public override void OnInspectorGUI()
    {
        meshBaker.Update();

        showInstructions = EditorGUILayout.Foldout(showInstructions, "Instructions:");
        if (showInstructions)
        {
            EditorGUILayout.HelpBox("1. Create empty assets for result materials and (if needed) result prefab.\n\n" +
                                    "2. Select shader on result materials.\n\n" +
                                    "3. Add scene objects or prefabs to combine. For best results these should use the same shader as result material.\n\n" +
                                    "4. Select an output option.\n\n" +
                                    "5. Bake objects.\n\n" +
                                    "6. Look at warnings/errors in console. Decide if action needs to be taken.\n\n" +
                                    "5. Use the combined/adjusted meshes.\n\n" +
                                    "7. (optional) Disable renderers in source objects.\n\n" +
                                    "8. (optional) Remove the MeshBaker object. You may want to keep it for easy re-baking if something changes in the source objects.", UnityEditor.MessageType.None);

            EditorGUILayout.Separator();
        }

        MB_MeshBaker mom = (MB_MeshBaker)target;

        EditorGUILayout.LabelField("Options", EditorStyles.boldLabel);
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.PropertyField(fixOutOfBoundsUVs, fixOutOfBoundsGUIContent);
        EditorGUILayout.PropertyField(doMultiMaterial, new GUIContent("Multiple Combined Materials"));
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.PropertyField(atlasPadding, new GUIContent("Atlas Padding"));
        EditorGUILayout.PropertyField(resizePowerOfTwoTextures, resizePowerOfTwoGUIContent);
        EditorGUILayout.PropertyField(customShaderPropNames, customShaderPropertyNamesGUIContent, true);

        if (mom.doMultiMaterial)
        {
            MB_EditorUtil.DrawSeparator();
            EditorGUILayout.LabelField("Source Material To Combined Mapping", EditorStyles.boldLabel);
            EditorGUILayout.BeginHorizontal();
            resultMaterialsFoldout = EditorGUILayout.Foldout(resultMaterialsFoldout, combinedMaterialsGUIContent);
            if (GUILayout.Button(insertContent, EditorStyles.miniButtonLeft, buttonWidth))
            {
                if (resultMaterials.arraySize == 0)
                {
                    mom.resultMaterials = new MB_MultiMaterial[1];
                }
                else
                {
                    resultMaterials.InsertArrayElementAtIndex(resultMaterials.arraySize - 1);
                }
            }
            if (GUILayout.Button(deleteContent, EditorStyles.miniButtonRight, buttonWidth))
            {
                resultMaterials.DeleteArrayElementAtIndex(resultMaterials.arraySize - 1);
            }
            EditorGUILayout.EndHorizontal();
            if (resultMaterialsFoldout)
            {
                for (int i = 0; i < resultMaterials.arraySize; i++)
                {
                    EditorGUILayout.Separator();
                    EditorGUILayout.LabelField("---------- submesh:" + i);
                    EditorGUILayout.Separator();
                    SerializedProperty resMat = resultMaterials.GetArrayElementAtIndex(i);
                    EditorGUILayout.PropertyField(resMat.FindPropertyRelative("combinedMaterial"));
                    SerializedProperty sourceMats = resMat.FindPropertyRelative("sourceMaterials");
                    EditorGUILayout.PropertyField(sourceMats, true);
                }
            }
        }
        else
        {
            MB_EditorUtil.DrawSeparator();
            EditorGUILayout.LabelField("Combined Material", EditorStyles.boldLabel);
            EditorGUILayout.PropertyField(resultMaterial, new GUIContent("Combined Mesh Material"));
        }

        MB_EditorUtil.DrawSeparator();
        EditorGUILayout.LabelField("Objects To Be Combined", EditorStyles.boldLabel);
        if (GUILayout.Button(openToolsWindowLabelContent))
        {
            MB_MeshBakerEditorWindow mmWin = (MB_MeshBakerEditorWindow)EditorWindow.GetWindow(typeof(MB_MeshBakerEditorWindow));
            mmWin.target = (MB_MeshBaker)target;
        }
        EditorGUILayout.PropertyField(objsToMesh, new GUIContent("Objects To Be Combined"), true);
        MB_EditorUtil.DrawSeparator();

        EditorGUILayout.Separator();
        mom.resultPrefab = (GameObject)EditorGUILayout.ObjectField("Combined Mesh Prefab", mom.resultPrefab, typeof(GameObject), false);
        EditorGUILayout.PropertyField(outputOption, outputOptionGUIContent);
        if (GUILayout.Button("Bake"))
        {
            if (mom.outputOption == MB_OutputOptions.bakeIntoPrefab)
            {
                bakeMeshesIntoPrefab();
            }
            else if (mom.outputOption == MB_OutputOptions.bakeMeshsInPlace)
            {
                bakeMeshesInPlace();
            }
            else if (mom.outputOption == MB_OutputOptions.bakeTextureAtlasesOnly)
            {
                bakeTexturesOnly();
            }
        }
        EditorGUILayout.Separator();


        MB_EditorUtil.DrawSeparator();
        EditorGUILayout.LabelField("Utilities", EditorStyles.boldLabel);
        if (GUILayout.Button(createPrefabAndMaterialLabelContent))
        {
            string newPrefabPath = EditorUtility.SaveFilePanelInProject("Prefab name", "", "prefab", "Enter a name for the combined mesh prefab");
            if (newPrefabPath != null)
            {
                createNewPrefab(newPrefabPath);
            }
        }
        string enableRenderersLabel;

        if (mom.disableSourceRenderers)
        {
            enableRenderersLabel = "Disable Renderers On Combined Objects";
        }
        else
        {
            enableRenderersLabel = "Enable Renderers On Combined Objects";
        }
        if (GUILayout.Button(enableRenderersLabel))
        {
            mom.disableSourceRenderers = !mom.disableSourceRenderers;
            mom.EnableDisableSourceObjectRenderers(mom.disableSourceRenderers);
        }
        meshBaker.ApplyModifiedProperties();
    }
Exemplo n.º 2
0
    public void DrawGUI(MB2_MeshBakerCommon target)
    {
        if (meshBaker == null)
        {
            _init(target);
        }

        meshBaker.Update();

        showInstructions = EditorGUILayout.Foldout(showInstructions, "Instructions:");
        if (showInstructions)
        {
            EditorGUILayout.HelpBox("1. Bake combined material(s).\n\n" +
                                    "2. If necessary set the 'Material 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();
        }

        MB2_MeshBakerCommon mom = (MB2_MeshBakerCommon)target;

        EditorGUILayout.PropertyField(textureBakeResults, textureBakeResultsGUIContent);

        EditorGUILayout.LabelField("Objects To Be Combined", EditorStyles.boldLabel);
        if (mom.GetComponent <MB2_TextureBaker>() != null)
        {
            EditorGUILayout.PropertyField(useObjsToMeshFromTexBaker, useTextureBakerObjsGUIContent);
        }
        else
        {
            useObjsToMeshFromTexBaker.boolValue = false;
        }

        if (!mom.useObjsToMeshFromTexBaker)
        {
            if (GUILayout.Button(openToolsWindowLabelContent))
            {
                MB_MeshBakerEditorWindow mmWin = (MB_MeshBakerEditorWindow)EditorWindow.GetWindow(typeof(MB_MeshBakerEditorWindow));
                mmWin.target = (MB2_MeshBakerRoot)target;
            }
            EditorGUILayout.PropertyField(objsToMesh, objectsToCombineGUIContent, true);
        }

        EditorGUILayout.LabelField("Output", EditorStyles.boldLabel);

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.PropertyField(doNorm, doNormGUIContent);
        EditorGUILayout.PropertyField(doTan, doTanGUIContent);
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.PropertyField(doUV, doUVGUIContent);
        EditorGUILayout.PropertyField(doUV1, doUV1GUIContent);
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.PropertyField(doCol, doColGUIContent);

        if (mom.lightmapOption == MB2_LightmapOptions.generate_new_UV2_layout)
        {
            EditorGUILayout.HelpBox("Generating new lightmap UVs can split vertices which can push the number of vertices over the 64k limit.", MessageType.Warning);
        }
        EditorGUILayout.PropertyField(lightmappingOption, lightmappingOptionGUIContent);

        EditorGUILayout.PropertyField(outputOptions, outputOptoinsGUIContent);
        EditorGUILayout.PropertyField(renderType, renderTypeGUIContent);
        if (mom.outputOption == MB2_OutputOptions.bakeIntoSceneObject)
        {
            mom.resultSceneObject = (GameObject)EditorGUILayout.ObjectField("Combined Mesh Object", mom.resultSceneObject, typeof(GameObject), true);
        }
        else if (mom.outputOption == MB2_OutputOptions.bakeIntoPrefab)
        {
            mom.resultPrefab = (GameObject)EditorGUILayout.ObjectField("Combined Mesh Prefab", mom.resultPrefab, typeof(GameObject), true);
        }

        if (GUILayout.Button("Bake"))
        {
            bake(mom);
        }

        string enableRenderersLabel;
        bool   disableRendererInSource = false;

        if (mom.objsToMesh.Count > 0)
        {
            Renderer r = MB_Utility.GetRenderer(mom.objsToMesh[0]);
            if (r != null && r.enabled)
            {
                disableRendererInSource = true;
            }
        }
        if (disableRendererInSource)
        {
            enableRenderersLabel = "Disable Renderers On Combined Objects";
        }
        else
        {
            enableRenderersLabel = "Enable Renderers On Combined Objects";
        }
        if (GUILayout.Button(enableRenderersLabel))
        {
            mom.EnableDisableSourceObjectRenderers(!disableRendererInSource);
        }

        meshBaker.ApplyModifiedProperties();
        meshBaker.SetIsDifferentCacheDirty();
    }
Exemplo n.º 3
0
    public void DrawGUI(MB2_TextureBaker mom)
    {
        if (meshBaker == null)
        {
            _init(mom);
        }

        meshBaker.Update();

        showInstructions = EditorGUILayout.Foldout(showInstructions, "Instructions:");
        if (showInstructions)
        {
            EditorGUILayout.HelpBox("1. Create Empty Assets For Combined Material(s)\n\n" +
                                    "2. Select shader on result material(s).\n\n" +
                                    "3. Add scene objects or prefabs to combine. For best results these should use the same shader as result material.\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);
        }

        //MB2_TextureBaker mom = (MB2_TextureBaker) target;

        EditorGUILayout.Separator();
        EditorGUILayout.LabelField("Output", EditorStyles.boldLabel);
        if (GUILayout.Button(createPrefabAndMaterialLabelContent))
        {
            string newPrefabPath = EditorUtility.SaveFilePanelInProject("Asset name", "", "asset", "Enter a name for the baked texture results");
            if (newPrefabPath != null)
            {
                createCombinedMaterialAssets(mom, newPrefabPath);
            }
        }
        EditorGUILayout.PropertyField(textureBakeResults, textureBakeResultsGUIContent);
        EditorGUILayout.PropertyField(doMultiMaterial, new GUIContent("Multiple Combined Materials"));

        if (mom.doMultiMaterial)
        {
            EditorGUILayout.LabelField("Source Material To Combined Mapping", EditorStyles.boldLabel);
            EditorGUILayout.BeginHorizontal();
            resultMaterialsFoldout = EditorGUILayout.Foldout(resultMaterialsFoldout, combinedMaterialsGUIContent);
            if (GUILayout.Button(insertContent, EditorStyles.miniButtonLeft, buttonWidth))
            {
                if (resultMaterials.arraySize == 0)
                {
                    mom.resultMaterials = new MB_MultiMaterial[1];
                }
                else
                {
                    resultMaterials.InsertArrayElementAtIndex(resultMaterials.arraySize - 1);
                }
            }
            if (GUILayout.Button(deleteContent, EditorStyles.miniButtonRight, buttonWidth))
            {
                resultMaterials.DeleteArrayElementAtIndex(resultMaterials.arraySize - 1);
            }
            EditorGUILayout.EndHorizontal();
            if (resultMaterialsFoldout)
            {
                for (int i = 0; i < resultMaterials.arraySize; i++)
                {
                    EditorGUILayout.Separator();
                    EditorGUILayout.LabelField("---------- submesh:" + i, EditorStyles.boldLabel);
                    EditorGUILayout.Separator();
                    SerializedProperty resMat = resultMaterials.GetArrayElementAtIndex(i);
                    EditorGUILayout.PropertyField(resMat.FindPropertyRelative("combinedMaterial"));
                    SerializedProperty sourceMats = resMat.FindPropertyRelative("sourceMaterials");
                    EditorGUILayout.PropertyField(sourceMats, true);
                }
            }
        }
        else
        {
            EditorGUILayout.PropertyField(resultMaterial, new GUIContent("Combined Mesh Material"));
        }

        EditorGUILayout.Separator();
        EditorGUILayout.LabelField("Objects To Be Combined", EditorStyles.boldLabel);
        if (GUILayout.Button(openToolsWindowLabelContent))
        {
            MB_MeshBakerEditorWindow mmWin = (MB_MeshBakerEditorWindow)EditorWindow.GetWindow(typeof(MB_MeshBakerEditorWindow));
            mmWin.target = (MB2_MeshBakerRoot)mom;
        }
        EditorGUILayout.PropertyField(objsToMesh, objectsToCombineGUIContent, true);

        EditorGUILayout.Separator();
        EditorGUILayout.LabelField("Material Bake Options", EditorStyles.boldLabel);
        EditorGUILayout.PropertyField(atlasPadding, new GUIContent("Atlas Padding"));
        EditorGUILayout.PropertyField(resizePowerOfTwoTextures, resizePowerOfTwoGUIContent);
        EditorGUILayout.PropertyField(customShaderPropNames, customShaderPropertyNamesGUIContent, true);
        EditorGUILayout.PropertyField(maxTilingBakeSize, maxTilingBakeSizeGUIContent);
        EditorGUILayout.PropertyField(fixOutOfBoundsUVs, fixOutOfBoundsGUIContent);

        EditorGUILayout.Separator();
        if (GUILayout.Button("Bake Materials Into Combined Material"))
        {
            bake(mom);
        }
        meshBaker.ApplyModifiedProperties();
        meshBaker.SetIsDifferentCacheDirty();
    }