mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 09:16:01 +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);
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
@ -23,6 +23,16 @@ namespace XNodeEditor {
|
||||
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)]
|
||||
public class CustomNodeGraphEditorAttribute : Attribute,
|
||||
INodeEditorAttrib {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user