mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-21 01:36:03 +08:00
Implemented OrderBy in Add Node Menu (#247)
This commit is contained in:
parent
77d7802b7e
commit
a61bb3f87e
@ -41,11 +41,22 @@ namespace XNodeEditor {
|
|||||||
return NodeEditorUtilities.NodeDefaultPath(type);
|
return NodeEditorUtilities.NodeDefaultPath(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary> The order by which the menu items are displayed. </summary>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary> Add items for the context menu when right-clicking this node. Override to add custom menu items. </summary>
|
/// <summary> Add items for the context menu when right-clicking this node. Override to add custom menu items. </summary>
|
||||||
public virtual void AddContextMenuItems(GenericMenu menu) {
|
public virtual void AddContextMenuItems(GenericMenu menu) {
|
||||||
Vector2 pos = NodeEditorWindow.current.WindowToGridPosition(Event.current.mousePosition);
|
Vector2 pos = NodeEditorWindow.current.WindowToGridPosition(Event.current.mousePosition);
|
||||||
for (int i = 0; i < NodeEditorReflection.nodeTypes.Length; i++) {
|
var nodeTypes = NodeEditorReflection.nodeTypes.OrderBy(type => GetNodeMenuOrder(type)).ToArray();
|
||||||
Type type = NodeEditorReflection.nodeTypes[i];
|
for (int i = 0; i < nodeTypes.Length; i++) {
|
||||||
|
Type type = nodeTypes[i];
|
||||||
|
|
||||||
//Get node context menu path
|
//Get node context menu path
|
||||||
string path = GetNodeMenuName(type);
|
string path = GetNodeMenuName(type);
|
||||||
|
|||||||
@ -317,10 +317,20 @@ namespace XNode {
|
|||||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
|
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
|
||||||
public class CreateNodeMenuAttribute : Attribute {
|
public class CreateNodeMenuAttribute : Attribute {
|
||||||
public string menuName;
|
public string menuName;
|
||||||
|
public int order;
|
||||||
/// <summary> Manually supply node class with a context menu path </summary>
|
/// <summary> Manually supply node class with a context menu path </summary>
|
||||||
/// <param name="menuName"> Path to this node in the context menu. Null or empty hides it. </param>
|
/// <param name="menuName"> Path to this node in the context menu. Null or empty hides it. </param>
|
||||||
public CreateNodeMenuAttribute(string menuName) {
|
public CreateNodeMenuAttribute(string menuName) {
|
||||||
this.menuName = menuName;
|
this.menuName = menuName;
|
||||||
|
this.order = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Manually supply node class with a context menu path </summary>
|
||||||
|
/// <param name="menuName"> Path to this node in the context menu. Null or empty hides it. </param>
|
||||||
|
/// <param name="order"> The order by which the menu items are displayed. </param>
|
||||||
|
public CreateNodeMenuAttribute(string menuName, int order) {
|
||||||
|
this.menuName = menuName;
|
||||||
|
this.order = order;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user