diff --git a/Scripts/Editor/NodeGraphEditor.cs b/Scripts/Editor/NodeGraphEditor.cs
index 6089d29..f8e1eda 100644
--- a/Scripts/Editor/NodeGraphEditor.cs
+++ b/Scripts/Editor/NodeGraphEditor.cs
@@ -41,11 +41,22 @@ namespace XNodeEditor {
return NodeEditorUtilities.NodeDefaultPath(type);
}
+ /// The order by which the menu items are displayed.
+ public virtual int GetNodeMenuOrder(Type type) {
+ //Check if type has the CreateNodeMenuAttribute
+ XNode.Node.CreateNodeMenuAttribute attrib;
+ if (NodeEditorUtilities.GetAttrib(type, out attrib)) // Return custom path
+ return attrib.order;
+ else
+ return 0;
+ }
+
/// Add items for the context menu when right-clicking this node. Override to add custom menu items.
public virtual void AddContextMenuItems(GenericMenu menu) {
Vector2 pos = NodeEditorWindow.current.WindowToGridPosition(Event.current.mousePosition);
- for (int i = 0; i < NodeEditorReflection.nodeTypes.Length; i++) {
- Type type = NodeEditorReflection.nodeTypes[i];
+ var nodeTypes = NodeEditorReflection.nodeTypes.OrderBy(type => GetNodeMenuOrder(type)).ToArray();
+ for (int i = 0; i < nodeTypes.Length; i++) {
+ Type type = nodeTypes[i];
//Get node context menu path
string path = GetNodeMenuName(type);
diff --git a/Scripts/Node.cs b/Scripts/Node.cs
index beb5f77..9d2721b 100644
--- a/Scripts/Node.cs
+++ b/Scripts/Node.cs
@@ -317,10 +317,20 @@ namespace XNode {
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class CreateNodeMenuAttribute : Attribute {
public string menuName;
+ public int order;
/// Manually supply node class with a context menu path
/// Path to this node in the context menu. Null or empty hides it.
public CreateNodeMenuAttribute(string menuName) {
this.menuName = menuName;
+ this.order = 0;
+ }
+
+ /// Manually supply node class with a context menu path
+ /// Path to this node in the context menu. Null or empty hides it.
+ /// The order by which the menu items are displayed.
+ public CreateNodeMenuAttribute(string menuName, int order) {
+ this.menuName = menuName;
+ this.order = order;
}
}