protected virtual void OnMouseMove(MouseMoveEvent e) { if (!m_Active) { return; } m_EdgeDragHelper.HandleMouseMove(e); e.StopPropagation(); }
protected void OnMouseMove(MouseMoveEvent evt) { // If the left mouse button is not down then return if (m_Edge == null) { return; } evt.StopPropagation(); bool alreadyDetached = (m_DetachedPort != null); // If one end of the edge is not already detached then if (!alreadyDetached) { float delta = (evt.mousePosition - m_PressPos).sqrMagnitude; if (delta < (s_StartDragDistance * s_StartDragDistance)) { return; } var graphView = m_Edge.GetFirstAncestorOfType <GraphView>(); var outputPortUI = m_Edge.Output.GetUI <Port>(graphView); var inputPortUI = m_Edge.Input.GetUI <Port>(graphView); if (outputPortUI == null || inputPortUI == null) { return; } // Determine which end is the nearest to the mouse position then detach it. Vector2 outputPos = new Vector2(outputPortUI.GetGlobalCenter().x, outputPortUI.GetGlobalCenter().y); Vector2 inputPos = new Vector2(inputPortUI.GetGlobalCenter().x, inputPortUI.GetGlobalCenter().y); float distanceFromOutput = (m_PressPos - outputPos).sqrMagnitude; float distanceFromInput = (m_PressPos - inputPos).sqrMagnitude; if (distanceFromInput > 50 * 50 && distanceFromOutput > 50 * 50) { return; } m_DetachedFromInputPort = distanceFromInput < distanceFromOutput; IGTFPortModel connectedPort; Port connectedPortUI; if (m_DetachedFromInputPort) { connectedPort = m_Edge.Output; connectedPortUI = outputPortUI; m_DetachedPort = m_Edge.Input; } else { connectedPort = m_Edge.Input; connectedPortUI = inputPortUI; m_DetachedPort = m_Edge.Output; } // Use the edge drag helper of the still connected port m_ConnectedEdgeDragHelper = connectedPortUI.EdgeConnector.edgeDragHelper; m_ConnectedEdgeDragHelper.originalEdge = m_Edge; m_ConnectedEdgeDragHelper.draggedPort = connectedPort; m_ConnectedEdgeDragHelper.CreateEdgeCandidate(connectedPort.GraphModel); m_ConnectedEdgeDragHelper.edgeCandidateModel.EndPoint = evt.mousePosition; // Redirect the last mouse down event to active the drag helper if (m_ConnectedEdgeDragHelper.HandleMouseDown(m_LastMouseDownEvent)) { m_Active = true; } else { Reset(); } m_LastMouseDownEvent = null; } if (m_Active) { m_ConnectedEdgeDragHelper.HandleMouseMove(evt); } }