Beispiel #1
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);
         }
     }
 }
Beispiel #2
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();
     }
 }
Beispiel #3
0
        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();
            }
        }