コード例 #1
0
ファイル: BTEditorGraph.cs プロジェクト: woojehyun/Brainiac
 public void OnNodeDelete(BTEditorGraphNode node)
 {
     if (node != null)
     {
         BTUndoSystem.RegisterUndo(new UndoNodeDeleted(node));
         node.OnDelete();
     }
 }
コード例 #2
0
ファイル: BTEditorGraph.cs プロジェクト: woojehyun/Brainiac
        public void OnPopNodeGroup()
        {
            if (m_rootStack.Count > 1)
            {
                var oldWorkingRoot = m_rootStack.Pop();

                SelectEntireNodeGroup(oldWorkingRoot);
                BTUndoSystem.RegisterUndo(new UndoNodeGroupPop(oldWorkingRoot));
            }
        }
コード例 #3
0
ファイル: BTEditorGraph.cs プロジェクト: woojehyun/Brainiac
        public void OnPushNodeGroup(BTEditorGraphNode node)
        {
            if (node != null && node.Node is NodeGroup)
            {
                BTUndoSystem.RegisterUndo(new UndoNodeGroupPush(node));
                m_rootStack.Push(node);

                SelectSingle(node);
            }
        }
コード例 #4
0
ファイル: BTEditorGraph.cs プロジェクト: woojehyun/Brainiac
 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));
         }
     }
 }
コード例 #5
0
ファイル: BTEditorGraph.cs プロジェクト: woojehyun/Brainiac
        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();
            }
        }
コード例 #6
0
ファイル: BTEditorGraph.cs プロジェクト: woojehyun/Brainiac
 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);
         }
     }
 }
コード例 #7
0
ファイル: BTEditorGraph.cs プロジェクト: woojehyun/Brainiac
        public void SetBehaviourTree(BehaviourTree 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();
        }
コード例 #8
0
ファイル: BTEditorGraph.cs プロジェクト: woojehyun/Brainiac
 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();
     }
 }
コード例 #9
0
ファイル: BTEditorGraph.cs プロジェクト: woojehyun/Brainiac
        public void OnNodeSwitchType(BTEditorGraphNode target, Type newType)
        {
            if (target == null || newType == null)
            {
                return;
            }

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

            BehaviourNode node = BTUtils.CreateNode(newType);

            if (node != null)
            {
                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.NodePositon = oldPosition;
                    BTUndoSystem.RegisterUndo(new UndoNodeCreated(newNode));
                }

                BTUndoSystem.EndUndoGroup();
            }
        }
コード例 #10
0
ファイル: BTEditorGraph.cs プロジェクト: woojehyun/Brainiac
        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);
                }
            }
        }
コード例 #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);
        }