private static void DrawPortHandle(Rect rect, Type type) { Color col = GUI.color; GUI.color = new Color32(90, 97, 105, 255); GUI.DrawTexture(rect, NodeEditorResources.dotOuter); GUI.color = NodeEditorPreferences.GetTypeColor(type); GUI.DrawTexture(rect, NodeEditorResources.dot); GUI.color = col; }
private static void DrawPortHandle(Rect rect, Type type, Color backgroundColor) { Color col = GUI.color; GUI.color = backgroundColor; GUI.DrawTexture(rect, NodeEditorResources.dotOuter); GUI.color = NodeEditorPreferences.GetTypeColor(type); GUI.DrawTexture(rect, NodeEditorResources.dot); GUI.color = col; }
/// <summary> Draw a connection as we are dragging it </summary> public void DrawDraggedConnection() { if (IsDraggingPort) { if (!_portConnectionPoints.ContainsKey(draggedOutput)) return; Vector2 from = _portConnectionPoints[draggedOutput].center; Vector2 to = draggedOutputTarget != null ? portConnectionPoints[draggedOutputTarget].center : WindowToGridPosition(Event.current.mousePosition); Color col = NodeEditorPreferences.GetTypeColor(draggedOutput.ValueType); col.a = 0.6f; DrawConnection(from, to, col); } }
/// <summary> Draw a connection as we are dragging it </summary> public void DrawDraggedConnection() { if (IsDraggingPort) { Color col = NodeEditorPreferences.GetTypeColor(draggedPort.ValueType); col.a = draggedPortTarget != null ? 1.0f : 0.6f; Rect fromRect; if (!_portConnectionPoints.TryGetValue(draggedPort, out fromRect)) { return; } List <Vector2> gridPoints = new List <Vector2>(); gridPoints.Add(fromRect.center); for (int i = 0; i < draggedOutputReroutes.Count; i++) { gridPoints.Add(draggedOutputReroutes[i]); } if (draggedPortTarget != null) { gridPoints.Add(portConnectionPoints[draggedPortTarget].center); } else { gridPoints.Add(WindowToGridPosition(Event.current.mousePosition)); } if (draggedPort.IsInput) { gridPoints.Reverse(); } DrawNoodle(col, gridPoints); Color bgcol = Color.black; Color frcol = col; bgcol.a = 0.6f; frcol.a = 0.6f; // Loop through reroute points again and draw the points for (int i = 0; i < draggedOutputReroutes.Count; i++) { // Draw reroute point at position Rect rect = new Rect(draggedOutputReroutes[i], new Vector2(16, 16)); rect.position = new Vector2(rect.position.x - 8, rect.position.y - 8); rect = GridToWindowRect(rect); NodeEditorGUILayout.DrawPortHandle(rect, bgcol, frcol); } } }
/// <summary> Draw a connection as we are dragging it </summary> public void DrawDraggedConnection() { if (IsDraggingPort) { Color col = NodeEditorPreferences.GetTypeColor(draggedOutput.ValueType); Rect fromRect; if (!_portConnectionPoints.TryGetValue(draggedOutput, out fromRect)) { return; } Vector2 from = fromRect.center; col.a = draggedOutputTarget != null ? 1.0f : 0.6f; Vector2 to = Vector2.zero; for (int i = 0; i < draggedOutputReroutes.Count; i++) { to = draggedOutputReroutes[i]; DrawConnection(from, to, col); from = to; } to = draggedOutputTarget != null ? portConnectionPoints[draggedOutputTarget].center : WindowToGridPosition(Event.current.mousePosition); DrawConnection(from, to, col); Color bgcol = Color.black; Color frcol = col; bgcol.a = 0.6f; frcol.a = 0.6f; // Loop through reroute points again and draw the points for (int i = 0; i < draggedOutputReroutes.Count; i++) { // Draw reroute point at position Rect rect = new Rect(draggedOutputReroutes[i], new Vector2(16, 16)); rect.position = new Vector2(rect.position.x - 8, rect.position.y - 8); rect = GridToWindowRect(rect); NodeEditorGUILayout.DrawPortHandle(rect, bgcol, frcol); } } }
/// <summary> Draws all connections </summary> public void DrawConnections() { foreach (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 (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++) { 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; DrawConnection(from, to, NodeEditorPreferences.GetTypeColor(output.ValueType)); } } } }
public virtual Color GetTypeColor(Type type) { return(NodeEditorPreferences.GetTypeColor(type)); }