Exemplo n.º 1
0
        public void DisconnectView(BaseConnectionView edgeView)
        {
            BasePortView inputPortView = edgeView.input as BasePortView;
            BaseNodeView inputNodeView = inputPortView.node as BaseNodeView;

            if (inputPortView != null)
            {
                inputPortView.Disconnect(edgeView);
            }
            inputPortView.Disconnect(edgeView);

            BasePortView outputPortView = edgeView.output as BasePortView;
            BaseNodeView outputNodeView = outputPortView.node as BaseNodeView;

            if (outputPortView != null)
            {
                outputPortView.Disconnect(edgeView);
            }
            outputPortView.Disconnect(edgeView);

            inputNodeView.RefreshPorts();
            outputNodeView.RefreshPorts();

            RemoveElement(edgeView);
        }
Exemplo n.º 2
0
        public bool OnSelectEntry(SearchTreeEntry searchTreeEntry, SearchWindowContext context)
        {
            var windowRoot          = graphView.GraphWindow.rootVisualElement;
            var windowMousePosition = windowRoot.ChangeCoordinatesTo(windowRoot.parent, context.screenMousePosition - graphView.GraphWindow.position.position);
            var graphMousePosition  = graphView.contentViewContainer.WorldToLocal(windowMousePosition);

            BaseNode createNode = graphView.Model.NewNode(searchTreeEntry.userData as Type, graphMousePosition);

            //自动连接
            if (ConnectionFilter != null)
            {
                graphView.CommandDispacter.Do(new AddNodeCommand(graphView.Model, createNode));
                Port         port      = ConnectionFilter.input == null ? ConnectionFilter.output : ConnectionFilter.input;
                BasePortView portView1 = port as BasePortView;

                string portName = nodePortNameMap[searchTreeEntry.userData as Type];
                if (checkInPort)
                {
                    graphView.CommandDispacter.Do(new ConnectCommand(graphView.Model, createNode, portName, waitConnectNode, waitConnectPortName));
                }
                else
                {
                    graphView.CommandDispacter.Do(new ConnectCommand(graphView.Model, waitConnectNode, waitConnectPortName, createNode, portName));
                }
            }
            else
            {
                graphView.CommandDispacter.Do(new AddNodeCommand(graphView.Model, createNode));
            }
            graphView.GraphWindow.Focus();
            return(true);
        }
Exemplo n.º 3
0
        void OnPortAdded(BasePort port)
        {
            BasePortView portView = NewPortView(port);

            portView.SetUp(port, Owner);
            portViews[port.name] = portView;

            if (portView.orientation == Orientation.Horizontal)
            {
                if (portView.direction == Direction.Input)
                {
                    inputContainer.Add(portView);
                }
                else
                {
                    outputContainer.Add(portView);
                }
            }
            else
            {
                if (portView.direction == Direction.Input)
                {
                    topPortContainer.Add(portView);
                }
                else
                {
                    bottomPortContainer.Add(portView);
                }
            }
            RefreshPorts();
        }
Exemplo n.º 4
0
 protected virtual bool IsCompatible(BasePortView portView, BasePortView toPortView, NodeAdapter nodeAdapter)
 {
     if (toPortView.direction == portView.direction)
     {
         return(false);
     }
     // 类型兼容查询
     if (!TypesAreConnectable(portView.Model.type, toPortView.Model.type))
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 5
0
        /// <summary>
        /// 获得匹配的端口
        /// </summary>
        /// <param name="startPortView"></param>
        /// <param name="nodeAdapter"></param>
        /// <returns></returns>
        public override List <Port> GetCompatiblePorts(Port startPortView, NodeAdapter nodeAdapter)
        {
            BasePortView portView        = startPortView as BasePortView;
            List <Port>  compatiblePorts = new List <Port>();

            ports.ForEach(_portView =>
            {
                var toPortView = _portView as BasePortView;
                if (IsCompatible(portView, toPortView, nodeAdapter))
                {
                    compatiblePorts.Add(_portView);
                }
            });
            return(compatiblePorts);
        }
Exemplo n.º 6
0
        private void InitPorts()
        {
            void AddPortView(BasePort port)
            {
                if (port == null)
                {
                    return;
                }
                BasePortView portView = NewPortView(port);

                portView.SetUp(port, Owner);
                portViews[port.name] = portView;

                if (portView.orientation == Orientation.Horizontal)
                {
                    if (portView.direction == Direction.Input)
                    {
                        inputContainer.Add(portView);
                    }
                    else
                    {
                        outputContainer.Add(portView);
                    }
                }
                else
                {
                    if (portView.direction == Direction.Input)
                    {
                        topPortContainer.Add(portView);
                    }
                    else
                    {
                        bottomPortContainer.Add(portView);
                    }
                }
            }

            //自定义端口
            foreach (var port in Model.Ports.Values)
            {
                AddPortView(port);
            }
        }
Exemplo n.º 7
0
        //创建连接菜单
        private void CreateEdgeNodeMenu(List <SearchTreeEntry> tree)
        {
            nodePortNameMap.Clear();
            waitConnectNode     = null;
            waitConnectPortName = null;

            void CollectNodePortName(BasePort checkPort, Type nodeType, PortInfo portInfo, bool checkInPort)
            {
                if (checkInPort)
                {
                    for (int i = 0; i < portInfo.InPorts.Count; i++)
                    {
                        if (graphView.TypesAreConnectable(checkPort.type, portInfo.InPorts[i].type))
                        {
                            nodePortNameMap.Add(nodeType, portInfo.InPorts[i].name);
                            return;
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < portInfo.OutPorts.Count; i++)
                    {
                        if (graphView.TypesAreConnectable(checkPort.type, portInfo.OutPorts[i].type))
                        {
                            nodePortNameMap.Add(nodeType, portInfo.OutPorts[i].name);
                            return;
                        }
                    }
                }
            }

            Port port = ConnectionFilter.input == null ? ConnectionFilter.output : ConnectionFilter.input;

            if (port == null)
            {
                return;
            }
            BasePortView portView = port as BasePortView;

            waitConnectNode     = portView.Model.Owner;
            waitConnectPortName = portView.Model.name;
            bool checkInPort = ConnectionFilter.input == null ? true : false;

            foreach (var item in nodePortMap)
            {
                Type     nodeType = item.Key;
                PortInfo portInfo = item.Value;
                CollectNodePortName(portView.Model, nodeType, portInfo, checkInPort);
            }

            //创建菜单
            var titlePaths = new HashSet <string>();

            foreach (var item in nodePortNameMap)
            {
                Type   nodeType = item.Key;
                string portName = item.Value;
                if (!AttributeHelper.TryGetTypeAttribute(nodeType, out NodeMenuItemAttribute attr))
                {
                    continue;
                }
                var nodePath = attr.title;
                var nodeName = nodePath;
                var level    = 0;
                var parts    = nodePath.Split('/');

                if (parts.Length > 1)
                {
                    level++;
                    nodeName = parts[parts.Length - 1];
                    var fullTitleAsPath = "";

                    for (var i = 0; i < parts.Length - 1; i++)
                    {
                        var title = parts[i];
                        fullTitleAsPath += title;
                        level            = i + 1;

                        // 如果节点在子类别中,则添加节标题
                        if (!titlePaths.Contains(fullTitleAsPath))
                        {
                            tree.Add(new SearchTreeGroupEntry(new GUIContent(title))
                            {
                                level = level
                            });
                            titlePaths.Add(fullTitleAsPath);
                        }
                    }
                }

                tree.Add(new SearchTreeEntry(new GUIContent(nodeName))
                {
                    level    = level + 1,
                    userData = nodeType
                });
            }
        }