public BaseEdge Connect(NodePort _inputPort, NodePort _outputPort)
        {
            // 在连接两个端口,如果端口设置为只能连接一个端口,则需要在连接前把其他所有连接断开
            if (!_inputPort.Multiple)
            {
                Disconnect(_inputPort);
            }
            if (!_outputPort.Multiple)
            {
                Disconnect(_outputPort);
            }

            // 创建一条连线
            BaseEdge edge = BaseEdge.CreateNewEdge(_inputPort, _outputPort);

            edge.Enable(this);
            edges[edge.GUID] = edge;

            _inputPort.ConnectToEdge(edge);
            _outputPort.ConnectToEdge(edge);

            onEdgeAdded?.Invoke(edge);

            _inputPort.Owner.OnConnected(_inputPort, _outputPort);
            _outputPort.Owner.OnConnected(_outputPort, _inputPort);
            return(edge);
        }
Пример #2
0
 public void ConnectToEdge(BaseEdge _edge)
 {
     if (!edgeGUIDs.Contains(_edge.GUID))
     {
         edgeGUIDs.Add(_edge.GUID);
     }
 }
Пример #3
0
        /// <summary> ͨ��EdgeGUID��ȡ�ӵ�Զ�̶˿� </summary>
        public NodePort GetConnection(int _edgeGUID)
        {
            BaseEdge edge = GetEdge(_edgeGUID);

            if (edge == null)
            {
                return(null);
            }
            return(Direction == PortDirection.Input ? edge.OutputPort : edge.InputPort);
        }
        public void AddRelayNode(BaseEdge _edge, Vector2 _position)
        {
            NodePort inputPort  = _edge.InputPort;
            NodePort outputPort = _edge.OutputPort;

            DisconnectEdge(_edge.GUID);

            var      relayNode = BaseNode.CreateNew <RelayNode>(_position);
            BaseNode node      = AddNode(relayNode);

            Connect(node.Ports[nameof(RelayNode.input)], outputPort);
            Connect(inputPort, node.Ports[nameof(RelayNode.output)]);
        }
Пример #5
0
        public static BaseEdge CreateNewEdge(NodePort _inputPort, NodePort _outputPort)
        {
            BaseEdge edge = new BaseEdge();

            edge.guid = Guid.NewGuid().ToString();

            edge.inputNodeGUID  = _inputPort.Owner.GUID;
            edge.inputFieldName = _inputPort.FieldName;

            edge.outputNodeGUID  = _outputPort.Owner.GUID;
            edge.outputFieldName = _outputPort.FieldName;

            return(edge);
        }
Пример #6
0
 public void DisconnectToEdge(BaseEdge _edge)
 {
     DisconnectToEdge(_edge.GUID);
 }