Example #1
0
 public void RemoveNodeView(BaseNodeView nodeView)
 {
     RemoveElement(nodeView);
     nodeViews.Remove(nodeView);
     nodeViewsPerNode.Remove(nodeView.nodeTarget);
     UpdateComputeOrder();
 }
        Rect GetPortBounds(BaseNodeView nodeView, int index, List <PortView> portList)
        {
            var port   = portList[index];
            var bounds = port.worldBound;

            if (port.orientation == Orientation.Horizontal)
            {
                // Increase horizontal port bounds
                bounds.xMin = nodeView.worldBound.xMin;
                bounds.xMax = nodeView.worldBound.xMax;

                if (index == 0)
                {
                    bounds.yMin = nodeView.worldBound.yMin;
                }
                if (index == portList.Count - 1)
                {
                    bounds.yMax = nodeView.worldBound.yMax;
                }

                if (index > 0)
                {
                    Rect above = portList[index - 1].worldBound;
                    bounds.yMin = (above.yMax + bounds.yMin) / 2.0f;
                }
                if (index < portList.Count - 1)
                {
                    Rect below = portList[index + 1].worldBound;
                    bounds.yMax = (below.yMin + bounds.yMax) / 2.0f;
                }

                if (port.direction == Direction.Input)
                {
                    bounds.xMin -= kPortDetectionWidth;
                }
                else
                {
                    bounds.xMax += kPortDetectionWidth;
                }
            }
            else
            {
                // Increase vertical port bounds
                if (port.direction == Direction.Input)
                {
                    bounds.yMin -= kPortDetectionWidth;
                }
                else
                {
                    bounds.yMax += kPortDetectionWidth;
                }
            }

            return(bounds);
        }
Example #3
0
        public static void CreatePortBehavior(BaseNodeView nodeView, FieldInfo field, Direction direction, EdgeConnectorListener listener, bool isMultiple, string name)
        {
            Type behaviorType;

            portBehaviors.TryGetValue(field.FieldType, out behaviorType);

            if (behaviorType == null)
            {
                behaviorType = typeof(DefaultPortBehavior);
            }

            Activator.CreateInstance(behaviorType, nodeView, field, direction, listener, isMultiple, name);
        }
Example #4
0
        public virtual void Initialize(BaseNodeView nodeView, string name)
        {
            this.owner = nodeView;

            // Correct port type if port accept multiple values (and so is a container)
            if (direction == Direction.Input && portData.acceptMultipleEdges && portType == fieldType)             // If the user haven't set a custom field type
            {
                portType = fieldType.GetGenericArguments()[0];
            }

            if (name != null)
            {
                portName = name;
            }
            visualClass = "Port_" + portType.Name;
        }
Example #5
0
        public virtual void Initialize(BaseNodeView nodeView, bool isMultiple, string name)
        {
            this.isMultiple = isMultiple;
            this.owner      = nodeView;

            // Correct port type if port accept multiple values (and so is a container)
            if (isMultiple)
            {
                portType = portType.GetGenericArguments()[0];
            }

            if (name != null)
            {
                portName = name;
            }
            visualClass = "Port_" + portType.Name;
        }
        protected VisualElement CreateNodeBlock(BaseNodeView nodeView)
        {
            var view = new VisualElement();

            view.Add(new Label(nodeView.nodeTarget.name));

            var tmp = nodeView.controlsContainer;

            nodeView.controlsContainer = view;
            nodeView.Enable(true);
            nodeView.controlsContainer.AddToClassList("NodeControls");
            var block = nodeView.controlsContainer;

            nodeView.controlsContainer = tmp;

            return(block);
        }
Example #7
0
        public MultiPortBehavior(BaseNodeView nodeView, FieldInfo fieldInfo, Direction direction, EdgeConnectorListener listener, bool isMultiple, string name)
        {
            this.multiPorts = fieldInfo.GetValue(nodeView.nodeTarget) as MultiPorts;
            this.node       = nodeView;
            this.fieldInfo  = fieldInfo;
            this.direction  = direction;
            this.listener   = listener;
            this.isMultiple = isMultiple;
            this.name       = name;

            // Initialize the MultiPort field if null
            if (multiPorts == null)
            {
                multiPorts = new MultiPorts();
                fieldInfo.SetValue(nodeView.nodeTarget, multiPorts);
            }

            // Instantiate all ports needed to create the serialized connections
            // Minus one because we count our current instance
            for (int i = 0; i < multiPorts.portCount; i++)
            {
                AddPort();
            }
        }
Example #8
0
 public DefaultPortBehavior(BaseNodeView nodeView, FieldInfo fieldInfo, Direction direction, EdgeConnectorListener listener, bool isMultiple, string name)
 {
     nodeView.AddPort(fieldInfo, direction, listener, isMultiple, name);
 }
Example #9
0
 public virtual void NodeViewRemoved(BaseNodeView view)
 {
     selectedNodes.Remove(view);
     nodeSelectionUpdated?.Invoke();
 }
Example #10
0
 protected void RemoveNodeView(BaseNodeView nodeView)
 {
     RemoveElement(nodeView);
     nodeViews.Remove(nodeView);
     nodeViewsPerNode.Remove(nodeView.nodeTarget);
 }
 public virtual void NodeViewRemoved(BaseNodeView view)
 {
     selectedNodes.Remove(view);
 }