public void Draw(Rect rect, HashSet <Node> selected, Vector2 drag) { r.width = rect.width; r.height = rect.height; GraphTransform dragTransform = new GraphTransform(transform); dragTransform.offset += drag; GUI.BeginGroup(rect); GraphUtility.PushBackgroundColor(Color.black); GraphUtility.PopBackgroundColor(); DrawGrid(rect.size); foreach (Noodle noodle in noodles) { noodle.Draw(transform); } foreach (Node node in nodes) { if (selected.Contains(node)) { GraphUtility.PushBackgroundColor(Color.green); node.Draw(dragTransform); GraphUtility.PopBackgroundColor(); } else { node.Draw(transform); } } GUI.EndGroup(); }
public Rect GetRect(GraphTransform transform, bool includePorts) { if (!dirty) { if (includePorts) { Rect full = new Rect( rect.x - (PORT_PAD + PORT_SIZE), rect.y, rect.width + ((PORT_PAD + PORT_SIZE) * 2), rect.height); return(full); } return(rect); } rect.x = position.x + transform.offset.x; rect.y = position.y + transform.offset.y; int inputCount = input == null ? 0 : input.Count; int outputCount = output == null ? 0 : output.Count; float width = EditorStyles.nodeTitle.CalcSize(GUIUtil.TempContent(name)).x + (NODE_PAD * 2); float height = TITLE_HEIGHT + PORT_PAD; float pad = NODE_PAD * 2; for (int i = 0; i < System.Math.Max(inputCount, outputCount); i++) { float inputWidth = i < inputCount?EditorStyles.nodePortLabel.CalcSize(GUIUtil.TempContent(input[i].GetLabel())).x + pad : 0f; float outputWidth = i < outputCount?EditorStyles.nodePortLabel.CalcSize(GUIUtil.TempContent(output[i].GetLabel())).x + pad : 0f; width = Mathf.Max(width, inputWidth + outputWidth); height += PORT_LINE_HEIGHT + PORT_PAD; } rect.width = width; rect.height = height; if (includePorts) { rect.x -= (PORT_PAD + PORT_SIZE); rect.width += (PORT_PAD + PORT_SIZE) * 2; } return(rect); }
public void Draw(GraphTransform transform) { if (source.node == null || destination.node == null) { return; } int leftIndex = source.node.GetPortIndex(source.port); int rightIndex = destination.node.GetPortIndex(destination.port); if (leftIndex < 0 || rightIndex < 0) { Debug.LogWarning("Port index invalid!\n" + source.ToString() + "\n" + destination.ToString()); return; } Vector2 left = source.node.GetPortRectAtIndex(PortType.Input, leftIndex).center; Vector2 right = destination.node.GetPortRectAtIndex(PortType.Output, rightIndex).center; Draw(left, right); }
public GraphTransform(GraphTransform transform) { this.offset = transform.offset; this.scale = transform.scale; }
public virtual void Draw(GraphTransform transform) { rect = GetRect(transform, false); GUI.Label(rect, "", EditorStyles.nodeBackground); Rect nodeTitle = new Rect( rect.x + NODE_PAD, rect.y + 1, 300, 40); GUI.Label(nodeTitle, name, EditorStyles.nodeTitle); Rect portText = new Rect( rect.x + NODE_PAD, rect.y + TITLE_HEIGHT + PORT_PAD, 300, PORT_LINE_HEIGHT); Rect portIcon = new Rect( rect.x - PORT_SIZE - PORT_PAD, 0, PORT_SIZE, PORT_SIZE); if (input != null) { foreach (Port port in input) { portIcon.y = (portText.y + (PORT_LINE_HEIGHT / 2)) - (PORT_SIZE / 2) + 1; GUI.Label(portIcon, "", EditorStyles.nodeBackground); GUI.Label(portText, port.GetLabel(), EditorStyles.nodePortLabel); portIcon.y += PORT_SIZE + PORT_PAD; portText.y += PORT_LINE_HEIGHT; } } if (output != null) { portText.y = rect.y + TITLE_HEIGHT + PORT_PAD; portIcon.x = rect.x + rect.width + PORT_PAD; foreach (Port port in output) { GUIContent content = GUIUtil.TempContent(port.GetLabel()); portIcon.y = (portText.y + (PORT_LINE_HEIGHT / 2)) - (PORT_SIZE / 2) + 1; Vector2 labelSize = EditorStyles.nodePortLabel.CalcSize(content); portText.x = (rect.x + rect.width) - (NODE_PAD + labelSize.x); GUI.Label(portIcon, "", EditorStyles.nodeBackground); GUI.Label(portText, content, EditorStyles.nodePortLabel); portIcon.y += PORT_SIZE + PORT_PAD; portText.y += PORT_LINE_HEIGHT; } } }