/// <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()); } }
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); } } }