public void SetActiveItem(LinkItem item, bool detach)
        {
            this.pickedUpItem = item;

            ///如果目标已经被使用,阻止和其他元素断开
            if (item.Used)
            {
                List <LinkPort> disconnected  = new List <LinkPort>();
                LinkPort[]      connectedPort = item.GetLinkedPorts();

                if (detach)
                {
                    for (int i = 0; i < connectedPort.Length; i++)
                    {
                        LinkPort port      = connectedPort[i];
                        LinkPort otherPort = port.ConnectedNode;

                        LinkUtil.DetachNodes(port, otherPort);
                        disconnected.Add(port);
                        disconnected.Add(otherPort);
                    }

                    if (onDisconnected != null)
                    {
                        onDisconnected.Invoke(disconnected.ToArray());
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 判断两个物体是否已经连接
        /// </summary>
        /// <param name="linkItemA"></param>
        /// <param name="linkItemB"></param>
        /// <returns></returns>
        public static bool HaveConnected(LinkItem linkItemA, LinkItem linkItemB)
        {
            var connectedPorts = from port in linkItemA.GetLinkedPorts()
                                 select port.ConnectedNode;

            foreach (var item in linkItemB.GetLinkedPorts())
            {
                if (connectedPorts.Contains(item))
                {
                    return(true);
                }
            }
            return(false);
        }