/// <summary> /// Handles sending the motion data to the selected nodes /// </summary> private void HandleMouseMove() { IEnumerable <Node> selectedNodes = NodeEditor.GetSelectedNodes(); int used = 0; int count = 0; Vector2 zoomedDrag = NodeEditor.ApplyZoomToVector(Event.current.delta); foreach (Node node in selectedNodes) { if (node.HandleDrag(zoomedDrag)) { used++; } count++; } if (used > 0) { NodeEditor.FlagRepaint(); Event.current.Use(); } else if (count == 0) { Deactivate(); } }
/// <summary> /// Initializes the connections based on the selected connection logic /// </summary> private void InitializeConnections() { IEnumerable <Node> selectedNodes = NodeEditor.GetSelectedNodes(); switch (ConnectionLogic) { case ConnectionStyle.FIRST_SELECTED: selectedNodes = new Node[] { selectedNodes.FirstOrDefault() }; break; case ConnectionStyle.LAST_SELECTED: selectedNodes = new Node[] { selectedNodes.LastOrDefault() }; break; } foreach (Node node in selectedNodes) { if (node == null) { continue; } Connector connector = ConnectorFactory(NodeEditor, node, NodeEditor.MouseNode); NodeEditor.AddConnector(connector); newConnections.Add(connector); } }
/// <summary> /// Perform the focusing logic /// </summary> private void PerformFocus() { IEnumerable <Node> selectedNodes = NodeEditor.GetSelectedNodes(); int count = 0; Vector2 averagePosition = Vector2.zero; foreach (Node node in selectedNodes) { averagePosition += node.NodeRect.position; count++; } IEnumerable <Connector> selectedConnectors = NodeEditor.GetSelectedConnectors(); foreach (Connector connector in selectedConnectors) { Node startNode = connector.GetStartNode(); Node endNode = connector.GetEndNode(); averagePosition += ((startNode.NodeRect.position + endNode.NodeRect.position) * 0.5f); count++; } if (count == 0) { foreach (Node node in NodeEditor.Nodes) { averagePosition += node.NodeRect.position; count++; } } if (count == 0) { NodeEditor.SetPanOffset(Vector2.zero); return; } Vector2 offset = NodeEditor.NodeEditorRect.size * 0.5f; NodeEditor.SetPanOffset((-averagePosition / count) + offset); }