diff --git a/Scripts/Editor/NodeEditorAction.cs b/Scripts/Editor/NodeEditorAction.cs
index f9ff7ee..ee2dd8d 100644
--- a/Scripts/Editor/NodeEditorAction.cs
+++ b/Scripts/Editor/NodeEditorAction.cs
@@ -31,14 +31,12 @@ public partial class NodeEditorWindow {
Event e = Event.current;
switch (e.type) {
case EventType.MouseMove:
- UpdateHovered();
break;
case EventType.ScrollWheel:
if (e.delta.y > 0) zoom += 0.1f * zoom;
else zoom -= 0.1f * zoom;
break;
case EventType.MouseDrag:
- UpdateHovered();
if (e.button == 0) {
if (IsDraggingPort) {
if (IsHoveringPort && hoveredPort.IsInput) {
@@ -62,7 +60,6 @@ public partial class NodeEditorWindow {
if (e.keyCode == KeyCode.F) Home();
break;
case EventType.MouseDown:
- UpdateHovered();
Repaint();
SelectNode(hoveredNode);
if (IsHoveringPort) {
@@ -103,7 +100,6 @@ public partial class NodeEditorWindow {
if (!isPanning) ShowContextMenu();
isPanning = false;
}
- UpdateHovered();
AssetDatabase.SaveAssets();
break;
}
@@ -133,49 +129,6 @@ public partial class NodeEditorWindow {
}
}
- /// Updates and
- void UpdateHovered() {
- Vector2 mousePos = Event.current.mousePosition;
- Node newHoverNode = null;
- foreach (Node node in graph.nodes) {
- if (node == null) return;
- //Get node position
- Vector2 nodePos = GridToWindowPosition(node.rect.position);
- Rect windowRect = new Rect(nodePos, new Vector2(node.rect.size.x / zoom, node.rect.size.y / zoom));
- if (windowRect.Contains(mousePos)) {
- newHoverNode = node;
- }
- }
- if (newHoverNode != hoveredNode) {
- hoveredNode = newHoverNode;
- Repaint();
- }
- //If we are hovering a node, check if we are also hovering a port
- NodePort newHoverPort = null;
- //Check all input ports
- for (int k = 0; k < graph.nodes.Count; k++) {
-
- for (int i = 0; i < graph.nodes[k].InputCount; i++) {
- NodePort port = graph.nodes[k].inputs[i];
- //Check if port rect is available
- if (!portConnectionPoints.ContainsKey(port)) continue;
- Rect r = GridToWindowRect(portConnectionPoints[port]);
- if (r.Contains(mousePos)) newHoverPort = port;
- }
- //Check all output ports
- for (int i = 0; i < graph.nodes[k].OutputCount; i++) {
- NodePort port = graph.nodes[k].outputs[i];
- //Check if port rect is available
- if (!portConnectionPoints.ContainsKey(port)) continue;
- Rect r = GridToWindowRect(portConnectionPoints[port]);
- if (r.Contains(mousePos)) newHoverPort = port;
- }
- }
- if (newHoverPort != hoveredPort) {
- hoveredPort = newHoverPort;
- }
- }
-
bool IsHoveringTitle(Node node) {
Vector2 mousePos = Event.current.mousePosition;
//Get node position
diff --git a/Scripts/Editor/NodeEditorGUI.cs b/Scripts/Editor/NodeEditorGUI.cs
index 2dac4cb..8e6c3b1 100644
--- a/Scripts/Editor/NodeEditorGUI.cs
+++ b/Scripts/Editor/NodeEditorGUI.cs
@@ -151,6 +151,9 @@ public partial class NodeEditorWindow {
BeginZoomed(position, zoom);
+ Vector2 mousePos = Event.current.mousePosition;
+
+
foreach (Node node in graph.nodes) {
if (node == null) return;
NodeEditor nodeEditor = GetNodeEditor(node.GetType());
@@ -169,7 +172,6 @@ public partial class NodeEditorWindow {
//Draw node contents
Dictionary portHandlePoints;
nodeEditor.OnNodeGUI(out portHandlePoints);
- EditorGUILayout.Space();
if (e.type == EventType.Repaint) {
foreach (var kvp in portHandlePoints) {
@@ -182,7 +184,31 @@ public partial class NodeEditorWindow {
GUILayout.EndVertical();
- //if (e.type == EventType.Repaint) node.rect.size = GUILayoutUtility.GetLastRect().size;
+ //Check if we are hovering this node
+ Vector2 nodeSize = GUILayoutUtility.GetLastRect().size / zoom;
+ Rect windowRect = new Rect(nodePos, nodeSize);
+ if (windowRect.Contains(mousePos)) hoveredNode = node;
+
+ //Check if we are hovering any of this nodes ports
+ //Check input ports
+ for (int i = 0; i < node.InputCount; i++)
+ {
+ NodePort port = node.inputs[i];
+ //Check if port rect is available
+ if (!portConnectionPoints.ContainsKey(port)) continue;
+ Rect r = GridToWindowRect(portConnectionPoints[port]);
+ if (r.Contains(mousePos)) hoveredPort = port;
+ }
+ //Check all output ports
+ for (int i = 0; i < node.OutputCount; i++)
+ {
+ NodePort port = node.outputs[i];
+ //Check if port rect is available
+ if (!portConnectionPoints.ContainsKey(port)) continue;
+ Rect r = GridToWindowRect(portConnectionPoints[port]);
+ if (r.Contains(mousePos)) hoveredPort = port;
+ }
+
GUILayout.EndArea();
}
EndZoomed(position, zoom);
diff --git a/Scripts/Editor/NodeEditorResources.cs b/Scripts/Editor/NodeEditorResources.cs
index 70853e6..cc9320e 100644
--- a/Scripts/Editor/NodeEditorResources.cs
+++ b/Scripts/Editor/NodeEditorResources.cs
@@ -48,13 +48,10 @@ public static class NodeEditorResources {
nodeBody = new GUIStyle();
nodeBody.normal.background = NodeEditorResources.nodeBody;
nodeBody.border = new RectOffset(32, 32, 32, 32);
- nodeBody.padding = new RectOffset(16, 16, 4, 6);
+ nodeBody.padding = new RectOffset(16, 16, 4, 16);
tooltip = new GUIStyle("helpBox");
tooltip.alignment = TextAnchor.MiddleCenter;
- //tooltip.border = new RectOffset(0, 0, 0, 0);
- //tooltip.normal.background
- //tooltip.padding = new RectOffset(0, 0, 0, 0);
}
}