コード例 #1
0
    public override void OnInspectorGUI()
    {
        MB2_MeshBaker tb = (MB2_MeshBaker)target;

        if (GUILayout.Button(" MIGRATE COMPONENTS TO VERSION 3 "))
        {
            GameObject go = tb.gameObject;
            MB2_TextureBakerEditor.MigrateTestureBakerToVersion3Component(go);
            MB2_MultiMeshBakerEditor.MigrateMultiMeshBakerToVersion3Component(go);
            MigrateMeshBakerToVersion3Component(go);
        }
        mbe.OnInspectorGUI((MB2_MeshBakerCommon)target, typeof(MB_MeshBakerEditorWindow));
    }
コード例 #2
0
    public void DrawGUI(MB2_TextureBaker mom)
    {
        if (textureBaker == null)
        {
            _init(mom);
        }

        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.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("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)
            {
                MB2_TextureBakerEditor.CreateCombinedMaterialAssets(mom, 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);
            }
        }
        EditorGUILayout.PropertyField(doMultiMaterial, new GUIContent("Multiple Combined Materials"));

        if (mom.doMultiMaterial)
        {
            EditorGUILayout.LabelField("Source Material To Combined Mapping", EditorStyles.boldLabel);
            if (GUILayout.Button(configMultiMatFromObjsContent))
            {
                ConfigureMutiMaterialsFromObjsToCombine(mom);
            }
            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();
                    string s = "";
                    if (i < mom.resultMaterials.Length && mom.resultMaterials[i] != null && mom.resultMaterials[i].combinedMaterial != null)
                    {
                        s = mom.resultMaterials[i].combinedMaterial.shader.ToString();
                    }
                    EditorGUILayout.LabelField("---------- submesh:" + i + " " + s, 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("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.PropertyField(texturePackingAlgorithm, texturePackingAgorithmGUIContent);

        EditorGUILayout.Separator();
        if (GUILayout.Button("Bake Materials Into Combined Material"))
        {
            mom.CreateAndSaveAtlases(updateProgressBar, System.IO.File.WriteAllBytes);
            EditorUtility.ClearProgressBar();
            EditorUtility.SetDirty(mom.textureBakeResults);
        }
        textureBaker.ApplyModifiedProperties();
        textureBaker.SetIsDifferentCacheDirty();
    }