示例#1
0
        private void DragNodes(List <int> nodes)
        {
            if (Application.isPlaying || nodes.Count <= 0)
            {
                return;
            }

            Vector2 step = GetDragStep();

            // 只有单节点时才允许连带子节点移动
            BTNode tempNode = null;

            if (nodes.Count == 1 && Event.current.shift)
            {
                tempNode = BTEditorManager.GetNodeByID(nodes[0]);
                DragWithChildren(tempNode, step);
            }
            else
            {
                // 只移动选中的节点
                foreach (var nodeID in nodes)
                {
                    tempNode = BTEditorManager.GetNodeByID(nodeID);
                    if (tempNode == null)
                    {
                        continue;
                    }

                    tempNode.editorPosition += step;
                }
            }

            mMouseStartPos += step;
        }
示例#2
0
        void DrawConnectionLine()
        {
            if (mSelectedNodes.Count < 0)
            {
                return;
            }

            BTNode contextNode = BTEditorManager.GetNodeByID(mSelectedNodes[0]);

            if (contextNode == null)
            {
                return;
            }

            Vector3 startPos = Vector3.zero;
            Vector3 startTan = Vector3.zero;
            Vector2 mousePos = Event.current.mousePosition;
            Vector3 endPos   = new Vector3(mousePos.x, mousePos.y, 0);
            Vector3 endTan   = Vector3.zero;

            if (mCurMode == Mode.ConnectParent)
            {
                startPos = new Vector3(contextNode.editorPosition.x + (NodeRenderer.Width / 2), contextNode.editorPosition.y, 0);
                startTan = startPos + Vector3.down * GridRenderer.step.x * 2;
                endTan   = endPos + Vector3.up * GridRenderer.step.x * 2;
            }
            else if (mCurMode == Mode.ConnectChild)
            {
                startPos = new Vector3(contextNode.editorPosition.x + (NodeRenderer.Width / 2), contextNode.editorPosition.y + NodeRenderer.Height, 0);
                startTan = startPos + Vector3.up * GridRenderer.step.x * 2;
                endTan   = endPos + Vector3.down * GridRenderer.step.x * 2;
            }

            Handles.DrawBezier(startPos, endPos, startTan, endTan, Color.white, null, 4);
        }
        public static void Connect(int parentID, int childID)
        {
            BTNode parent = BTEditorManager.GetNodeByID(parentID);
            BTNode child  = BTEditorManager.GetNodeByID(childID);

            if (parent != null && parent.CanConnectChild && child != null)
            {
                parent.ConnectChild(child);
                // SortChildren(parent);
                Dirty();
            }
            else
            {
                Debug.LogWarning(string.Format("{0} can't accept child {1}", parent, child));
            }
        }
示例#4
0
        private void RefreshSelection()
        {
            if (mSelectedNodes == null)
            {
                return;
            }

            int count = mSelectedNodes.Count;

            UnityEngine.Object[] nodeArray = new UnityEngine.Object[count];
            for (int i = 0; i < count; ++i)
            {
                nodeArray[i] = BTEditorManager.GetNodeByID(mSelectedNodes[i]);
            }

            Selection.objects = nodeArray;
        }
示例#5
0
        public void ShowContextMenu(Vector2 mousePos, Vector2 offset, List <int> nodeList)
        {
            if (Application.isPlaying)
            {
                return;
            }

            var menu = new GenericMenu();

            if (nodeList != null && nodeList.Count > 0)
            {
                if (nodeList.Count == 1)
                {
                    BTNode node = BTEditorManager.GetNodeByID(nodeList[0]);

                    // 添加
                    if (node.CanConnectChild)
                    {
                        foreach (var kvp in mAddContextDic)
                        {
                            menu.AddItem(new GUIContent("Add Child/" + kvp.Key), false, Add,
                                         new MenuAction(nodeList, mousePos, kvp.Value));
                        }
                    }
                    else
                    {
                        menu.AddDisabledItem(new GUIContent("Add"));
                    }

                    // Connect/Disconnect Parent
                    menu.AddSeparator("");
                    if (!(node is BaseRoot) && !(node is Root))
                    {
                        if (node.parent != null)
                        {
                            menu.AddItem(new GUIContent("Disconnect from Parent"), false, Unparent, new MenuAction(nodeList));
                        }
                        else
                        {
                            menu.AddItem(new GUIContent("Connect to Parent"), false, ConnectParent, new MenuAction(nodeList));
                        }
                    }

                    // Connect Child
                    menu.AddSeparator("");
                    if (node.CanConnectChild)
                    {
                        menu.AddItem(new GUIContent("Connect to Child"), false, ConnectChild, new MenuAction(nodeList));
                    }
                    else
                    {
                        menu.AddDisabledItem(new GUIContent("Connect to Child"));
                    }

                    // Copy
                    menu.AddSeparator("");
                    menu.AddItem(new GUIContent("Copy"), false, Copy, new MenuAction(nodeList, mousePos));

                    // Delete
                    menu.AddSeparator("");
                    menu.AddItem(new GUIContent("Delete"), false, Delete, new MenuAction(nodeList));
                }
                else
                {
                    // Copy
                    menu.AddSeparator("");
                    menu.AddItem(new GUIContent("Copy"), false, Copy, new MenuAction(nodeList, mousePos));

                    // Delete
                    menu.AddSeparator("");
                    menu.AddItem(new GUIContent("Delete"), false, Delete, new MenuAction(nodeList));
                }
            }
            // 右键点击画布
            else
            {
                // 添加
                foreach (var kvp in mAddContextDic)
                {
                    menu.AddItem(new GUIContent("Add/" + kvp.Key), false, Add,
                                 new MenuAction(nodeList, mousePos, kvp.Value));
                }

                // 粘贴
                menu.AddSeparator("");
                if (BTEditorManager.CopyFromNodes.Count > 0)
                {
                    menu.AddItem(new GUIContent("Paste"), false, Paste,
                                 new MenuAction(null, mousePos));
                }
                else
                {
                    menu.AddDisabledItem(new GUIContent("Paste"));
                }

                // 保存
                menu.AddSeparator("");
                menu.AddItem(new GUIContent("Save"), false, Save, null);
            }

            menu.DropDown(new Rect(mousePos + offset, Vector2.zero));
        }