コード例 #1
0
        public static GenericMenu CreateNodeInspectorContextMenu(BehaviourNode targetNode)
        {
            GenericMenu menu = new GenericMenu();

            BTConstraintFactory.AddConstraint(menu, targetNode);
            //BTServiceFactory.AddService(menu, targetNode);

            return(menu);
        }
コード例 #2
0
        public static GenericMenu CreateNodeContextMenu(BTEditorGraphNode targetNode)
        {
            GenericMenu menu        = new GenericMenu();
            bool        canAddChild = false;

            if (targetNode.Node is Composite)
            {
                canAddChild = true;
            }
            else if (targetNode.Node is NodeGroup)
            {
                canAddChild = ((NodeGroup)targetNode.Node).GetChild() == null && targetNode.IsRoot;
            }
            else if (targetNode.Node is Decorator)
            {
                canAddChild = ((Decorator)targetNode.Node).GetChild() == null;
            }

            if (!targetNode.Graph.ReadOnly)
            {
                if (canAddChild)
                {
                    BTNodeFactory.AddChild(menu, targetNode);
                }

                BTConstraintFactory.AddConstraint(menu, targetNode.Node);

                if (!(targetNode.Node is NodeGroup))
                {
                    BTNodeFactory.SwitchType(menu, targetNode);
                }

                if (canAddChild || !(targetNode.Node is NodeGroup))
                {
                    menu.AddSeparator("");
                }

                if (targetNode.IsRoot)
                {
                    menu.AddDisabledItem(new GUIContent("Copy"));
                    menu.AddDisabledItem(new GUIContent("Cut"));
                }
                else
                {
                    menu.AddItem(new GUIContent("Copy"), false, () => targetNode.Graph.OnCopyNode(targetNode));
                    menu.AddItem(new GUIContent("Cut"), false, () =>
                    {
                        targetNode.Graph.OnCopyNode(targetNode);
                        targetNode.Graph.OnNodeDelete(targetNode);
                    });
                }

                if (targetNode.Graph.CanPaste(targetNode))
                {
                    menu.AddItem(new GUIContent("Paste"), false, () => targetNode.Graph.OnPasteNode(targetNode));
                }
                else
                {
                    menu.AddDisabledItem(new GUIContent("Paste"));
                }

                if (targetNode.IsRoot)
                {
                    menu.AddDisabledItem(new GUIContent("Delete"));
                }
                else
                {
                    menu.AddItem(new GUIContent("Delete"), false, () => targetNode.Graph.OnNodeDelete(targetNode));
                }

                if (targetNode.Node is Composite)
                {
                    if (((Composite)targetNode.Node).ChildCount > 0)
                    {
                        menu.AddItem(new GUIContent("Delete Children"), false, () => targetNode.Graph.OnNodeDeleteChildren(targetNode));
                    }
                    else
                    {
                        menu.AddDisabledItem(new GUIContent("Delete Children"));
                    }
                }
                else if (targetNode.Node is NodeGroup)
                {
                    if (targetNode.IsRoot)
                    {
                        if (((NodeGroup)targetNode.Node).GetChild() != null)
                        {
                            menu.AddItem(new GUIContent("Delete Child"), false, () => targetNode.Graph.OnNodeDeleteChildren(targetNode));
                        }
                        else
                        {
                            menu.AddDisabledItem(new GUIContent("Delete Child"));
                        }
                    }
                }
                else if (targetNode.Node is Decorator)
                {
                    if (((Decorator)targetNode.Node).GetChild() != null)
                    {
                        menu.AddItem(new GUIContent("Delete Child"), false, () => targetNode.Graph.OnNodeDeleteChildren(targetNode));
                    }
                    else
                    {
                        menu.AddDisabledItem(new GUIContent("Delete Child"));
                    }
                }

                menu.AddSeparator("");
            }

            foreach (Breakpoint item in Enum.GetValues(typeof(Breakpoint)))
            {
                menu.AddItem(new GUIContent("Breakpoint/" + item.ToString()), targetNode.Node.Breakpoint.Has(item), (obj) =>
                {
                    Breakpoint option = (Breakpoint)obj;
                    if (option == Breakpoint.None)
                    {
                        targetNode.Node.Breakpoint = Breakpoint.None;
                    }
                    else
                    {
                        if (targetNode.Node.Breakpoint.Has(option))
                        {
                            targetNode.Node.Breakpoint = targetNode.Node.Breakpoint.Remove(option);
                        }
                        else
                        {
                            if (targetNode.Node.Breakpoint == Breakpoint.None)
                            {
                                targetNode.Node.Breakpoint = option;
                            }
                            else
                            {
                                targetNode.Node.Breakpoint = targetNode.Node.Breakpoint.Add(option);
                            }
                        }
                    }
                }, item);
            }

            return(menu);
        }