public static void TryToMakeNewConnection(Joint from, Joint to, Connection lastDraggedConnection) { if (from != null && to != null){ if (lastDraggedConnection.InputJoint != null && lastDraggedConnection.OutputJoint != null){ ObjectConnector.UpdateExistingConnection(from, to, lastDraggedConnection); } else { ObjectConnector.CreateNewConnection(from, to); } } }
public static void UpdateExistingConnection(Joint jointFrom, Joint jointTo, Connection existingConnection) { if (jointFrom == jointTo){ return; } Joint changeJointFrom, changeJointTo; Joint anotherJoint; if (existingConnection.InputJoint == jointFrom || existingConnection.InputJoint == jointTo){ changeJointFrom = existingConnection.InputJoint; anotherJoint = existingConnection.OutputJoint; } else { changeJointFrom = existingConnection.OutputJoint; anotherJoint = existingConnection.InputJoint; } ClearReffToAnotherObject(changeJointFrom); changeJointTo = jointFrom == changeJointFrom ? jointTo : jointFrom; CreateNewConnection(changeJointTo, anotherJoint); }
void HandleDraggConnections(List<Node> nodes, Connection lastDraggedConnection) { switch(Event.current.GetTypeForControl(ControlID)){ case EventType.MouseDown: { StartDraggJoint = GetJointUnderMousePosition(nodes); if (StartDraggJoint != null){ GUIUtility.hotControl = StartDraggJoint.ControlID; Event.current.Use(); } break; } case EventType.mouseUp: { if (StartDraggJoint != null){ Joint EndDragJoint = GetJointUnderMousePosition(nodes); ObjectConnector.TryToMakeNewConnection(StartDraggJoint, EndDragJoint, lastDraggedConnection); StartDraggJoint = null; GUIUtility.hotControl = 0; Event.current.Use(); } break ; } } }