/* ------------------------------------------- Node Drawing --------------------------------------------- */ void DrawNodes() { if (sequence == null || sequence.nodes == null) { return; } foreach (int key in sequence.nodes.Keys) { DrawNode(sequence.nodes[key], key); if (sequence.nodes[key].next == null) { continue; } foreach (BaseNode child in sequence.nodes[key].next) { CurveUtils.DrawNodeCurve(sequence.nodes[key].position, child.position); } } }
/// <summary> /// Handles connections between nodes /// </summary> /// <param name="e">E.</param> void HandleConnections() { Event e = Event.current; if (sequence == null || sequence.nodes == null) { return; } if ((e.type == EventType.MouseDown) && e.button == 0) { foreach (int key in sequence.nodes.Keys) { if (CurveUtils.IsStartCurve(sequence.nodes[key], e.mousePosition)) { this.isDraggingConnector = true; this.dragStart = sequence.nodes[key]; e.Use(); break; } else if (CurveUtils.IsEndCurve(sequence.nodes[key], e.mousePosition) && sequence.nodes[key].prev != null) { this.dragStart = sequence.nodes[key].prev; this.isDraggingConnector = true; sequence.nodes[key].prev.Remove(sequence.nodes[key]); sequence.nodes[key].prev = null; } } } if (e.type == EventType.MouseUp && e.button == 0) { this.isDraggingConnector = false; foreach (int key in sequence.nodes.Keys) { if (CurveUtils.IsEndCurve(sequence.nodes[key], e.mousePosition)) { sequence.nodes[key].AddInput(this.dragStart); this.dragStart.AddOutput(sequence.nodes[key]); } } Repaint();//repaint to stop drawing the curve } }