Exemplo n.º 1
0
        /// <summary> 连接节点 </summary>
        IEnumerator LinkNodeViews()
        {
            int step = 0;

            foreach (var connection in Model.Connections)
            {
                if (connection == null)
                {
                    continue;
                }
                BaseNodeView fromNodeView, toNodeView;
                if (!NodeViews.TryGetValue(connection.FromNodeGUID, out fromNodeView))
                {
                    throw new NullReferenceException($"找不到From节点{connection.FromNodeGUID}");
                }
                if (!NodeViews.TryGetValue(connection.ToNodeGUID, out toNodeView))
                {
                    throw new NullReferenceException($"找不到To节点{connection.ToNodeGUID}");
                }
                ConnectView(fromNodeView, toNodeView, connection);
                step++;
                if (step % 5 == 0)
                {
                    yield return(null);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary> 连接节点 </summary>
        IEnumerator LinkNodeViews()
        {
            foreach (var serializedEdge in Model.Edges)
            {
                yield return(0);

                if (serializedEdge.Value == null)
                {
                    continue;
                }
                BaseNodeView inputNodeView, outputNodeView;
                if (!NodeViews.TryGetValue(serializedEdge.Value.InputNodeGUID, out inputNodeView))
                {
                    yield break;
                }
                if (!NodeViews.TryGetValue(serializedEdge.Value.OutputNodeGUID, out outputNodeView))
                {
                    yield break;
                }
                ConnectView(inputNodeView.PortViews[serializedEdge.Value.InputFieldName]
                            , outputNodeView.PortViews[serializedEdge.Value.OutputFieldName]
                            , serializedEdge.Value);
            }
        }
Exemplo n.º 3
0
        void DeserializeAndPasteCallback(string _operationName, string _serializedData)
        {
            ClearSelection();
            var data = SerializationUtility.DeserializeValue <ClipBoard>(Encoding.UTF8.GetBytes(_serializedData), DataFormat.JSON, ClipBoard.objectReferences);
            Dictionary <string, BaseNode> copiedNodesMap = new Dictionary <string, BaseNode>();

            foreach (var node in data.copiedNodes)
            {
                if (node == null)
                {
                    continue;
                }
                string sourceGUID = node.GUID;
                // 新节点重置id
                BaseNode.IDAllocation(node);
                // 新节点与旧id存入字典
                copiedNodesMap[sourceGUID] = node;
                Model.AddNode(node).ClearConnectionsWithoutNotification();
                node.Position += new Vector2(20, 20);
                AddToSelection(NodeViews[node.GUID]);
            }

            foreach (var group in data.copiedGroups)
            {
                group.Position = new Rect(new Vector2(20, 20), group.Position.size);

                var oldGUIDList = group.InnerNodeGUIDs.ToList();
                group.InnerNodeGUIDs.Clear();

                foreach (var guid in oldGUIDList)
                {
                    if (copiedNodesMap.TryGetValue(guid, out var node))
                    {
                        group.InnerNodeGUIDs.Add(node.GUID);
                    }
                }
                Model.AddGroup(group);
            }

            foreach (var edge in data.copiedEdges)
            {
                //edge.Enable(Model);
                copiedNodesMap.TryGetValue(edge.InputNodeGUID, out var inputNode);
                copiedNodesMap.TryGetValue(edge.OutputNodeGUID, out var outputNode);

                inputNode  = inputNode == null ? Model.Nodes[edge.InputNodeGUID] : Model.Nodes[inputNode.GUID];
                outputNode = outputNode == null ? Model.Nodes[edge.OutputNodeGUID] : Model.Nodes[outputNode.GUID];

                if (inputNode == null || outputNode == null)
                {
                    continue;
                }

                inputNode.TryGetPort(edge.InputFieldName, out NodePort inputPort);
                outputNode.TryGetPort(edge.OutputFieldName, out NodePort outputPort);
                if (!inputPort.Multiple && inputPort.IsConnected)
                {
                    continue;
                }
                if (!outputPort.Multiple && outputPort.IsConnected)
                {
                    continue;
                }

                if (NodeViews.TryGetValue(inputNode.GUID, out BaseNodeView inputNodeView) &&
                    NodeViews.TryGetValue(outputNode.GUID, out BaseNodeView outputNodeView))
                {
                    Model.Connect(inputNodeView.Model.Ports[edge.InputFieldName], outputNodeView.Model.Ports[edge.OutputFieldName]);
                }
            }

            SetDirty();
        }