public override void UnDoChanges(UnityEngine.Object target)
        {
            base.UnDoChanges(target);
            mousePosCatch      = transform.position = startPos;
            transform.rotation = startRot;

            foreach (var item in ChildNodes)
            {
                LinkUtil.DetachNodes(item, item.ConnectedNode);
            }
        }
        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;
            }
        }
Beispiel #3
0
 public void ResetTransform()
 {
     if (ConnectedNode != null)
     {
         LinkInfo connect = connectAble.Find(x => { return(x.itemName == ConnectedNode.Body.Name && x.nodeId == ConnectedNode.NodeID); });
         if (connect != null)
         {
             LinkUtil.ResetTargetTranform(Body, ConnectedNode.Body, connect.relativePos, connect.relativeDir);
             Body.OnTranformChanged(new List <LinkItem>()
             {
                 ConnectedNode.Body
             });
         }
     }
 }
        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;
            }
        }
        void OnPickStay(PickUpAbleComponent obj)
        {
            if (!Active)
            {
                return;
            }

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

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

            linkItem = null;
        }
Beispiel #7
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);
            }
        }
Beispiel #11
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);
                }
            }
        }
Beispiel #12
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);
                }
            }
        }
 public void OnTranformChanged(List <LinkItem> context)
 {
     LinkUtil.UpdateBrotherPos(this, context);
 }