/// <summary> Draws all connections </summary> public void DrawConnections() { foreach (Siccity.XNode.Node node in graph.nodes) { //If a null node is found, return. This can happen if the nodes associated script is deleted. It is currently not possible in Unity to delete a null asset. if (node == null) { continue; } foreach (Siccity.XNode.NodePort output in node.Outputs) { //Needs cleanup. Null checks are ugly if (!portConnectionPoints.ContainsKey(output)) { continue; } Vector2 from = _portConnectionPoints[output].center; for (int k = 0; k < output.ConnectionCount; k++) { Siccity.XNode.NodePort input = output.GetConnection(k); if (input == null) { continue; //If a script has been updated and the port doesn't exist, it is removed and null is returned. If this happens, return. } if (!input.IsConnectedTo(output)) { input.Connect(output); } if (!_portConnectionPoints.ContainsKey(input)) { continue; } Vector2 to = _portConnectionPoints[input].center; Color connectionColor = graphEditor.GetTypeColor(output.ValueType); DrawConnection(from, to, connectionColor); } } } }
/// <summary> Draws all connections </summary> public void DrawConnections() { Vector2 mousePos = Event.current.mousePosition; List <RerouteReference> selection = preBoxSelectionReroute != null ? new List <RerouteReference>(preBoxSelectionReroute) : new List <RerouteReference>(); hoveredReroute = new RerouteReference(); Color col = GUI.color; foreach (XNode.Node node in graph.nodes) { //If a null node is found, return. This can happen if the nodes associated script is deleted. It is currently not possible in Unity to delete a null asset. if (node == null) { continue; } // Draw full connections and output > reroute foreach (XNode.NodePort output in node.Outputs) { //Needs cleanup. Null checks are ugly Rect fromRect; if (!_portConnectionPoints.TryGetValue(output, out fromRect)) { continue; } Color connectionColor = graphEditor.GetTypeColor(output.ValueType); for (int k = 0; k < output.ConnectionCount; k++) { XNode.NodePort input = output.GetConnection(k); // Error handling if (input == null) { continue; //If a script has been updated and the port doesn't exist, it is removed and null is returned. If this happens, return. } if (!input.IsConnectedTo(output)) { input.Connect(output); } Rect toRect; if (!_portConnectionPoints.TryGetValue(input, out toRect)) { continue; } Vector2 from = fromRect.center; Vector2 to = Vector2.zero; List <Vector2> reroutePoints = output.GetReroutePoints(k); // Loop through reroute points and draw the path for (int i = 0; i < reroutePoints.Count; i++) { to = reroutePoints[i]; DrawConnection(from, to, connectionColor); from = to; } to = toRect.center; DrawConnection(from, to, connectionColor); // Loop through reroute points again and draw the points for (int i = 0; i < reroutePoints.Count; i++) { RerouteReference rerouteRef = new RerouteReference(output, k, i); // Draw reroute point at position Rect rect = new Rect(reroutePoints[i], new Vector2(12, 12)); rect.position = new Vector2(rect.position.x - 6, rect.position.y - 6); rect = GridToWindowRect(rect); // Draw selected reroute points with an outline if (selectedReroutes.Contains(rerouteRef)) { GUI.color = NodeEditorPreferences.GetSettings().highlightColor; GUI.DrawTexture(rect, NodeEditorResources.dotOuter); } GUI.color = connectionColor; GUI.DrawTexture(rect, NodeEditorResources.dot); if (rect.Overlaps(selectionBox)) { selection.Add(rerouteRef); } if (rect.Contains(mousePos)) { hoveredReroute = rerouteRef; } } } } } GUI.color = col; if (Event.current.type != EventType.Layout && currentActivity == NodeActivity.DragGrid) { selectedReroutes = selection; } }
/// <summary> Draws all connections </summary> public void DrawConnections() { Vector2 mousePos = Event.current.mousePosition; List <RerouteReference> selection = preBoxSelectionReroute != null ? new List <RerouteReference>(preBoxSelectionReroute) : new List <RerouteReference>(); hoveredReroute = new RerouteReference(); foreach (XNode.Node node in graph.nodes) { //If a null node is found, return. This can happen if the nodes associated script is deleted. It is currently not possible in Unity to delete a null asset. if (node == null) { continue; } // Draw full connections and output > reroute foreach (XNode.NodePort output in node.Outputs) { //Needs cleanup. Null checks are ugly if (!portConnectionPoints.ContainsKey(output)) { continue; } Color connectionColor = graphEditor.GetTypeColor(output.ValueType); for (int k = 0; k < output.ConnectionCount; k++) { XNode.NodePort input = output.GetConnection(k); // Error handling if (input == null) { continue; //If a script has been updated and the port doesn't exist, it is removed and null is returned. If this happens, return. } if (!input.IsConnectedTo(output)) { input.Connect(output); } if (!_portConnectionPoints.ContainsKey(input)) { continue; } Vector2 from = _portConnectionPoints[output].center; Vector2 to = Vector2.zero; List <Vector2> reroutePoints = output.GetReroutePoints(k); // Loop through reroute points and draw the path for (int i = 0; i < reroutePoints.Count; i++) { to = reroutePoints[i]; DrawConnection(from, to, connectionColor); from = to; } to = _portConnectionPoints[input].center; DrawConnection(from, to, connectionColor); // Loop through reroute points again and draw the points for (int i = 0; i < reroutePoints.Count; i++) { // Draw reroute point at position Rect rect = new Rect(reroutePoints[i], new Vector2(16, 16)); rect.position = new Vector2(rect.position.x - 8, rect.position.y - 8); rect = GridToWindowRect(rect); Color bgcol = new Color32(90, 97, 105, 255);; if (selectedReroutes.Contains(new RerouteReference(output, k, i))) { bgcol = Color.yellow; } NodeEditorGUILayout.DrawPortHandle(rect, bgcol, connectionColor); if (rect.Overlaps(selectionBox)) { selection.Add(new RerouteReference(output, k, i)); } if (rect.Contains(mousePos)) { hoveredReroute = new RerouteReference(output, k, i); } } } } } if (Event.current.type != EventType.Layout && currentActivity == NodeActivity.DragGrid) { selectedReroutes = selection; } }