mirror of
https://github.com/Siccity/xNode.git
synced 2026-03-26 22:49:02 +08:00
Moved things around
Moved CreateNode from NodeEditorWindow to NodeGraphEditor Replaced NodeEditorWindow.ShowGraphContextMenu with NodeGraphEditor.AddContextMenuItems
This commit is contained in:
parent
a2cb736811
commit
73912b1448
@ -264,7 +264,9 @@ namespace XNodeEditor {
|
||||
NodeEditor.GetEditor(hoveredNode).AddContextMenuItems(menu);
|
||||
menu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
|
||||
} else if (!IsHoveringNode) {
|
||||
ShowGraphContextMenu();
|
||||
GenericMenu menu = new GenericMenu();
|
||||
graphEditor.AddContextMenuItems(menu);
|
||||
menu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
|
||||
}
|
||||
}
|
||||
isPanning = false;
|
||||
@ -325,15 +327,6 @@ namespace XNodeEditor {
|
||||
panOffset = Vector2.zero;
|
||||
}
|
||||
|
||||
public void CreateNode(Type type, Vector2 position) {
|
||||
XNode.Node node = graph.AddNode(type);
|
||||
node.position = position;
|
||||
node.name = UnityEditor.ObjectNames.NicifyVariableName(type.Name);
|
||||
AssetDatabase.AddObjectToAsset(node, graph);
|
||||
if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
|
||||
Repaint();
|
||||
}
|
||||
|
||||
/// <summary> Remove nodes in the graph in Selection.objects</summary>
|
||||
public void RemoveSelectedNodes() {
|
||||
// We need to delete reroutes starting at the highest point index to avoid shifting indices
|
||||
|
||||
@ -116,27 +116,6 @@ namespace XNodeEditor {
|
||||
if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
|
||||
}
|
||||
|
||||
/// <summary> Show right-click context menu for current graph </summary>
|
||||
void ShowGraphContextMenu() {
|
||||
GenericMenu contextMenu = new GenericMenu();
|
||||
Vector2 pos = WindowToGridPosition(Event.current.mousePosition);
|
||||
for (int i = 0; i < nodeTypes.Length; i++) {
|
||||
Type type = nodeTypes[i];
|
||||
|
||||
//Get node context menu path
|
||||
string path = graphEditor.GetNodeMenuName(type);
|
||||
if (string.IsNullOrEmpty(path)) continue;
|
||||
|
||||
contextMenu.AddItem(new GUIContent(path), false, () => {
|
||||
CreateNode(type, pos);
|
||||
});
|
||||
}
|
||||
contextMenu.AddSeparator("");
|
||||
contextMenu.AddItem(new GUIContent("Preferences"), false, () => OpenPreferences());
|
||||
AddCustomContextMenuItems(contextMenu, graph);
|
||||
contextMenu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
|
||||
}
|
||||
|
||||
/// <summary> Draw a bezier from startpoint to endpoint, both in grid coordinates </summary>
|
||||
public void DrawConnection(Vector2 startPoint, Vector2 endPoint, Color col) {
|
||||
startPoint = GridToWindowPosition(startPoint);
|
||||
|
||||
@ -38,10 +38,39 @@ namespace XNodeEditor {
|
||||
return ObjectNames.NicifyVariableName(type.ToString().Replace('.', '/'));
|
||||
}
|
||||
|
||||
/// <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) {
|
||||
Vector2 pos = NodeEditorWindow.current.WindowToGridPosition(Event.current.mousePosition);
|
||||
for (int i = 0; i < NodeEditorWindow.nodeTypes.Length; i++) {
|
||||
Type type = NodeEditorWindow.nodeTypes[i];
|
||||
|
||||
//Get node context menu path
|
||||
string path = GetNodeMenuName(type);
|
||||
if (string.IsNullOrEmpty(path)) continue;
|
||||
|
||||
menu.AddItem(new GUIContent(path), false, () => {
|
||||
CreateNode(type, pos);
|
||||
});
|
||||
}
|
||||
menu.AddSeparator("");
|
||||
menu.AddItem(new GUIContent("Preferences"), false, () => NodeEditorWindow.OpenPreferences());
|
||||
NodeEditorWindow.AddCustomContextMenuItems(menu, target);
|
||||
}
|
||||
|
||||
public virtual Color GetTypeColor(Type type) {
|
||||
return NodeEditorPreferences.GetTypeColor(type);
|
||||
}
|
||||
|
||||
/// <summary> Create a node and save it in the graph asset </summary>
|
||||
public virtual void CreateNode(Type type, Vector2 position) {
|
||||
XNode.Node node = target.AddNode(type);
|
||||
node.position = position;
|
||||
node.name = UnityEditor.ObjectNames.NicifyVariableName(type.Name);
|
||||
AssetDatabase.AddObjectToAsset(node, target);
|
||||
if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
|
||||
NodeEditorWindow.RepaintAll();
|
||||
}
|
||||
|
||||
/// <summary> Creates a copy of the original node in the graph </summary>
|
||||
public XNode.Node CopyNode(XNode.Node original) {
|
||||
XNode.Node node = target.CopyNode(original);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user