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());
                    }
                }
            }
        }
Esempio n. 2
0
 void OnPickStay(PickUpAbleItem go)
 {
     if (go is LinkItem)
     {
         LinkUtil.ClearActivedLinkPort(go as LinkItem);
         linkConnectCtrl.TryConnect();
         pickCtrl.PickStay();
     }
 }
Esempio n. 3
0
        void OnMatch(LinkPort itemA, LinkPort itemB)
        {
            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;
            }
        }
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            serializedObject.Update();
            if (GUILayout.Button("Clamp"))
            {
                LinkUtil.Clamp(targetItem.transform);
            }
            DrawLinkPortInfos();
            serializedObject.ApplyModifiedProperties();
        }
 public override void OnUnDoExecute()
 {
     base.OnUnDoExecute();
     if (coroutine != null)
     {
         StopCoroutine(coroutine);
         coroutine = null;
     }
     LinkUtil.DetachConnectedPorts(ConnectedDic, transform);
     ConnectedDic.Clear();
     ResetPositions();
 }
Esempio n. 6
0
 /// <summary>
 /// 放下
 /// </summary>
 /// <param name="obj"></param>
 void OnPickDown(PickUpAbleItem obj)
 {
     if (obj is LinkItem)
     {
         LinkUtil.ClearActivedLinkPort(obj as LinkItem);
         var linkItem = obj as LinkItem;
         if (linkItem)
         {
             linkConnectCtrl.SetDisableItem();
         }
     }
 }
Esempio n. 7
0
 void OnPickUp(PickUpAbleItem obj)
 {
     if (obj is LinkItem)
     {
         linkItem = obj as LinkItem;
         if (linkItem)
         {
             linkConnectCtrl.SetActiveItem(linkItem, false);
             //显示可以所有可以安装的点
             LinkUtil.TryActiveLinkPorts(linkItem);
         }
     }
 }
        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;
            }
        }
Esempio n. 9
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
             });
         }
     }
 }
Esempio n. 10
0
        public bool FindConnectableObject()
        {
            if (pickedUpItem != null)
            {
                LinkPort tempNode;
                foreach (var item in pickedUpItem.ChildNodes)
                {
                    if (LinkUtil.FindInstallableNode(item, out tempNode))
                    {
                        activeNode = item;
                        targetNode = tempNode;
                        return(true);
                    }
                }
            }

            return(false);
        }
Esempio n. 11
0
        public void TryConnect()
        {
            if (activeNode != null && targetNode != null && !targetNode.Body.transform.IsChildOf(activeNode.Body.transform))
            {
                LinkUtil.RecordToDic(ConnectedDic, activeNode);

                LinkUtil.RecordToDic(ConnectedDic, targetNode);

                LinkUtil.AttachNodes(activeNode, targetNode);

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

                activeNode = null;
                targetNode = null;
            }
        }
Esempio n. 12
0
        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);
            }
        }
Esempio n. 13
0
        private IEnumerator AutoLinkItems()
        {
            for (int i = 0; i < defultLink.Count; i++)
            {
                var linkGroup = defultLink[i];

                var portA = linkItems[linkGroup.ItemA].ChildNodes[linkGroup.portA];
                var portB = linkItems[linkGroup.ItemB].ChildNodes[linkGroup.portB];

                angleCtrl.UnNotice(anglePos);
                anglePos = portA.transform;

                yield return(MoveBToA(portA, portB));

                LinkUtil.AttachNodes(portB, portA);
                LinkUtil.RecordToDic(ConnectedDic, portA);
                LinkUtil.RecordToDic(ConnectedDic, portB);
            }

            TryComplete();
        }
Esempio n. 14
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);
                }
            }
        }
 private void DrawToolsButtons()
 {
     using (var hor = new EditorGUILayout.HorizontalScope())
     {
         var style = EditorStyles.toolbarButton;
         if (GUILayout.Button("AutoRecord", style))
         {
             foreach (var item in targetItem.ChildNodes)
             {
                 List <LinkPort> otherPorts;
                 if (LinkUtil.FindTriggerNodes(item, out otherPorts))
                 {
                     for (int i = 0; i < otherPorts.Count; i++)
                     {
                         var otherPort = otherPorts[i];
                         TryRecordConnect(item, otherPort);
                     }
                 }
             }
         }
         if (GUILayout.Button("LoadRecord", style))
         {
             if (Selection.instanceIDs != null && Selection.instanceIDs.Length == 2)
             {
             }
         }
         if (GUILayout.Button("ClampRot", style))
         {
             if (Selection.activeGameObject != null)
             {
                 var selected = Selection.activeGameObject;
                 if (selected == null)
                 {
                     return;
                 }
                 LinkUtil.ClampRotation(selected.transform);
             }
         }
     }
 }
Esempio n. 16
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 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());
            }
        }
        private void InitReorderLists()
        {
            portLists = new ReorderableList[linkPorts.Length];
            for (int i = 0; i < portLists.Length; i++)
            {
                var port = linkPorts[i];
                port.connectAble.Sort();

                portLists[i] = new ReorderableList(port.connectAble, typeof(LinkInfo));
                portLists[i].drawHeaderCallback = (rect) => {
                    var nameRect  = new Rect(rect.x + 15, rect.y, rect.width * 0.4f, EditorGUIUtility.singleLineHeight);
                    var idRect    = new Rect(rect.x + rect.width * 0.4f, rect.y, rect.width * 0.3f, EditorGUIUtility.singleLineHeight);
                    var rangeRect = new Rect(rect.x + rect.width * 0.55f, rect.y, 60, EditorGUIUtility.singleLineHeight);

                    EditorGUI.LabelField(nameRect, string.Format("目标({0}:{1})", port.name, port.NodeID));
                    EditorGUI.LabelField(idRect, "端口");
                    EditorGUI.BeginChangeCheck();
                    port.Range = GUI.HorizontalSlider(rangeRect, port.Range, 0.1f, 2);
                    if (EditorGUI.EndChangeCheck())
                    {
                        port.Range = (float)System.Math.Round(port.Range, 2);
                    }
                    var btnRect = new Rect(rect.x + rect.width - buttonWidth * 2f, rect.y, buttonWidth, EditorGUIUtility.singleLineHeight);

                    if (GUI.Button(btnRect, "Record"))
                    {
                        List <LinkPort> otherPorts;
                        if (LinkUtil.FindTriggerNodes(port, out otherPorts))
                        {
                            if (otherPorts != null && otherPorts.Count > 0)
                            {
                                var window = EditorWindow.GetWindow <LinkWindow>();
                                window.InitPortGroup(port, otherPorts.ToArray());
                            }
                        }
                    }
                    btnRect.x += buttonWidth;
                    if (GUI.Button(btnRect, "Link"))
                    {
                        if (Selection.activeGameObject != null)
                        {
                            var linkport = Selection.activeGameObject.GetComponentInParent <LinkPort>();
                            if (linkport != null)
                            {
                                var linkItem = linkport.GetComponentInParent <LinkItem>();
                                var linkInfo = port.connectAble.Find(x => x.itemName == linkItem.Name && x.nodeId == linkport.NodeID);
                                if (linkInfo != null)
                                {
                                    LinkUtil.ResetTargetTranform(targetItem, linkItem, linkInfo.relativePos, linkInfo.relativeDir);
                                }
                            }
                            else
                            {
                                EditorUtility.DisplayDialog("温馨提示", "请选择目标端口后重试", "确认");
                            }
                        }
                    }
                };
                portLists[i].drawElementCallback = (rect, index, isactive, isfoces) =>
                {
                    var linkInfo = port.connectAble[index];
                    var nameRect = new Rect(rect.x, rect.y, rect.width * 0.3f, EditorGUIUtility.singleLineHeight);
                    EditorGUI.LabelField(nameRect, linkInfo.itemName);
                    var idRect = new Rect(rect.x + rect.width * 0.4f, rect.y, rect.width * 0.3f, EditorGUIUtility.singleLineHeight);
                    EditorGUI.LabelField(idRect, linkInfo.nodeId.ToString());
                    var rangeRect = new Rect(rect.x + rect.width * 0.55f, rect.y, 60, EditorGUIUtility.singleLineHeight);
                    EditorGUI.LabelField(rangeRect, port.Range.ToString());
                };
            }
        }
Esempio n. 18
0
 public void OnTranformChanged(List <LinkItem> context)
 {
     LinkUtil.UpdateBrotherPos(this, context);
 }