コード例 #1
0
    public override void OnInspectorGUI()
    {
        AfsFoliageTool = new SerializedObject(target);
        GetProperties();
        AfsFoliageTool script       = (AfsFoliageTool)target;
        Color          myBlue       = new Color(0.5f, 0.7f, 1.0f, 1.0f);
        Color          SplitterCol  = new Color(1f, 1f, 1f, 0.075f);
        Color          SplitterCol1 = new Color(.6f, .9f, .22f, .005f);
        Color          myCol        = new Color(.5f, .8f, .0f, 1f);     // Light Green
        Color          myBgCol      = SplitterCol;

        myBgCol = myCol;         //new Color(.5f, .75f, .24f, 1f);
        if (!EditorGUIUtility.isProSkin)
        {
            // myCol = new Color(0.0f,0.15f,0.55f,1.0f);	// Dark Blue
            myCol        = new Color(0.05f, 0.45f, 0.0f, 1.0f);                 // Dark Green
            myBgCol      = new Color(0.94f, 0.94f, 0.94f, 1.0f);
            SplitterCol  = new Color(0f, 0f, 0f, 0.125f);
            SplitterCol1 = new Color(1f, 1f, 1f, 0.5f);
        }

        // Custom Foldout
        GUIStyle myFoldoutStyle = new GUIStyle(EditorStyles.foldout);

        myFoldoutStyle.fontStyle = FontStyle.Bold;
        myFoldoutStyle.fontSize  = 12;

        myFoldoutStyle.normal.textColor   = myCol;
        myFoldoutStyle.onNormal.textColor = myCol;
        //myFoldoutStyle.hover.textColor = Color.white;
        //myFoldoutStyle.onHover.textColor = Color.white;
        myFoldoutStyle.active.textColor    = myCol;
        myFoldoutStyle.onActive.textColor  = myCol;
        myFoldoutStyle.focused.textColor   = myCol;
        myFoldoutStyle.onFocused.textColor = myCol;

        // Help Foldout
        GUIStyle helpFoldoutStyle = new GUIStyle(EditorStyles.foldout);

        //helpFoldoutStyle.fixedWidth = 40;
        //helpFoldoutStyle.alignment = TextAnchor.MiddleRight;
        helpFoldoutStyle.normal.textColor    = myBlue;
        helpFoldoutStyle.onNormal.textColor  = myBlue;
        helpFoldoutStyle.active.textColor    = myBlue;
        helpFoldoutStyle.onActive.textColor  = myBlue;
        helpFoldoutStyle.focused.textColor   = myBlue;
        helpFoldoutStyle.onFocused.textColor = myBlue;

        // Custom Label
        GUIStyle myLabel = new GUIStyle(EditorStyles.label);

        myLabel.normal.textColor   = myCol;
        myLabel.onNormal.textColor = myCol;

        // Custom Label Bold
        GUIStyle myLabelBold = new GUIStyle(EditorStyles.label);

        myLabelBold.fontStyle          = FontStyle.Bold;
        myLabelBold.normal.textColor   = myCol;
        myLabelBold.onNormal.textColor = myCol;

        // Custom Label Big Bold
        GUIStyle myLabelBigBold = new GUIStyle(EditorStyles.label);

        myLabelBigBold.fontStyle        = FontStyle.Bold;
        myLabelBigBold.fontSize         = 12;
        myLabelBigBold.normal.textColor = myCol;

        // Default icon Size
        EditorGUIUtility.SetIconSize(new Vector2(16, 16));

        // Enable rich text for helpboxes
        GUIStyle helpBoxes = GUI.skin.GetStyle("HelpBox");

        helpBoxes.richText = true;

        EditorGUILayout.BeginVertical();
        GUILayout.Space(10);

        if (!script.hasBeenSaved)
        {
            GUILayout.Label("Get started", myLabel);
            EditorGUILayout.HelpBox("<b>Please note:</b>\nYou have to safe a new mesh before you can start editing it.", MessageType.Warning, true);
        }

        else
        {
            //	Call this only if the Application is not playing as static batching might produce strange messages
            if (!Application.isPlaying)
            {
                script.checkSubmeshes();
            }
            //	///////////////////////////
            //	///////////////////////////
            //
            //	Convert Tree & merge Submeshes
            //
            if (script.hasSubmeshes)
            {
                showSaveBtn           = false;
                script.mergeSubMeshes = true;
                EditorGUILayout.HelpBox("The assigned Mesh has more than one Submesh. " +
                                        "So the script assumes that you want to convert a tree.\n" +
                                        "Please select one of the options below.", MessageType.Warning, true);

                GUILayout.Space(5);

                //	//////////////////////////////////
                //	Convert to Simple Tree
                GUI.backgroundColor = myBgCol;
                EditorGUILayout.BeginVertical("Box");
                GUI.color = Color.white;                         //myCol;
                // Foldout incl. Icon
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(-2);
                EditorGUI.indentLevel++;
                EditorGUILayout.BeginVertical();
                // Only icon gets rendered
                script.convert2simpletree = EditorGUILayout.Foldout(script.convert2simpletree, "Convert Tree into flattened Tree", myFoldoutStyle);
                EditorGUILayout.EndVertical();
                EditorGUI.indentLevel--;
                EditorGUILayout.BeginVertical(GUILayout.Width(20));
                GUILayout.Space(3);
                // Label needs width!
                EditorGUILayout.LabelField(new GUIContent(icnTree), GUILayout.Width(20), GUILayout.Height(20));
                EditorGUILayout.EndVertical();
                EditorGUILayout.EndHorizontal();
                GUILayout.Space(-2);
                GUI.backgroundColor = Color.white;
                EditorGUILayout.EndVertical();
                // FoldoutContent
                if (script.convert2simpletree)
                {
                    script.convert2simpletree = true;
                    script.convert2foliage    = false;

                    GUILayout.Space(-5);
                    EditorGUILayout.BeginVertical("Box");
                    GUILayout.Space(10);
                    GUILayout.Label("Mesh Processing", myLabel);
                    EditorGUILayout.HelpBox("Converting a tree into a flattened one just flattens the submeshes so as result you will get a tree with only one material.\n" +
                                            "Bending parameters will be copied.", MessageType.None, true);

                    GUILayout.Space(10);
                    GUILayout.Label("Texture Processing", myLabel);
                    // Grab Textures
                    if (script.sourceTexDiffuse == null)
                    {
                        script.grabDiffuse();
                    }
                    if (script.sourceTex1 == null)
                    {
                        script.grabTranslucencyGloss();
                    }

                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.BeginVertical();
                    GUILayout.Label("diffuse");
                    script.sourceTexDiffuse = (Texture2D)EditorGUILayout.ObjectField(script.sourceTexDiffuse, typeof(Texture2D), false, GUILayout.MinHeight(64), GUILayout.MinWidth(64), GUILayout.MaxWidth(64));
                    EditorGUILayout.EndVertical();

                    EditorGUILayout.BeginVertical();
                    GUILayout.Label("translucency_gloss");
                    script.sourceTex1 = (Texture2D)EditorGUILayout.ObjectField(script.sourceTex1, typeof(Texture2D), false, GUILayout.MinHeight(64), GUILayout.MinWidth(64), GUILayout.MaxWidth(64));
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.EndHorizontal();
                    GUILayout.Space(4);
                    //
                    EditorGUILayout.BeginVertical();
                    EditorGUILayout.BeginHorizontal();
                    toolTip = "If your tree uses one of the most common texture setups the script can automatically fill the proper parts of the translucency map with black so the bark will be completely opaque.\n" +
                              "Otherwise you will have to edit the generated texture manually and fill those parts of the red color channel with black where the tree should be fully opaque.";
                    //EditorGUILayout.LabelField(new GUIContent("Texture Split", toolTip), GUILayout.Width(80));
                    //script.TextureSplitSelected = (TextureSplit)EditorGUILayout.EnumPopup(script.TextureSplitSelected);
                    EditorGUILayout.PropertyField(TextureSplitSelected, new GUIContent("Texture Split", toolTip));
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.EndVertical();

                    GUILayout.Space(5);
                    if (!EditorApplication.isPlaying && script.sourceTexDiffuse != null && script.sourceTex1 != null)
                    {
                        if (GUILayout.Button("Convert Tree", GUILayout.Height(34)))
                        {
                            script.hasChanged = false;
                            // Save mesh
                            script.SaveNewPlantMesh();
                            // Save textures
                            mergeTextureTree();
                            // Update Materials
                            script.updateSimpleTree();
                            script.simpleTreeConverted = true;
                        }
                    }
                    else
                    {
                        GUI.enabled = false;
                        GUILayout.Button("Convert Tree", GUILayout.Height(34));
                        GUI.enabled = true;
                    }
                    GUILayout.Space(3);
                    EditorGUILayout.EndVertical();
                }

                GUILayout.Space(5);

                //	//////////////////////////////////
                //	Convert to Foliage Shader
                GUI.backgroundColor = myBgCol;
                EditorGUILayout.BeginVertical("Box");
                GUI.color = Color.white;                         //myCol;
                // Foldout incl. Icon
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(-2);
                EditorGUI.indentLevel++;
                EditorGUILayout.BeginVertical();
                // Only icon gets rendered
                script.convert2foliage = EditorGUILayout.Foldout(script.convert2foliage, "Convert Tree for Foliage Shader", myFoldoutStyle);
                EditorGUILayout.EndVertical();
                EditorGUI.indentLevel--;
                EditorGUILayout.BeginVertical(GUILayout.Width(20));
                GUILayout.Space(3);
                // Label needs width!
                EditorGUILayout.LabelField(new GUIContent(icnTree), GUILayout.Width(20), GUILayout.Height(20));
                EditorGUILayout.EndVertical();
                EditorGUILayout.EndHorizontal();
                GUILayout.Space(-2);
                GUI.backgroundColor = Color.white;
                EditorGUILayout.EndVertical();
                // FoldoutContent
                if (script.convert2foliage)
                {
                    script.convert2simpletree = false;
                    script.convert2foliage    = true;
                    script.delete2ndUV        = true;

                    GUILayout.Space(-5);
                    EditorGUILayout.BeginVertical("Box");
                    GUILayout.Space(10);
                    GUILayout.Label("Mesh Processing", myLabel);
                    //script.BendingModeSelected = (BendingModes)EditorGUILayout.EnumPopup("Bending Parameters", script.BendingModeSelected);
                    EditorGUILayout.PropertyField(BendingModeSelected, new GUIContent("Bending Parameters"));
                    if (script.BendingModeSelected == BendingModes.VertexColors)
                    {
                        EditorGUILayout.HelpBox("If you chose 'Vertex Colors' you will have to set up primary and secondary bending from scratch. " +
                                                "Original bending parameters will be lost. Check 'generate UV2' if you want to support lightmapping.", MessageType.None, true);
                        script.storeUV4 = false;
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("If you chose 'Vertex Colors and UV4' the original bending parameters will simply be copied to UV4. " +
                                                "UV2 will be skipped unless you check 'generate UV2' (needed for lightmapping).", MessageType.None, true);
                        script.storeUV4 = true;
                    }
                    EditorGUILayout.BeginHorizontal();
                    script.generateUV2 = EditorGUILayout.Toggle("", script.generateUV2, GUILayout.Width(14));
                    GUILayout.Label("Generate UV2");
                    EditorGUILayout.EndHorizontal();
                    // Grab Textures
                    if (script.sourceTex0 == null)
                    {
                        script.grabNormalSpecular();
                    }
                    if (script.sourceTex1 == null)
                    {
                        script.grabTranslucencyGloss();
                    }
                    GUILayout.Space(10);
                    GUILayout.Label("Texture Processing", myLabel);
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.BeginVertical();
                    GUILayout.Label("normal_specular");
                    script.sourceTex0 = (Texture2D)EditorGUILayout.ObjectField(script.sourceTex0, typeof(Texture2D), false, GUILayout.MinHeight(64), GUILayout.MinWidth(64), GUILayout.MaxWidth(64));
                    EditorGUILayout.EndVertical();

                    EditorGUILayout.BeginVertical();
                    GUILayout.Label("translucency_gloss");
                    script.sourceTex1 = (Texture2D)EditorGUILayout.ObjectField(script.sourceTex1, typeof(Texture2D), false, GUILayout.MinHeight(64), GUILayout.MinWidth(64), GUILayout.MaxWidth(64));
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.EndHorizontal();
                    GUILayout.Space(4);
                    //
                    EditorGUILayout.BeginVertical();
                    EditorGUILayout.BeginHorizontal();
                    toolTip = "If your tree uses one of the most common texture setups the script can automatically fill the proper parts of the translucency map with black so the bark will be completely opaque.\n" +
                              "Otherwise you will have to edit the generated texture manually and fill those parts of the red color channel with black where the tree should be fully opaque.";
                    //EditorGUILayout.LabelField(new GUIContent("Texture Split", toolTip), GUILayout.Width(80));
                    //script.TextureSplitSelected = (TextureSplit)EditorGUILayout.EnumPopup(script.TextureSplitSelected);
                    EditorGUILayout.PropertyField(TextureSplitSelected, new GUIContent("Texture Split", toolTip));
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.EndVertical();

                    GUILayout.Space(5);
                    if (!EditorApplication.isPlaying && script.sourceTex0 != null && script.sourceTex1 != null)
                    {
                        if (GUILayout.Button("Convert Tree", GUILayout.Height(34)))
                        {
                            if (EditorUtility.DisplayDialog("Convert Tree to be compatible with the foliage shader?", "This will finally remove the 'tree' component from the gameobject. So please make sure that you are working on a copy.", "Convert", "Cancel"))
                            {
                                script.hasChanged = false;
                                // Save mesh
                                script.SaveNewPlantMesh();
                                if (script.savePath != "")
                                {
                                    // Save textures
                                    mergeTextureFoliage();
                                    // Update Materials
                                    script.updateFoliageTree();
                                    script.foliageTreeConverted = true;
                                    if (script.BendingModeSelected == BendingModes.VertexColorsAndUV4)
                                    {
                                        script.foliageTreeUV4Converted = true;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        GUI.enabled = false;
                        GUILayout.Button("Convert Tree", GUILayout.Height(34));
                        GUI.enabled = true;
                    }
                    GUILayout.Space(3);
                    // End Box
                    EditorGUILayout.EndVertical();
                }
            }

            //	////////////////////////////////
            //	////////////////////////////////
            //
            //	Success
            //
            if (script.simpleTreeConverted)
            {
                EditorGUILayout.HelpBox("The tree has been converted to a simple one. " +
                                        "Textures that needed to be updated have been created and assigned as well as a new Material.", MessageType.Warning, true);
                EditorGUILayout.HelpBox("As there is nothing else you can do here, you should simply remove the script.", MessageType.Warning, true);
            }

            if (script.foliageTreeConverted)
            {
                EditorGUILayout.HelpBox("The tree has been converted to be compatible with the foliage shaders. " +
                                        "Textures that needed to be updated have been created and assigned as well as a new Material.", MessageType.Warning, true);
                if (script.foliageTreeUV4Converted)
                {
                    EditorGUILayout.HelpBox("As there is nothing else you can do here, you should simply remove the script.", MessageType.Warning, true);
                }
                else
                {
                    EditorGUILayout.HelpBox("As you have chosen to store bending in vertex colors only you will have to set up primary and secondary bending below.", MessageType.Warning, true);
                }
            }


            //	////////////////////////////////
            //	////////////////////////////////
            //
            //	Rework meshes
            //
            if (!script.mergeSubMeshes && !script.simpleTreeConverted && !script.foliageTreeUV4Converted)
            {
                showSaveBtn = true;

                //	Set Bending
                GUI.backgroundColor = myBgCol;
                EditorGUILayout.BeginVertical("Box");
                GUI.color = Color.white;
                // Foldout incl. Icon
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(-2);
                EditorGUI.indentLevel++;
                EditorGUILayout.BeginVertical();
                // Only icon gets rendered
                script.adjustBending = EditorGUILayout.Foldout(script.adjustBending, "Set Bending", myFoldoutStyle);
                EditorGUILayout.EndVertical();
                EditorGUI.indentLevel--;
                EditorGUILayout.BeginVertical(GUILayout.Width(20));
                GUILayout.Space(3);
                // Label needs width!
                EditorGUILayout.LabelField(new GUIContent(icnBending), GUILayout.Width(20), GUILayout.Height(20));
                EditorGUILayout.EndVertical();
                EditorGUILayout.EndHorizontal();
                GUILayout.Space(-2);
                GUI.backgroundColor = Color.white;
                EditorGUILayout.EndVertical();
                // FoldoutContent
                if (script.adjustBending)
                {
                    script.adjustVertexColors = false;
                    GUILayout.Space(-5);
                    EditorGUILayout.BeginVertical("Box");
                    DrawSplitter1(EditorGUILayout.GetControlRect(false, 4), SplitterCol1);
                    int RestoreBendingMode = BendingModeSelected.enumValueIndex;
                    EditorGUI.BeginChangeCheck();
                    EditorGUILayout.PropertyField(BendingModeSelected, new GUIContent("Bending Parameters"));
                    if (EditorGUI.EndChangeCheck())
                    {
                        if (!EditorUtility.DisplayDialog("Change Bending Mode?", "This will effect all plants sharing the assigned material as soon as you hit 'Apply'.", "Change", "Cancel"))
                        {
                            BendingModeSelected.enumValueIndex = RestoreBendingMode;
                        }
                        ;
                    }
                    GUILayout.Space(5);

                    //		Classic Bending
                    if (script.BendingModeSelected == BendingModes.VertexColors)
                    {
                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("Primary and secondary Bending", myLabel);
                        Rect h1rect = EditorGUILayout.GetControlRect(false, 15);
                        h1rect.x   += h1rect.width - 30;
                        hSetBending = EditorGUI.Foldout(h1rect, hSetBending, "Help", helpFoldoutStyle);
                        EditorGUILayout.EndHorizontal();
                        // Help
                        if (hSetBending)
                        {
                            EditorGUILayout.HelpBox("Set up vertex colors for primary and secondary bending from scratch. " +
                                                    "Using this function will overwrite all vertex color blue values originally baked into the mesh.", MessageType.None, true);
                        }
                        GUILayout.Space(2);
                    }

                    //		Bending stored in UV4
                    else if (script.BendingModeSelected == BendingModes.VertexColorsAndUV4)                       // use ref here
                    {
                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("Primary Bending", myLabel);
                        Rect h2rect = EditorGUILayout.GetControlRect(false, 15);
                        h2rect.x     += h2rect.width - 30;
                        hSetBendingUV = EditorGUI.Foldout(h2rect, hSetBendingUV, "Help", helpFoldoutStyle);
                        EditorGUILayout.EndHorizontal();
                        GUILayout.Space(2);
                        // Help
                        if (hSetBendingUV)
                        {
                            EditorGUILayout.HelpBox("Writes primary and secondary bending values to UV4 instead of vertex color blue. " +
                                                    "As soon as you hit 'Apply' the assigned material will be tweaked automatically.", MessageType.None, true);
                        }
                    }

                    // Bending y-axis

                    /*EditorGUILayout.BeginHorizontal();
                     *      script.Set1stBendingAlongY = EditorGUILayout.Toggle("", script.Set1stBendingAlongY, GUILayout.Width(14) );
                     *      EditorGUILayout.PropertyField(maxBendingValueY, new GUIContent("Along Y-axis"));
                     *      curvY.animationCurveValue = EditorGUILayout.CurveField("", curvY.animationCurveValue, new Color (0.0f, 1.0f, 1.0f, 0.75f), new Rect(0, 0, 1, 1), GUILayout.Width(40));
                     * EditorGUILayout.EndHorizontal();
                     * EditorGUILayout.BeginHorizontal();
                     *      script.Set1stBendingRelative2Pivot= EditorGUILayout.Toggle("", script.Set1stBendingRelative2Pivot, GUILayout.Width(14) );
                     *      GUILayout.Label ("Relative to Pivot");
                     * EditorGUILayout.EndHorizontal(); */

                    /*EditorGUILayout.BeginHorizontal();
                     *      string[] options = new string[] { " Along Y-Axis", " Relative to Pivot" };
                     *      //selected = GUILayout.SelectionGrid(selected, options, options.Length, EditorStyles.radioButton);
                     *      selected = GUILayout.SelectionGrid(selected, options, 1, EditorStyles.radioButton);
                     *
                     *      EditorGUILayout.PropertyField(maxBendingValueY, GUIContent.none);
                     *      curvY.animationCurveValue = EditorGUILayout.CurveField("", curvY.animationCurveValue, new Color (0.0f, 1.0f, 1.0f, 0.75f), new Rect(0, 0, 1, 1), GUILayout.Width(40));
                     * EditorGUILayout.EndHorizontal();*/

                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.PropertyField(Set1stBendingSelected, GUIContent.none, GUILayout.Width(112));
                    GUILayout.Space(10);
                    EditorGUILayout.PropertyField(maxBendingValueY, GUIContent.none);
                    curvY.animationCurveValue = EditorGUILayout.CurveField("", curvY.animationCurveValue, new Color(0.0f, 1.0f, 1.0f, 0.75f), new Rect(0, 0, 1, 1), GUILayout.Width(40));
                    EditorGUILayout.EndHorizontal();


                    if (script.BendingModeSelected == BendingModes.VertexColorsAndUV4)
                    {
                        GUILayout.Space(5);
                        GUILayout.Label("Secondary Bending", myLabel);
                    }
                    // Bending xz-axes
                    EditorGUILayout.BeginHorizontal();
                    //EditorGUILayout.PropertyField(maxBendingValueX, new GUIContent("Along XZ-axis") );
                    GUILayout.Label("Along XZ-Axes", GUILayout.Width(112));
                    GUILayout.Space(10);
                    EditorGUILayout.PropertyField(maxBendingValueX, GUIContent.none);
                    curvX.animationCurveValue = EditorGUILayout.CurveField("", curvX.animationCurveValue, Color.green, new Rect(0, 0, 1, 1), GUILayout.Width(40));
                    EditorGUILayout.EndHorizontal();

                    // Mask secondary Bending
                    if (script.BendingModeSelected == BendingModes.VertexColorsAndUV4)
                    {
                        GUILayout.Space(5);
                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("Mask secondary Bending", myLabel);
                        EditorGUILayout.EndHorizontal();
                        GUILayout.Space(2);
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.PropertyField(Mask2ndBendingSelected, GUIContent.none, GUILayout.Width(112));
                        GUILayout.Label("");
                        if (Mask2ndBendingSelected.enumValueIndex == 0)
                        {
                            curvZ.animationCurveValue = EditorGUILayout.CurveField("", curvZ.animationCurveValue, Color.red, new Rect(0, 0, 1, 1), GUILayout.Width(40));
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    // Draw Gizmos
                    GUILayout.Space(5);
                    EditorGUILayout.BeginHorizontal();
                    script.showGizmos = EditorGUILayout.Toggle("", script.showGizmos, GUILayout.Width(14));
                    GUILayout.Label("Show Gizmos", myLabel);
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    GUI.enabled = false;
                    script.VertexBlueValsStored = EditorGUILayout.Toggle("", script.VertexBlueValsStored, GUILayout.Width(14));
                    GUILayout.Label("Vertex Color Blue Values stored");
                    GUI.enabled = true;
                    EditorGUILayout.EndHorizontal();

                    GUILayout.Space(10);
                    EditorGUILayout.BeginHorizontal();
                    if (!EditorApplication.isPlaying)
                    {
                        if (GUILayout.Button("Apply"))
                        {
                            script.hasChanged = true;
                            script.AdjustBending();
                        }
                        if (GUILayout.Button("Test", GUILayout.Width(94)))
                        {
                            EditorApplication.isPlaying = true;
                        }
                    }
                    else
                    {
                        GUI.enabled = false;
                        GUILayout.Button("Apply");
                        GUI.enabled = true;
                        if (GUILayout.Button("Stop", GUILayout.Width(94)))
                        {
                            EditorApplication.isPlaying = false;
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                    GUILayout.Space(2);
                    EditorGUILayout.EndVertical();
                }

                GUILayout.Space(5);

                //	Adjust Vertex Colors
                GUI.backgroundColor = myBgCol;
                EditorGUILayout.BeginVertical("Box");
                GUI.color = Color.white;
                // Foldout incl. Icon
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(-2);
                EditorGUI.indentLevel++;
                EditorGUILayout.BeginVertical();
                // Only icon gets rendered
                script.adjustVertexColors = EditorGUILayout.Foldout(script.adjustVertexColors, "Adjust Vertex Colors", myFoldoutStyle);
                EditorGUILayout.EndVertical();
                EditorGUI.indentLevel--;
                EditorGUILayout.BeginVertical(GUILayout.Width(20));
                GUILayout.Space(3);
                // Label needs width!
                EditorGUILayout.LabelField(new GUIContent(icnVertexColors), GUILayout.Width(20), GUILayout.Height(20));
                EditorGUILayout.EndVertical();
                EditorGUILayout.EndHorizontal();
                GUILayout.Space(-2);
                GUI.backgroundColor = Color.white;
                EditorGUILayout.EndVertical();
                // FoldoutContent
                if (script.adjustVertexColors)
                {
                    //
                    script.adjustBending = false;
                    //
                    GUILayout.Space(-5);
                    EditorGUILayout.BeginVertical("Box");
                    DrawSplitter1(EditorGUILayout.GetControlRect(false, 4), SplitterCol1);
                    EditorGUILayout.BeginHorizontal();
                    Rect h3rect = EditorGUILayout.GetControlRect(false, 20);
                    h3rect.x     += h3rect.width - 40;
                    hVertexColors = EditorGUI.Foldout(h3rect, hVertexColors, "Help", helpFoldoutStyle);
                    EditorGUILayout.EndHorizontal();
                    if (hVertexColors)
                    {
                        EditorGUILayout.HelpBox("This option let's you change the vertex colors applied to the original mesh in order to adjust the overall bending. " +
                                                "All changes are done only relatively to the original values.", MessageType.None, true);
                    }
                    EditorGUILayout.PropertyField(adjustBlueValue, new GUIContent("Main Bending (Blue/%)"));
                    EditorGUILayout.PropertyField(adjustGreenValue, new GUIContent("Edge Flutter (Green/%)"));
                    EditorGUILayout.PropertyField(adjustRedValue, new GUIContent("Phase (Red/%)"));
                    EditorGUILayout.PropertyField(adjustAlphaValue, new GUIContent("AO (Alpha/%)"));

                    GUILayout.Space(5);
                    EditorGUILayout.BeginHorizontal();
                    if (!EditorApplication.isPlaying)
                    {
                        if (GUILayout.Button("Apply"))
                        {
                            script.hasChanged = true;
                            script.AdjustVertexColors();
                        }
                        if (GUILayout.Button("Test", GUILayout.Width(94)))
                        {
                            EditorApplication.isPlaying = true;
                        }
                    }
                    else
                    {
                        GUI.enabled = false;
                        GUILayout.Button("Apply");
                        GUI.enabled = true;
                        if (GUILayout.Button("Stop", GUILayout.Width(94)))
                        {
                            EditorApplication.isPlaying = false;
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                    GUILayout.Space(2);
                    EditorGUILayout.EndVertical();
                }
            }
        }

        //	Save Btn
        if (showSaveBtn == true && !script.simpleTreeConverted && !script.foliageTreeUV4Converted)
        {
            if (script.hasChanged)
            {
                GUI.backgroundColor = Color.red;
            }

            GUILayout.Space(5);
            if (!EditorApplication.isPlaying)
            {
                if (GUILayout.Button("Save Mesh", GUILayout.Height(34)))
                {
                    //script.hasChanged = false;
                    script.SaveNewPlantMesh();
                }
            }
            else
            {
                GUI.enabled = false;
                GUILayout.Button("Save Mesh", GUILayout.Height(34));
                GUI.enabled = true;
            }
            GUI.backgroundColor = Color.white;
            GUILayout.Space(3);
        }
        EditorGUILayout.EndVertical();
        if (GUI.changed)
        {
            EditorUtility.SetDirty(script);
        }
        AfsFoliageTool.ApplyModifiedProperties();
    }
コード例 #2
0
    public override void OnInspectorGUI()
    {
        AfsFoliageTool script = (AfsFoliageTool)target;
        Color          myBlue = new Color(0.5f, 0.7f, 1.0f, 1.0f);
        Color          myCol  = Color.green;

        //EditorGUILayout.BeginVertical("Box");
        EditorGUILayout.BeginVertical();
        GUILayout.Space(10);
        GUI.color = myCol;
        GUILayout.Label("Rework your plants and save them as new mesh", "BoldLabel");
        GUI.color = Color.white;

        //script.adjustScale = EditorGUILayout.Toggle("Adjust Scale", script.adjustScale);
        //GUI.color = myBlue;
        //hScale = EditorGUILayout.Foldout(hScale," Help");
        //GUI.color = Color.white;
        //if(hScale){
        //	EditorGUILayout.HelpBox("Smaller plants should react differently to touch bending than larger ones. " +
        //	"But the shader does not know about the size of each model." +
        //	"So baking the model's size into the mesh will give all needed information to the shader to handle each model differently." +
        //	"\n1 = small plant leading to less bending amplitudes whereas 3 = big plant on which the full bending will be applied.", MessageType.None, true);
        //}
        //if (script.adjustScale) {
        //	script.Scale = EditorGUILayout.IntSlider("Size", (int) script.Scale, 1, 3);
        //}

        //GUILayout.Space(5);
        //GUILayout.Label (script.oldFileName,"BoldLabel");


        if (!script.hasBeenSaved)
        {
            GUILayout.Space(10);
            EditorGUILayout.HelpBox("You have to safe a new mesh before you can start reworking it. ", MessageType.Warning, true);
        }



        else
        {
/////////

            script.checkSubmeshes();
            if (script.hasSubmeshes)
            {
                GUILayout.Space(10);
                EditorGUILayout.HelpBox("The assigned Mesh has more than one Submesh.\n" +
                                        "You should start by merging the submeshes first.\nSo check 'Merge Submeshes', then hit 'Save Mesh'.", MessageType.Warning, true);


                EditorGUILayout.BeginHorizontal();
                script.mergeSubMeshes = EditorGUILayout.Toggle("", script.mergeSubMeshes, GUILayout.Width(14));
                GUI.color             = myCol;
                GUILayout.Label("Merge Submeshes");
                GUI.color = Color.white;

                if (!script.has2ndUV)
                {
                    GUI.enabled = false;
                }
                script.delete2ndUV = EditorGUILayout.Toggle("", script.delete2ndUV, GUILayout.Width(14));
                GUILayout.Label("Delete 2nd UV Set");
                if (!script.has2ndUV)
                {
                    GUI.enabled = true;
                }
                EditorGUILayout.EndHorizontal();
                script.showTextureCombine = true;
            }

            if (!script.mergeSubMeshes)
            {
                GUILayout.Space(10);

                EditorGUILayout.BeginHorizontal();
                script.adjustBending = EditorGUILayout.Toggle("", script.adjustBending, GUILayout.Width(14));
                GUI.color            = myCol;
                GUILayout.Label("Set Bending");
                GUI.color = Color.white;
                EditorGUILayout.EndHorizontal();

                GUI.color   = myBlue;
                hSetBending = EditorGUILayout.Foldout(hSetBending, " Help");
                GUI.color   = Color.white;
                if (hSetBending)
                {
                    EditorGUILayout.HelpBox("Set up vertex colors for primary and secondary bending from scratch. " +
                                            "Using this function will overwrite all vertex color blue values originally baked into the mesh.", MessageType.None, true);
                }

                if (script.adjustBending)
                {
                    GUILayout.Space(5);
                    script.adjustVertexColors = false;

                    EditorGUILayout.BeginHorizontal();
                    script.maxBendingValueY = EditorGUILayout.Slider("Along Y-axis", script.maxBendingValueY, 0.0f, 1.0f);
                    if (script.curvY.length < 2)
                    {
                        script.curvY.AddKey(0.0f, 0.0f);
                        script.curvY.AddKey(1.0f, 1.0f);
                    }
                    script.curvY = EditorGUILayout.CurveField("", script.curvY, GUILayout.Width(40));
                    EditorGUILayout.EndHorizontal();



                    EditorGUILayout.BeginHorizontal();
                    script.maxBendingValueX = EditorGUILayout.Slider("Along XZ-axis", script.maxBendingValueX, 0.0f, 1.0f);
                    if (script.curvX.length < 2)
                    {
                        script.curvX.AddKey(0.0f, 0.0f);
                        script.curvX.AddKey(1.0f, 1.0f);
                    }
                    script.curvX = EditorGUILayout.CurveField("", script.curvX, GUILayout.Width(40));
                    EditorGUILayout.EndHorizontal();
                    //curveZ = EditorGUILayout.CurveField("Animation on Z", curveZ);



                    /*
                     * EditorGUILayout.BeginHorizontal();
                     *      GUILayout.Label ("Along X and Z axis", GUILayout.MinWidth(144));
                     *      EditorGUILayout.BeginVertical();
                     *              script.maxBendingValueX = EditorGUILayout.Slider("", script.maxBendingValueX, 0.0f, 1.0f);
                     *              script.curvX = EditorGUILayout.CurveField("", script.curvX);
                     *      EditorGUILayout.EndVertical();
                     * EditorGUILayout.EndHorizontal();
                     */

                    GUILayout.Space(5);
                    EditorGUILayout.BeginHorizontal();

                    if (!EditorApplication.isPlaying)
                    {
                        if (GUILayout.Button("Apply"))
                        {
                            script.AdjustBending();
                        }
                        if (GUILayout.Button("Test", GUILayout.Width(94)))
                        {
                            EditorApplication.isPlaying = true;
                        }
                    }
                    else
                    {
                        GUI.enabled = false;
                        GUILayout.Button("Apply");
                        GUI.enabled = true;
                        if (GUILayout.Button("Stop", GUILayout.Width(94)))
                        {
                            EditorApplication.isPlaying = false;
                        }
                    }

                    EditorGUILayout.EndHorizontal();
                }
                GUILayout.Space(10);

                ////////////

                EditorGUILayout.BeginHorizontal();
                script.adjustVertexColors = EditorGUILayout.Toggle("", script.adjustVertexColors, GUILayout.Width(14));
                GUI.color = myCol;
                GUILayout.Label("Adjust Vertex Colors");
                GUI.color = Color.white;
                EditorGUILayout.EndHorizontal();

                GUI.color     = myBlue;
                hVertexColors = EditorGUILayout.Foldout(hVertexColors, " Help");
                GUI.color     = Color.white;
                if (hVertexColors)
                {
                    EditorGUILayout.HelpBox("This option let's you change the vertex colors applied to the original mesh in order to adjust the overall bending. " +
                                            "All changes are done only relatively to the original values.", MessageType.None, true);
                }
                if (script.adjustVertexColors)
                {
                    GUILayout.Space(5);

                    script.adjustBending = false;

                    script.adjustBlueValue  = EditorGUILayout.Slider("Main Bending (Blue/%)", script.adjustBlueValue, -95.0f, 95.0f);
                    script.adjustGreenValue = EditorGUILayout.Slider("Edge Flutter (Green/%)", script.adjustGreenValue, -95.0f, 95.0f);
                    script.adjustRedValue   = EditorGUILayout.Slider("Phase (Red/%)", script.adjustRedValue, -95.0f, 95.0f);

                    //GUILayout.Space(5);
                    //script.RedcurvY = EditorGUI.CurveField(new Rect(0,0,10,10),"sasasas", script.RedcurvY );
                    //GUILayout.Space(5);

                    script.adjustAlphaValue = EditorGUILayout.Slider("AO (Alpha/%)", script.adjustAlphaValue, -95.0f, 95.0f);

                    GUILayout.Space(5);
                    EditorGUILayout.BeginHorizontal();

                    if (!EditorApplication.isPlaying)
                    {
                        if (GUILayout.Button("Apply"))
                        {
                            script.AdjustVertexColors();
                        }
                        if (GUILayout.Button("Test", GUILayout.Width(94)))
                        {
                            EditorApplication.isPlaying = true;
                        }
                    }
                    else
                    {
                        GUI.enabled = false;
                        GUILayout.Button("Apply");
                        GUI.enabled = true;
                        if (GUILayout.Button("Stop", GUILayout.Width(94)))
                        {
                            EditorApplication.isPlaying = false;
                        }
                    }

                    EditorGUILayout.EndHorizontal();
                }
            }



/////
        }

        GUILayout.Space(10);
        if (!EditorApplication.isPlaying)
        {
            if (GUILayout.Button("Save Mesh", GUILayout.Height(34)))
            {
                script.SaveNewPlantMesh();
            }
        }
        else
        {
            GUI.enabled = false;
            GUILayout.Button("Save Mesh", GUILayout.Height(34));
            GUI.enabled = true;
        }

/////
        GUI.color = myCol;
        GUILayout.Space(10);
        script.showTextureCombine = EditorGUILayout.Foldout(script.showTextureCombine, " Merge Tree Creator Textures");
        GUI.color = Color.white;
        if (script.showTextureCombine || script.hasSubmeshes)
        {
            //
            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.BeginVertical();
            GUILayout.Label("normal_specular");
            script.sourceTex0 = (Texture2D)EditorGUILayout.ObjectField(script.sourceTex0, typeof(Texture2D), false, GUILayout.MinHeight(64), GUILayout.MinWidth(64), GUILayout.MaxWidth(64));
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical();
            GUILayout.Label("translucency_gloss");
            script.sourceTex1 = (Texture2D)EditorGUILayout.ObjectField(script.sourceTex1, typeof(Texture2D), false, GUILayout.MinHeight(64), GUILayout.MinWidth(64), GUILayout.MaxWidth(64));
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();
            GUILayout.Space(4);
            //
            EditorGUILayout.BeginVertical();
            EditorGUILayout.BeginHorizontal();
            toolTip = "If your Texture are split into halfs (left half: bark / right half: leafs) check this and the script will automatically fill the left half of the translucency map with black. Otherwise you will have to edit the generated texture manually.";
            EditorGUILayout.LabelField(new GUIContent("Texture Split", toolTip), GUILayout.Width(80));
            script.TextureSplitSelected = (TextureSplit)EditorGUILayout.EnumPopup(script.TextureSplitSelected);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();
            GUILayout.Space(4);
            if (GUILayout.Button("Save Combined Texture", GUILayout.Height(34)))
            {
                mergeTexture();
            }
        }



        EditorGUILayout.EndVertical();

        EditorUtility.SetDirty(script);
    }