mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 17:26:02 +08:00
Added NodeGraphEditor.GetNodePath
You now have more control over which nodes get displayed in the context menu, and how they are displayed
This commit is contained in:
parent
869bd6a76d
commit
9e68617cb8
@ -103,12 +103,12 @@ namespace XNodeEditor {
|
|||||||
Vector2 pos = WindowToGridPosition(Event.current.mousePosition);
|
Vector2 pos = WindowToGridPosition(Event.current.mousePosition);
|
||||||
for (int i = 0; i < nodeTypes.Length; i++) {
|
for (int i = 0; i < nodeTypes.Length; i++) {
|
||||||
Type type = nodeTypes[i];
|
Type type = nodeTypes[i];
|
||||||
string name = nodeTypes[i].ToString().Replace('.', '/');
|
|
||||||
Node.CreateNodeMenuAttribute attrib;
|
//Get node context menu path
|
||||||
if (NodeEditorUtilities.GetAttrib(type, out attrib)) {
|
string path = currentGraphEditor.GetNodePath(type);
|
||||||
name = attrib.menuName;
|
if (path == null) continue;
|
||||||
}
|
|
||||||
contextMenu.AddItem(new GUIContent(name), false, () => {
|
contextMenu.AddItem(new GUIContent(path), false, () => {
|
||||||
CreateNode(type, pos);
|
CreateNode(type, pos);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,6 +23,16 @@ namespace XNodeEditor {
|
|||||||
return NodeEditorPreferences.crossTexture;
|
return NodeEditorPreferences.crossTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary> Returns context menu path. Returns null if node is not available. </summary>
|
||||||
|
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)]
|
[AttributeUsage(AttributeTargets.Class)]
|
||||||
public class CustomNodeGraphEditorAttribute : Attribute,
|
public class CustomNodeGraphEditorAttribute : Attribute,
|
||||||
INodeEditorAttrib {
|
INodeEditorAttrib {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user