Exemplo n.º 1
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;
            }
        }
Exemplo n.º 2
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
             });
         }
     }
 }
Exemplo n.º 3
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);
                }
            }
        }
Exemplo n.º 4
0
        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());
                };
            }
        }