protected override void OnMouseMove(MouseMoveEvent e) { base.OnMouseMove(e); if (!e.isPropagationStopped) { return; } VFXView view = m_Anchor.GetFirstAncestorOfType <VFXView>(); if (view == null) { return; } s_PickedList.Clear(); view.panel.PickAll(e.mousePosition, s_PickedList); VFXDataAnchor anchor = s_PickedList.OfType <VFXDataAnchor>().FirstOrDefault(); if (anchor != null) { view.StartEdgeDragInfo(this.edgeDragHelper.draggedPort as VFXDataAnchor, anchor); } else { view.StopEdgeDragInfo(); } }
void SyncAnchors(ReadOnlyCollection <VFXDataAnchorController> ports, VisualElement container) { var existingAnchors = container.Children().Cast <VFXDataAnchor>().ToDictionary(t => t.controller, t => t); Profiler.BeginSample("VFXNodeUI.SyncAnchors Delete"); var deletedControllers = existingAnchors.Keys.Except(ports).ToArray(); foreach (var deletedController in deletedControllers) { //Explicitely remove edges before removing anchor. GetFirstAncestorOfType <VFXView>().RemoveAnchorEdges(existingAnchors[deletedController]); container.Remove(existingAnchors[deletedController]); existingAnchors.Remove(deletedController); } Profiler.EndSample(); Profiler.BeginSample("VFXNodeUI.SyncAnchors New"); var order = ports.Select((t, i) => new KeyValuePair <VFXDataAnchorController, int>(t, i)).ToDictionary(t => t.Key, t => t.Value); var newAnchors = ports.Except(existingAnchors.Keys).ToArray(); foreach (var newController in newAnchors) { Profiler.BeginSample("VFXNodeUI.InstantiateDataAnchor"); var newElement = InstantiateDataAnchor(newController, this); Profiler.EndSample(); (newElement as VFXDataAnchor).controller = newController; container.Add(newElement); existingAnchors[newController] = newElement; } Profiler.EndSample(); Profiler.BeginSample("VFXNodeUI.SyncAnchors Reorder"); //Reorder anchors. if (ports.Count > 0) { var correctOrder = new VFXDataAnchor[ports.Count]; foreach (var kv in existingAnchors) { correctOrder[order[kv.Key]] = kv.Value; } correctOrder[0].SendToBack(); correctOrder[0].AddToClassList("first"); for (int i = 1; i < correctOrder.Length; ++i) { if (container.ElementAt(i) != correctOrder[i]) { correctOrder[i].PlaceInFront(correctOrder[i - 1]); } correctOrder[i].RemoveFromClassList("first"); } } Profiler.EndSample(); }
public static VFXDataAnchor Create(VFXDataAnchorController controller, VFXNodeUI node) { var anchor = new VFXDataAnchor(controller.orientation, controller.direction, controller.portType, node); anchor.m_EdgeConnector = new VFXEdgeConnector(anchor); anchor.controller = controller; anchor.AddManipulator(anchor.m_EdgeConnector); return anchor; }
public void StartEdgeDragInfo(VFXDataAnchor draggedAnchor, VFXDataAnchor overAnchor) { if (m_Displaying) { DisplayEdgeDragInfo(draggedAnchor, overAnchor); } else if (m_ScheduledItem == null) { m_ScheduledItem = m_View.schedule.Execute(t => DisplayEdgeDragInfo(draggedAnchor, overAnchor)).StartingIn(1000); } }
public VFXEdgeConnector(VFXDataAnchor anchor) : base(anchor) { m_Anchor = anchor; }
public void DisplayEdgeDragInfo(VFXDataAnchor draggedAnchor, VFXDataAnchor overAnchor) { if (m_ScheduledItem != null) { m_ScheduledItem.Pause(); m_ScheduledItem = null; } string error = null; if (draggedAnchor != overAnchor) { if (draggedAnchor.direction == overAnchor.direction) { if (draggedAnchor.direction == Direction.Input) { error = "You must link an input to an output"; } else { error = "You must link an output to an input"; } } else if (draggedAnchor.controller.connections.Any(t => draggedAnchor.direction == Direction.Input ? t.output == overAnchor.controller : t.input == overAnchor.controller)) { error = "An edge with the same input and output already exists"; } else if (!draggedAnchor.controller.model.CanLink(overAnchor.controller.model)) { error = "The input and output have incompatible types"; } else { bool can = draggedAnchor.controller.CanLink(overAnchor.controller); if (!can) { if (!draggedAnchor.controller.CanLinkToNode(overAnchor.controller.sourceNode, null)) { error = "The edge would create a loop in the operators"; } else { error = "Link impossible for an unknown reason"; } } } } if (error == null) { m_Displaying = false; style.display = DisplayStyle.None; } else { m_Displaying = true; m_Text.text = error; style.display = DisplayStyle.Flex; } Rect anchorLayout = overAnchor.connector.parent.ChangeCoordinatesTo(m_View, overAnchor.connector.layout); style.top = anchorLayout.yMax + 16; style.left = anchorLayout.xMax; //make sure the info is within the view Rect viewLayout = m_View.layout; Vector2 size = layout.size; if (style.top.value.value < 0) { style.top = 0; } if (style.left.value.value < 0) { style.left = 0; } if (style.top.value.value + size.y > viewLayout.yMax) { style.top = viewLayout.yMax - size.y; } if (style.left.value.value + size.x > viewLayout.xMax) { style.left = viewLayout.xMax - size.x; } }