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());
                    }
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// 空间查找触发的点
 /// </summary>
 /// <param name="item"></param>
 /// <param name="nodes"></param>
 /// <returns></returns>
 public static bool FindTriggerNodes(LinkPort item, out List <LinkPort> nodes)
 {
     nodes = null;
     Collider[] colliders = Physics.OverlapSphere(item.Pos, item.Range, LayerMask.GetMask(LinkPort.layer));
     if (colliders != null && colliders.Length > 0)
     {
         foreach (var collider in colliders)
         {
             LinkPort tempNode = collider.GetComponentInParent <LinkPort>();
             if (tempNode == null || tempNode == item || tempNode.Body == item.Body)
             {
                 continue;
             }
             else
             {
                 if (nodes == null)
                 {
                     nodes = new List <Actions.LinkPort>();
                 }
                 nodes.Add(tempNode);
             }
         }
     }
     return(nodes != null && nodes.Count > 0);
 }
 public void InitPortGroup(LinkPort port, LinkPort[] otherPorts)
 {
     this.port       = port;
     this.otherPorts = otherPorts;
     selection       = new bool[otherPorts.Length];
     InitReorderList();
 }
        public void Update()
        {
            timer += Time.deltaTime;
            if (pickedUpItem != null && timer > spanTime)
            {
                timer = 0f;

                if (FindConnectableObject())
                {
                    if (onMatch != null)
                    {
                        onMatch(activeNode, targetNode);
                    }
                }
                else
                {
                    if (onDisMatch != null && activeNode != null && targetNode != null)
                    {
                        onDisMatch.Invoke(targetNode, activeNode);
                    }

                    activeNode = null;
                    targetNode = null;
                }
            }
        }
Exemple #5
0
 public static void DetachNodes(LinkPort moveAblePort, LinkPort staticPort)
 {
     if (moveAblePort != null)
     {
         moveAblePort.ConnectedNode = null;
     }
     if (staticPort != null)
     {
         staticPort.ConnectedNode = null;
     }
 }
        public void TryConnect()
        {
            if (activeNode != null && targetNode != null)
            {
                LinkUtil.AttachNodes(activeNode, targetNode);

                if (onConnected != null)
                {
                    onConnected.Invoke(new LinkPort[] { activeNode, targetNode });
                }

                activeNode = null;
                targetNode = null;
            }
        }
        void OnDisMath(LinkPort itemA, LinkPort itemB)
        {
            if (!Active)
            {
                return;
            }

            highter.UnHighLightTarget(itemA.gameObject);
            highter.UnHighLightTarget(itemB.gameObject);

            if (linkItem)
            {
                linkItem.isMatching = false;
            }
        }
Exemple #8
0
        /// <summary>
        /// 判断两个点能否连接
        /// </summary>
        /// <param name="item"></param>
        /// <param name="tempNode"></param>
        /// <returns></returns>
        private static bool JudgeLinkPort(LinkPort item, LinkPort tempNode)
        {
            if (tempNode == null || tempNode == item || tempNode.Body == item.Body || tempNode.ConnectedNode != null)
            {
                return(false);
            }
            //主被动动连接点,非自身点,相同名,没有建立连接
            var linkInfo = item.connectAble.Find((x) => x.itemName == tempNode.Body.Name && x.nodeId == tempNode.NodeID);

            if (linkInfo != null)
            {
                return(true);
            }
            return(false);
        }
Exemple #9
0
        /// <summary>
        /// 空间查找可以可以连接的点
        /// </summary>
        /// <param name="item"></param>
        /// <param name="node"></param>
        /// <returns></returns>
        public static bool FindInstallableNode(LinkPort item, out LinkPort node)
        {
            if (item.ConnectedNode != null)
            {
                node = item.ConnectedNode;
                return(false);
            }
            switch (matchType)
            {
            case MatchType.ColliderRange:
                return(FindInstallableNode_ColliderRange(item, out node));

            case MatchType.WindowPosition:
            default:
                return(FindInstallableNode_WindowPosition(item, out node));
            }
        }
        public bool FindConnectableObject()
        {
            if (pickedUpItem != null)
            {
                LinkPort tempNode;
                foreach (var item in pickedUpItem.GroupNodes)
                {
                    if (LinkUtil.FindInstallableNode(item, out tempNode))
                    {
                        activeNode = item;
                        targetNode = tempNode;
                        return(true);
                    }
                }
            }

            return(false);
        }
        void OnMatch(LinkPort itemA, LinkPort itemB)
        {
            if (!Active)
            {
                return;
            }

            highter.HighLightTarget(itemA.gameObject, Color.green);
            var linkInfo = itemA.connectAble.Find(x => x.itemName == itemB.Body.Name && x.nodeId == itemB.NodeID);

            LinkUtil.ResetTargetTranform(itemA.Body, itemB.Body, linkInfo.relativePos, linkInfo.relativeDir);
            LinkUtil.UpdateBrotherPos(itemA.Body, new List <LinkItem>());

            if (linkItem)
            {
                linkItem.isMatching = true;
            }
        }
Exemple #12
0
 /// <summary>
 /// 按空间坐标的方式查找匹配点
 /// </summary>
 /// <param name="item"></param>
 /// <param name="node"></param>
 /// <returns></returns>
 public static bool FindInstallableNode_ColliderRange(LinkPort item, out LinkPort node)
 {
     Collider[] colliders = Physics.OverlapSphere(item.Pos, item.Range, LayerMask.GetMask(LinkPort.layer));
     if (colliders != null && colliders.Length > 0)
     {
         foreach (var collider in colliders)
         {
             LinkPort tempNode = collider.GetComponentInParent <LinkPort>();
             if (JudgeLinkPort(item, tempNode))
             {
                 node = tempNode;
                 return(true);
             }
         }
     }
     node = null;
     return(false);
 }
        public static void TryRecordConnect(LinkPort node_A, LinkPort node_B)
        {
            if (!node_A || !node_B)
            {
                return;
            }
            LinkItem item_A = node_A.GetComponentInParent <LinkItem>();
            LinkItem item_B = node_B.GetComponentInParent <LinkItem>();

            if (node_A == null || node_B == null || item_A == null || item_B == null)
            {
                return;
            }

            var confer = EditorUtility.DisplayDialog("[connected]", item_A.Name + ":" + (node_A.name) + "<->" + item_B.Name + ":" + (node_B.name), "确认");

            if (confer)
            {
                LinkInfo nodeArecored = node_A.connectAble.Find((x) => x.itemName == item_B.name && x.nodeId == node_B.NodeID);
                LinkInfo nodeBrecored = node_B.connectAble.Find((x) => x.itemName == item_A.name && x.nodeId == node_A.NodeID);
                //已经记录过
                if (nodeArecored == null)
                {
                    nodeArecored = new LinkInfo();
                    node_A.connectAble.Add(nodeArecored);
                }
                if (nodeBrecored == null)
                {
                    nodeBrecored = new LinkInfo();
                    node_B.connectAble.Add(nodeBrecored);
                }

                nodeArecored.itemName = item_B.Name;
                nodeBrecored.itemName = item_A.Name;
                nodeArecored.nodeId   = node_B.NodeID;
                nodeBrecored.nodeId   = node_A.NodeID;
                LinkUtil.RecordTransform(nodeArecored, nodeBrecored, item_A.transform, item_B.transform);
                EditorUtility.SetDirty(node_A);
                EditorUtility.SetDirty(node_B);
            }
        }
Exemple #14
0
        private IEnumerator MoveBToA(LinkPort portA, LinkPort portB)
        {
            //var linkInfoA = portA.connectAble.Find(x => x.itemName == portB.Body.Name);
            var linkInfoB = portB.connectAble.Find(x => x.itemName == portA.Body.Name);

            Vector3 pos;
            Vector3 eular;

            Debug.Assert(linkInfoB != null);

            LinkUtil.GetWorldPosFromTarget(portA.Body, linkInfoB.relativePos, linkInfoB.relativeDir, out pos, out eular);

            var startPos     = portB.Body.transform.position;
            var startforward = portB.Body.transform.forward;

            if (quickLink || autoLinkTime < 0.1f)
            {
                yield return(new WaitForSeconds(autoLinkTime));

                portB.Body.transform.eulerAngles = eular;
                portB.Body.transform.position    = pos;
                LinkUtil.UpdateBrotherPos(portB.Body, new List <LinkItem>());
            }
            else
            {
                var context = new List <LinkItem>();
                for (float j = 0; j < autoLinkTime; j += Time.deltaTime)
                {
                    yield return(null);

                    portB.Body.transform.position    = Vector3.Lerp(startPos, pos, j / autoLinkTime);
                    portB.Body.transform.eulerAngles = Vector3.Lerp(startforward, eular, j / autoLinkTime);
                    context.Clear();
                    LinkUtil.UpdateBrotherPos(portB.Body, context);
                }
            }
        }
Exemple #15
0
        /// <summary>
        /// 按屏幕坐标查找匹配点
        /// </summary>
        /// <param name="item"></param>
        /// <param name="node"></param>
        /// <returns></returns>
        public static bool FindInstallableNode_WindowPosition(LinkPort item, out LinkPort node)
        {
            var linkPosts = SelectPorts(CameraController.Instence.currentCamera.transform.position, item.Pos, item.Range);

            if (linkPosts == null || linkPosts.Length == 0)
            {
                node = null;
                return(false);
            }
            else
            {
                for (int i = 0; i < linkPosts.Length; i++)
                {
                    LinkPort tempNode = linkPosts[i];
                    if (JudgeLinkPort(item, tempNode))
                    {
                        node = tempNode;
                        return(true);
                    }
                }
                node = null;
                return(false);
            }
        }
 public void SetDisableItem()
 {
     pickedUpItem = null;
     targetNode   = null;
     activeNode   = null;
 }
Exemple #17
0
 public static void AttachNodes(LinkPort moveAblePort, LinkPort staticPort)
 {
     moveAblePort.ConnectedNode = staticPort;
     staticPort.ConnectedNode   = moveAblePort;
     moveAblePort.ResetTransform();
 }