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="linkItem"></param>
 public static void ClearActivedLinkPort(LinkItem linkItem)
 {
     if (log)
     {
         Debug.Log("清除所有" + linkItem + "的拷贝");
     }
     previewCtrl.UnNotice(linkItem.Body);
 }
Exemple #3
0
        public static void ResetTargetTranform(LinkItem target, LinkItem otherParent, Vector3 rPos, Vector3 rdDir)
        {
            var parent = target.Trans.parent;

            target.Trans.SetParent(otherParent.Trans);
            //当target作为otherParent子物体并移开的坐标
            target.Trans.localPosition    = rPos;
            target.Trans.localEulerAngles = rdDir;
            target.Trans.SetParent(parent);
        }
        /// <summary>
        /// 判断是否已经连接过了
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        private bool HaveConnected(LinkItem item)
        {
            bool connected = false;

            foreach (var child in item.ChildNodes)
            {
                connected |= (child.ConnectedNode != null);
            }
            return(connected);
        }
Exemple #5
0
        public static void GetWorldPosFromTarget(LinkItem target, Vector3 rPos, Vector3 rdDir, out Vector3 position, out Vector3 dir)
        {
            var temp = new GameObject("temp");

            temp.transform.SetParent(target.transform);
            temp.transform.localPosition    = rPos;
            temp.transform.localEulerAngles = rdDir;

            position = temp.transform.position;
            dir      = temp.transform.eulerAngles;
            UnityEngine.Object.Destroy(temp);
        }
        private void RetiveNodes(List <LinkItem> context, LinkItem linkItem)
        {
            context.Add(linkItem);
            _groupNodes.AddRange(linkItem.ChildNodes);

            foreach (var item in linkItem.ChildNodes)
            {
                if (item.ConnectedNode != null && !context.Contains(item.ConnectedNode.Body))
                {
                    RetiveNodes(context, item.ConnectedNode.Body);
                }
            }
        }
Exemple #7
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);
        }
        private void OnPickTwinceRight(PickUpAbleComponent obj)
        {
            if (!Active)
            {
                return;
            }

            var item = obj.GetComponentInParent <LinkItem>();

            if (item)
            {
                ElementController.Instence.ClearExtraCreated();
            }

            linkItem = null;
        }
        void OnPickStay(PickUpAbleComponent obj)
        {
            if (!Active)
            {
                return;
            }

            var item = obj.GetComponentInParent <LinkItem>();

            if (item)
            {
                LinkUtil.ClearActivedLinkPort(item);
                linkConnectCtrl.TryConnect();
                pickCtrl.PickStay();
            }

            linkItem = null;
        }
        /// <summary>
        /// 解除连接
        /// </summary>
        /// <param name="obj"></param>
        void OnPickTwinceLeft(PickUpAbleComponent obj)
        {
            if (!Active)
            {
                return;
            }

            var item = obj.GetComponentInParent <LinkItem>();

            if (item)
            {
                this.linkItem = item;
                if (linkItem && !linkItem.Used)
                {
                    linkConnectCtrl.SetActiveItem(linkItem, true);
                }
            }
        }
Exemple #11
0
        /// <summary>
        /// 激活匹配点
        /// </summary>
        /// <param name="pickedUp"></param>
        public static void TryActiveLinkPorts(LinkItem pickedUp)
        {
            var linkItems = GameObject.FindObjectsOfType <LinkItem>();
            var linkPorts = new List <PreviewSet>();

            for (int i = 0; i < pickedUp.ChildNodes.Count; i++)
            {
                var node = pickedUp.ChildNodes[i];
                if (node.ConnectedNode == null && node.connectAble.Count > 0)
                {
                    for (int j = 0; j < node.connectAble.Count; j++)
                    {
                        var info = node.connectAble[j];

                        var otheritems = (from x in linkItems
                                          where (x != null && x != pickedUp && x.Name == info.itemName)
                                          where !HaveConnected(pickedUp, x)
                                          select x);
                        Debug.Assert(otheritems != null && otheritems.Count() > 0);
                        foreach (var otheritem in otheritems)
                        {
                            if (otheritem != null)
                            {
                                var otherNode = otheritem.ChildNodes[info.nodeId];
                                if (otherNode != null && otherNode.ConnectedNode == null)
                                {
                                    if (log)
                                    {
                                        Debug.Log("在" + otheritem + "的" + info.nodeId + "端口上显示出 + " + pickedUp);
                                    }
                                    var set = new PreviewSet();
                                    LinkUtil.GetWorldPosFromTarget(otheritem, info.relativePos, info.relativeDir, out set.position, out set.eulerAngle);
                                    linkPorts.Add(set);
                                }
                            }
                        }
                    }
                }
            }
            if (linkPorts.Count > 0)
            {
                previewCtrl.Notice(pickedUp.Body, linkPorts.ToArray());
            }
        }
        /// <summary>
        /// 放下
        /// </summary>
        /// <param name="obj"></param>
        void OnPickDown(PickUpAbleComponent obj)
        {
            if (!Active)
            {
                return;
            }

            var item = obj.GetComponentInParent <LinkItem>();

            if (item)
            {
                LinkUtil.ClearActivedLinkPort(linkItem);
                if (linkItem)
                {
                    linkConnectCtrl.SetDisableItem();
                }
            }
            this.linkItem = null;
        }
        void OnPickUp(PickUpAbleComponent obj)
        {
            if (!Active)
            {
                return;
            }

            var item = obj.GetComponentInParent <LinkItem>();

            if (item)
            {
                this.linkItem = item;
                if (linkItem)
                {
                    linkConnectCtrl.SetActiveItem(linkItem, false);
                    //显示可以所有可以安装的点
                    LinkUtil.TryActiveLinkPorts(linkItem);
                }
            }
        }
        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 #15
0
        public static void UpdateBrotherPos(LinkItem target, List <LinkItem> context)
        {
            if (target.ChildNodes == null || target.ChildNodes.Count == 0)
            {
                return;
            }

            context.Add(target);

            foreach (var item in target.ChildNodes)
            {
                if (item.ConnectedNode != null && !context.Contains(item.ConnectedNode.Body))
                {
                    var targetNode = item.ConnectedNode.Body;
                    var linkInfo   = item.ConnectedNode.connectAble.Find(x => x.itemName == target.Name && x.nodeId == item.NodeID);

                    LinkUtil.ResetTargetTranform(targetNode, target, linkInfo.relativePos, linkInfo.relativeDir);
                    UpdateBrotherPos(targetNode, context);
                }
            }
        }
 public void SetDisableItem()
 {
     pickedUpItem = null;
     targetNode   = null;
     activeNode   = null;
 }