public override void OnInspectorGUI()
        {
            EditorGUIUtility.labelWidth = 135;
            int   functionCount        = template.treeFunctions.Count;
            int   rectHeightMultiplier = TreeFunctionAsset.height + TreeFunctionAsset.margin;
            int   rectHeight           = functionCount * rectHeightMultiplier; // get the height of the drawing window inside inspector
            Event e = Event.current;                                           // Get current event

            int heighIndex = 0;

            template.treeFunctions[0].UpdateRectRec(ref heighIndex, 0);

            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            EditorGUILayout.LabelField("Tree functions", EditorStyles.boldLabel);

            Rect rect = GUILayoutUtility.GetRect(10, 1000, rectHeight, rectHeight); // Create drawing window

            GUI.BeginClip(rect);

            for (int i = 0; i < template.treeFunctions.Count; i++)
            {
                template.treeFunctions[i].DrawFunction(i == selectedFuntionIndex, false);
            }

            GUI.EndClip();
            EditorGUILayout.EndVertical();

            if (e.type == EventType.MouseDown && e.button == 0) // If mouse button is pressed, get button pressed and act accordingly
            {
                for (int i = 0; i < functionCount; i++)
                {
                    TreeFunctionAsset tf = template.treeFunctions[i];

                    if (tf.rect.Contains(e.mousePosition - rect.position))
                    {
                        selectedFuntionIndex = i;
                        GUIUtility.ExitGUI();
                        break;
                    }
                }
            }

            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            TreeFunctionAsset selectedFunction = template.treeFunctions[selectedFuntionIndex];

            selectedFunction.DrawProperties();
            EditorGUILayout.EndVertical();
        }
Beispiel #2
0
        private void DisplayFunctionsTab()
        {
            EditorGUIUtility.labelWidth = 135;
            int functionCount = tree.treeFunctionsAssets.Count; // Used in multiple for loops

            EditorGUI.BeginDisabledGroup(tree.treeFunctionsAssets[tree.selectedFunctionIndex].name == "Leaves");
            if (GUILayout.Button("Add function"))
            {
                GenericMenu addFunctionMenu = new GenericMenu();
                addFunctionMenu.AddItem(new GUIContent("Add branch"), false, tree.AddBranchFunction);
                addFunctionMenu.AddItem(new GUIContent("Add Leafs"), false, tree.AddLeafFunction);
                addFunctionMenu.AddItem(new GUIContent("Split"), false, tree.AddSplitFunction);
                addFunctionMenu.AddItem(new GUIContent("Grow"), false, tree.AddGrowFunction);
                addFunctionMenu.ShowAsContext();
            }
            EditorGUI.EndDisabledGroup();

            int   rectHeight = functionCount * rectHeightMultiplier;                       // get the height of the drawing window inside inspector
            Rect  rect       = GUILayoutUtility.GetRect(10, 1000, rectHeight, rectHeight); // Create drawing window
            Event e          = Event.current;                                              // Get current event

            int heighIndex = 0;

            tree.treeFunctionsAssets[0].UpdateRectRec(ref heighIndex, 0);

            if (e.type == EventType.MouseDown && e.button == 0) // If mouse button is pressed, get button pressed and act accordingly
            {
                for (int i = 0; i < functionCount; i++)
                {
                    TreeFunctionAsset tf = tree.treeFunctionsAssets[i];


                    if (tf.rect.Contains(e.mousePosition - rect.position))
                    {
                        if (tf.deleteRect.Contains(e.mousePosition - rect.position))
                        {
                            tree.RemoveFunction(tf);
                            UpdateTree();
                        }
                        else
                        {
                            serializedObject.FindProperty("selectedFunctionIndex").intValue = i;
                            serializedObject.ApplyModifiedProperties();
                        }
                        GUIUtility.ExitGUI();
                        break;
                    }
                }
            }
            if (e.type == EventType.MouseDown && e.button == 1)
            {
                for (int i = 0; i < functionCount; i++)
                {
                    TreeFunctionAsset tf = tree.treeFunctionsAssets[i];
                    if (tf.rect.Contains(e.mousePosition - rect.position))
                    {
                        var menu = new GenericMenu();
                        if (!tf.name.Contains("Trunk"))
                        {
                            menu.AddItem(new GUIContent("Copy Tree Function"), false, SaveTF);
                        }
                        else
                        {
                            menu.AddDisabledItem(new GUIContent("Copy Tree Function"));
                        }


                        if (tree.savedFunction != null && tree.treeFunctionsAssets[tree.selectedFunctionIndex].name != "Leaves")
                        {
                            menu.AddItem(new GUIContent("Paste Tree Function"), false, InsertTF);
                        }
                        else
                        {
                            menu.AddDisabledItem(new GUIContent("Paste Tree Function"));
                        }

                        menu.ShowAsContext();
                        e.Use();
                    }
                }
            }
            GUI.BeginClip(rect);

            for (int i = 0; i < tree.treeFunctionsAssets.Count; i++)
            {
                tree.treeFunctionsAssets[i].DrawFunction(i == tree.selectedFunctionIndex, i > 0);
            }

            GUI.EndClip();

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.BeginVertical(EditorStyles.helpBox);

            if (GUILayout.Button("Randomize tree"))
            {
                tree.RandomizeTree();
            }

            TreeFunctionAsset selectedFunction = tree.treeFunctionsAssets[tree.selectedFunctionIndex];

            selectedFunction.DrawProperties();

            EditorGUILayout.EndVertical();
            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            var gs = new GUIStyle();

            gs.richText = true;
            EditorGUILayout.LabelField("<b>Vertex Color Adjustment</b> <i>(Baked Wind Settings)</i>", gs);
            EditorGUILayout.Slider(serializedObject.FindProperty("VColBarkModifier"), 0.1f, 5, new GUIContent("Stem Multiplier"));
            EditorGUILayout.Slider(serializedObject.FindProperty("VColLeafModifier"), 0.1f, 5, new GUIContent("Leaf Multiplier"));
            serializedObject.ApplyModifiedProperties();
            EditorGUILayout.EndVertical();
            if (EditorGUI.EndChangeCheck())
            {
                UpdateTree();
            }
            EditorGUILayout.Space();
            BezierMode();
        }