Example #1
0
 public void OnNodeDelete(BTEditorGraphNode node)
 {
     if (node != null)
     {
         BTUndoSystem.RegisterUndo(new UndoNodeDeleted(node));
         node.OnDelete();
     }
 }
Example #2
0
        public void OnPopNodeGroup()
        {
            if (m_rootStack.Count > 1)
            {
                var oldWorkingRoot = m_rootStack.Pop();

                SelectEntireNodeGroup(oldWorkingRoot);
                BTUndoSystem.RegisterUndo(new UndoNodeGroupPop(oldWorkingRoot));
            }
        }
Example #3
0
        public void OnPushNodeGroup(BTEditorGraphNode node)
        {
            if (node != null && node.Node is NodeGroup)
            {
                BTUndoSystem.RegisterUndo(new UndoNodeGroupPush(node));
                m_rootStack.Push(node);

                SelectSingle(node);
            }
        }
Example #4
0
 public void OnNodeCreateChild(BTEditorGraphNode parent, Type childType)
 {
     if (parent != null && childType != null)
     {
         BTEditorGraphNode child = parent.OnCreateChild(childType);
         if (child != null)
         {
             BTUndoSystem.RegisterUndo(new UndoNodeCreated(child));
         }
     }
 }
Example #5
0
        public void OnNodeEndDrag(BTEditorGraphNode node)
        {
            if (m_selection.Contains(node))
            {
                for (int i = 0; i < m_selection.Count; i++)
                {
                    m_selection[i].OnEndDrag();
                }

                BTUndoSystem.EndUndoGroup();
            }
        }
Example #6
0
 public void OnNodeBeginDrag(BTEditorGraphNode node, Vector2 position)
 {
     if (m_selection.Contains(node))
     {
         BTUndoSystem.BeginUndoGroup("Moved node(s)");
         for (int i = 0; i < m_selection.Count; i++)
         {
             BTUndoSystem.RegisterUndo(new UndoNodeMoved(m_selection[i]));
             m_selection[i].OnBeginDrag(position);
         }
     }
 }
Example #7
0
        public void OnNodeSwitchType(BTEditorGraphNode target, Type newType)
        {
            if (target == null || newType == null)
            {
                return;
            }

            BTEditorGraphNode parentNode  = target.Parent;
            Vector2           oldPosition = target.NodePosition;
            int oldIndex = target.Parent.GetChildIndex(target);

            BehaviourNode node = BTUtils.CreateNode(newType);

            if (node != null)
            {
                node.Constraints.AddRange(target.Node.Constraints);

                if (node is Decorator)
                {
                    Decorator original  = target.Node as Decorator;
                    Decorator decorator = node as Decorator;

                    decorator.SetChild(original.GetChild());
                }
                else if (node is Composite)
                {
                    Composite original  = target.Node as Composite;
                    Composite composite = node as Composite;

                    for (int i = 0; i < original.ChildCount; i++)
                    {
                        composite.AddChild(original.GetChild(i));
                    }
                }

                BTUndoSystem.BeginUndoGroup("Changed node type");
                BTUndoSystem.RegisterUndo(new UndoNodeDeleted(target));
                target.OnDelete();

                BTEditorGraphNode newNode = parentNode.OnInsertChild(oldIndex, node);
                if (newNode != null)
                {
                    newNode.NodePosition = oldPosition;
                    BTUndoSystem.RegisterUndo(new UndoNodeCreated(newNode));
                }

                BTUndoSystem.EndUndoGroup();
            }
        }
Example #8
0
 public void OnNodeDeleteChildren(BTEditorGraphNode node)
 {
     if (node != null)
     {
         BTUndoSystem.BeginUndoGroup("Delete children");
         int childIndex = 0;
         while (node.ChildCount > 0)
         {
             BTUndoSystem.RegisterUndo(new UndoNodeDeleted(node.GetChild(0), childIndex));
             node.OnDeleteChild(0);
             childIndex++;
         }
         BTUndoSystem.EndUndoGroup();
     }
 }
Example #9
0
        public void SetBehaviourTree(BTAsset asset, BehaviourTree behaviourTree)
        {
            this.m_asset   = asset;
            this.m_bevTree = behaviourTree;

            if (m_masterRoot != null)
            {
                BTEditorGraphNode.DestroyImmediate(m_masterRoot);
                m_masterRoot = null;
                m_rootStack.Clear();
            }

            m_isBehaviourTreeReadOnly = behaviourTree.ReadOnly;
            m_masterRoot = BTEditorGraphNode.CreateRoot(this, behaviourTree.Root);
            m_rootStack.Push(m_masterRoot);
            BTUndoSystem.Clear();
        }
Example #10
0
        public void OnPasteNode(BTEditorGraphNode destination)
        {
            if (CanPaste(destination))
            {
                BehaviourNode     node  = BTUtils.DeserializeNode(BTEditorCanvas.Current.Clipboard);
                BTEditorGraphNode child = destination.OnCreateChild(node);
                if (child != null)
                {
                    SelectBranch(child);

                    var undoState = new UndoNodeCreated(child);
                    undoState.Title = "Pasted " + child.Node.Title;

                    BTUndoSystem.RegisterUndo(undoState);
                }
            }
        }
Example #11
0
        public static GenericMenu CreateGraphContextMenu(BTEditorGraph graph)
        {
            GenericMenu menu = new GenericMenu();

            if (BTUndoSystem.CanUndo && !graph.ReadOnly)
            {
                BTUndoState topUndo = BTUndoSystem.PeekUndo();
                menu.AddItem(new GUIContent(string.Format("Undo \"{0}\"", topUndo.Title)), false, () => BTUndoSystem.Undo());
            }
            else
            {
                menu.AddDisabledItem(new GUIContent("Undo"));
            }

            if (BTUndoSystem.CanRedo && !graph.ReadOnly)
            {
                BTUndoState topRedo = BTUndoSystem.PeekRedo();
                menu.AddItem(new GUIContent(string.Format("Redo \"{0}\"", topRedo.Title)), false, () => BTUndoSystem.Redo());
            }
            else
            {
                menu.AddDisabledItem(new GUIContent("Redo"));
            }

            menu.AddSeparator("");

            if (!graph.ReadOnly)
            {
                menu.AddItem(new GUIContent("Select All"), false, () => graph.SelectEntireGraph());
            }
            else
            {
                menu.AddDisabledItem(new GUIContent("Select All"));
            }

            menu.AddItem(new GUIContent("Delete All Breakpoints"), false, () => graph.DeleteAllBreakpoints());

            return(menu);
        }