void AddLinkedContext(VFXNodeProvider.Descriptor d, Vector2 mPos) { VFXView view = GetFirstAncestorOfType <VFXView>(); if (view == null) { return; } Vector2 tPos = view.ChangeCoordinatesTo(view.contentViewContainer, mPos); view.UpdateSelectionWithNewNode(); VFXContext context = view.controller.AddVFXContext(tPos, d.modelDescriptor as VFXModelDescriptor <VFXContext>); view.controller.LightApplyChanges(); if (context == null) { return; } if (direction == Direction.Input) { controller.context.model.LinkFrom(context, 0, controller.slotIndex); } else { controller.context.model.LinkTo(context, controller.slotIndex, 0); } }
void PostSetupNode() { PostSetup(); m_SourceNode.position = m_Rect.center; m_SourceView.UpdateSelectionWithNewNode(); m_SourceController.graph.AddChild(m_SourceNode); m_SourceNode.SetSettingValue("m_Subgraph", m_TargetSubgraph); m_SourceController.LightApplyChanges(); m_SourceNodeController = m_SourceController.GetRootNodeController(m_SourceNode, 0); m_SourceNodeController.ApplyChanges(); }
void IEdgeConnectorListener.OnDropOutsidePort(Edge edge, Vector2 position) { VFXSlot startSlot = controller.model; VFXView view = this.GetFirstAncestorOfType <VFXView>(); VFXViewController viewController = view.controller; List <VisualElement> picked = new List <VisualElement>(); panel.PickAll(position, picked); VFXNodeUI endNode = null; foreach (var element in picked) { if (element is VFXNodeUI node) { endNode = node; break; } } VFXDataEdge dataEdge = edge as VFXDataEdge; bool exists = false; if (dataEdge.controller != null) { exists = true; view.controller.RemoveElement(dataEdge.controller); } if (endNode != null) { VFXNodeController nodeController = endNode.controller; if (nodeController != null) { IVFXSlotContainer slotContainer = nodeController.slotContainer; if (controller.direction == Direction.Input) { foreach (var output in nodeController.outputPorts.Where(t => t.model == null || t.model.IsMasterSlot())) { if (viewController.CreateLink(controller, output)) { break; } } } else { foreach (var input in nodeController.inputPorts.Where(t => t.model == null || t.model.IsMasterSlot() && !t.model.HasLink(true))) { if (viewController.CreateLink(input, controller)) { break; } } } } } else if (controller.direction == Direction.Input && Event.current.modifiers == EventModifiers.Alt) { var targetType = controller.portType; var attribute = VFXLibrary.GetAttributeFromSlotType(controller.portType); VFXModelDescriptorParameters parameterDesc; if (attribute != null && attribute.usages.HasFlag(VFXTypeAttribute.Usage.ExcludeFromProperty)) { parameterDesc = VFXLibrary.GetParameters().FirstOrDefault(t => { if (!t.model.outputSlots[0].CanLink(controller.model)) { return(false); } var attributeCandidate = VFXLibrary.GetAttributeFromSlotType(t.model.type); return(attributeCandidate == null || !attributeCandidate.usages.HasFlag(VFXTypeAttribute.Usage.ExcludeFromProperty)); }); } else { parameterDesc = VFXLibrary.GetParameters().FirstOrDefault(t => { return(t.model.type == targetType); }); } if (parameterDesc != null) { Vector2 pos = view.contentViewContainer.GlobalToBound(position) - new Vector2(140, 20); view.UpdateSelectionWithNewNode(); VFXParameter parameter = viewController.AddVFXParameter(pos, parameterDesc, false); parameter.SetSettingValue("m_Exposed", true); startSlot.Link(parameter.outputSlots[0]); CopyValueToParameter(parameter); viewController.AddVFXModel(pos, parameter); } } else if (!exists) { var window = VFXViewWindow.GetWindow(view); if (direction == Direction.Input || viewController.model.visualEffectObject is VisualEffectSubgraphOperator || viewController.model.visualEffectObject is VisualEffectSubgraphBlock) // no context for subgraph operators. { VFXFilterWindow.Show(window, Event.current.mousePosition, view.ViewToScreenPosition(Event.current.mousePosition), new VFXNodeProvider(viewController, AddLinkedNode, ProviderFilter, new Type[] { typeof(VFXOperator), typeof(VFXParameter) })); } else { VFXFilterWindow.Show(window, Event.current.mousePosition, view.ViewToScreenPosition(Event.current.mousePosition), new VFXNodeProvider(viewController, AddLinkedNode, ProviderFilter, new Type[] { typeof(VFXOperator), typeof(VFXParameter), typeof(VFXContext) })); } } }