Seneral / Node_Editor_Framework

A flexible and modular Node Editor Framework for creating node based displays and editors in Unity
https://nodeeditor.seneral.dev
MIT License
2.01k stars 414 forks source link

Simple node header coloring #110

Closed No3371 closed 7 years ago

No3371 commented 7 years ago

I remember that there is going to be a node customization feature, but it seems not yet there. So I add a tiny extension to color the headers for better recognizing for large canvas as a temporary solution, maybe you'd like to check it out.

default

using UnityEngine;
using DialogNodeEditor; // user's namespace

namespace NodeEditorFramework{

    public class NodesColoringExt{

        static Color defaultColor;

        public static void ColorOn(System.Type t){
            defaultColor = GUI.backgroundColor;

                        //user's node type
            if (t.IsSubclassOf(typeof(BaseVariableNode))){
                GUI.backgroundColor = new Color(0.1f, 0.1f, 0.9f);
            }
            else if (t.IsSubclassOf(typeof(BaseConvControlNode))){
                GUI.backgroundColor = new Color(0.9f, 0.1f, 0.1f);
            }
            else if (t.IsSubclassOf(typeof(BaseSystemControlNode))){
                GUI.backgroundColor = new Color(0.1f, 0.6f, 0.1f);
            }
            else if (t.IsSubclassOf(typeof(BaseActionNode))){
                GUI.backgroundColor = new Color(0.8f, 0.8f, 0.3f);
            }
            else{
                GUI.backgroundColor = new Color(0.4f, 0.4f, 0.4f);
            }
        }

        public static void ColorOff(){
            GUI.backgroundColor = defaultColor;
        }

    }
}

And insert these two line in Node.DrawNode();

**NodesColoringExt.ColorOn(this.GetType());**

// Create a headerRect out of the previous rect and draw it, marking the selected node as such by making the header bold
Rect headerRect = new Rect (nodeRect.x, nodeRect.y, nodeRect.width, contentOffset.y);
GUI.Label (headerRect, name, NodeEditor.curEditorState.selectedNode == this? NodeEditorGUI.nodeBoxBold : NodeEditorGUI.nodeBox);

**NodesColoringExt.ColorOff();**
Seneral commented 7 years ago

Already got something like this implemented recently in #106. It colors the full node, but you could easily adjust that. Then you just need to specify a color for each node and your good to go:)

Seneral commented 7 years ago

Btw, that Node Customization Feature you mentioned, don't think that was anything specific, or what did you expect of that? You can already customise nodes completely by overriding DrawNode in Node, but general stuff like coloring is added when needed. If your missing anything else, don't hesitate to ask:)