diff --git a/Scripts/Editor/NodeEditorGUI.cs b/Scripts/Editor/NodeEditorGUI.cs index 8fed2f8..97c3afb 100644 --- a/Scripts/Editor/NodeEditorGUI.cs +++ b/Scripts/Editor/NodeEditorGUI.cs @@ -103,12 +103,12 @@ namespace XNodeEditor { Vector2 pos = WindowToGridPosition(Event.current.mousePosition); for (int i = 0; i < nodeTypes.Length; i++) { Type type = nodeTypes[i]; - string name = nodeTypes[i].ToString().Replace('.', '/'); - Node.CreateNodeMenuAttribute attrib; - if (NodeEditorUtilities.GetAttrib(type, out attrib)) { - name = attrib.menuName; - } - contextMenu.AddItem(new GUIContent(name), false, () => { + + //Get node context menu path + string path = currentGraphEditor.GetNodePath(type); + if (path == null) continue; + + contextMenu.AddItem(new GUIContent(path), false, () => { CreateNode(type, pos); }); } diff --git a/Scripts/Editor/NodeGraphEditor.cs b/Scripts/Editor/NodeGraphEditor.cs index 8a4bb03..d791f59 100644 --- a/Scripts/Editor/NodeGraphEditor.cs +++ b/Scripts/Editor/NodeGraphEditor.cs @@ -23,6 +23,16 @@ namespace XNodeEditor { return NodeEditorPreferences.crossTexture; } + /// Returns context menu path. Returns null if node is not available. + public virtual string GetNodePath(Type type) { + //Check if type has the CreateNodeMenuAttribute + Node.CreateNodeMenuAttribute attrib; + if (NodeEditorUtilities.GetAttrib(type, out attrib)) // Return custom path + return attrib.menuName; + else // Return generated path + return ObjectNames.NicifyVariableName(type.ToString().Replace('.', '/')); + } + [AttributeUsage(AttributeTargets.Class)] public class CustomNodeGraphEditorAttribute : Attribute, INodeEditorAttrib {