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());
                    }
                }
            }
        }
        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);
        }
 /// <summary>
 /// 解除连接
 /// </summary>
 /// <param name="obj"></param>
 void OnPickTwinceLeft(PickUpAbleItem obj)
 {
     if (obj is LinkItem)
     {
         linkItem = obj as LinkItem;
         if (linkItem && !linkItem.Used)
         {
             linkConnectCtrl.SetActiveItem(linkItem, true);
         }
     }
 }
        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);
                }
            }
        }
 void OnPickUp(PickUpAbleItem obj)
 {
     if (obj is LinkItem)
     {
         linkItem = obj as LinkItem;
         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);
            }
        }
        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);
                }
            }
        }
        /// <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 otheritem = (from x in linkItems
                                         where (x != null && x != pickedUp && x.Name == info.itemName)
                                         select x).FirstOrDefault();

                        if (otheritem != null)
                        {
                            var otherNode = otheritem.ChildNodes[info.nodeId];
                            if (otherNode != null && otherNode.ConnectedNode == null)
                            {
                                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="linkItem"></param>
 public static void ClearActivedLinkPort(LinkItem linkItem)
 {
     Debug.Log("清除所有" + linkItem + "的拷贝");
     previewCtrl.UnNotice(linkItem.Body);
 }
Example #12
0
 private void OnEnable()
 {
     targetItem = target as LinkItem;
     linkPorts  = targetItem.ChildNodes.ToArray();
     InitReorderLists();
 }
 public void SetDisableItem()
 {
     pickedUpItem = null;
     targetNode   = null;
     activeNode   = null;
 }