Ejemplo n.º 1
0
        public BTEditorGraphNode OnInsertChild(int index, BehaviourNode node)
        {
            if (node != null && ((m_node is Composite) || (m_node is Decorator)))
            {
                BTEditorGraphNode graphNode = null;

                if (m_node is Composite)
                {
                    Composite composite = m_node as Composite;
                    composite.InsertChild(index, node);

                    graphNode = BTEditorGraphNode.CreateExistingNode(this, node);
                    m_children.Insert(index, graphNode);
                }
                else if (m_node is Decorator)
                {
                    Decorator decorator = m_node as Decorator;

                    DestroyChildren();
                    decorator.SetChild(node);

                    graphNode = BTEditorGraphNode.CreateExistingNode(this, node);
                    m_children.Add(graphNode);
                }

                BTEditorCanvas.Current.RecalculateSize(node.Position);
                return(graphNode);
            }

            return(null);
        }
Ejemplo n.º 2
0
 public void IncreaseEditingDepth(BTEditorGraphNode node)
 {
     if (node != null && (node.Node is NodeGroup || node.Node is Root))
     {
         m_rootStack.Push(node);
     }
 }
Ejemplo n.º 3
0
        private void SetExistingNode(BehaviourNode node)
        {
            DestroyChildren();

            m_node       = node;
            m_isSelected = false;

            if (node is Composite)
            {
                Composite composite = node as Composite;
                for (int i = 0; i < composite.ChildCount; i++)
                {
                    BehaviourNode     childNode = composite.GetChild(i);
                    BTEditorGraphNode graphNode = BTEditorGraphNode.CreateExistingNode(this, childNode);
                    m_children.Add(graphNode);
                }
            }
            else if (node is Decorator)
            {
                Decorator     decorator = node as Decorator;
                BehaviourNode childNode = decorator.GetChild();
                if (childNode != null)
                {
                    BTEditorGraphNode graphNode = BTEditorGraphNode.CreateExistingNode(this, childNode);
                    m_children.Add(graphNode);
                }
            }
        }
Ejemplo n.º 4
0
 public void OnNodeSelect(BTEditorGraphNode node)
 {
     if (BTEditorCanvas.Current.Event.shift && (node.Node is Composite || node.Node is Decorator))
     {
         SelectBranch(node);
     }
     else if (BTEditorCanvas.Current.Event.control || SelectionBox.HasValue)
     {
         if (!m_selection.Contains(node))
         {
             if (node.Node is NodeGroup && !IsRoot(node))
             {
                 SelectEntireNodeGroupAdditive(node);
             }
             else
             {
                 SelectSingleAdditive(node);
             }
         }
     }
     else
     {
         if (node.Node is NodeGroup && !IsRoot(node))
         {
             SelectEntireNodeGroup(node);
         }
         else
         {
             SelectSingle(node);
         }
     }
 }
Ejemplo n.º 5
0
 public void OnNodeDeselect(BTEditorGraphNode node)
 {
     if (m_selection.Remove(node))
     {
         node.OnDeselected();
     }
 }
Ejemplo n.º 6
0
 public UndoNodeMoved(BTEditorGraphNode node)
 {
     m_graph         = node.Graph;
     m_nodeHash      = m_graph.GetNodeHash(node);
     m_startPosition = node.Node.Position;
     m_endPosition   = Vector2.zero;
 }
Ejemplo n.º 7
0
 public void OnCopyNode(BTEditorGraphNode source)
 {
     if (CanCopy(source))
     {
         BTEditorCanvas.Current.Clipboard = BTUtils.SerializeNode(source.Node);
     }
 }
Ejemplo n.º 8
0
 public void OnNodeDelete(BTEditorGraphNode node)
 {
     if (node != null)
     {
         BTUndoSystem.RegisterUndo(new UndoNodeDeleted(node));
         node.OnDelete();
     }
 }
Ejemplo n.º 9
0
 public UndoNodeCreated(BTEditorGraphNode node)
 {
     m_graph           = node.Graph;
     m_createdNodeHash = m_graph.GetNodeHash(node);
     m_parentNodeHash  = null;
     m_serializedNode  = null;
     Title             = "Created " + node.Node.Title;
 }
Ejemplo n.º 10
0
 public void OnDelete()
 {
     if (m_parent != null)
     {
         m_parent.RemoveChild(this);
         BTEditorGraphNode.DestroyImmediate(this);
     }
 }
Ejemplo n.º 11
0
 private void OnDestroy()
 {
     m_graph.OnNodeDeselect(this);
     foreach (var child in m_children)
     {
         BTEditorGraphNode.DestroyImmediate(child);
     }
 }
Ejemplo n.º 12
0
        private void OnCopyNode()
        {
            BTEditorGraphNode targetNode = m_graph.GetLastSelectedNode();

            if (targetNode != null)
            {
                m_graph.OnCopyNode(targetNode);
            }
        }
Ejemplo n.º 13
0
        public static void AddChild(GenericMenu menu, BTEditorGraphNode targetNode)
        {
            GenericMenu.MenuFunction2 onCreateChild = t => targetNode.Graph.OnNodeCreateChild(targetNode, t as Type);

            foreach (var item in m_nodeMenuPaths)
            {
                menu.AddItem(new GUIContent(/*"Add Child/" + */ item.Item2), false, onCreateChild, item.Item1);
            }
        }
Ejemplo n.º 14
0
        private static BTEditorGraphNode CreateEmptyNode()
        {
            BTEditorGraphNode graphNode = ScriptableObject.CreateInstance <BTEditorGraphNode>();

            graphNode.OnCreated();
            graphNode.hideFlags = HideFlags.HideAndDontSave;

            return(graphNode);
        }
Ejemplo n.º 15
0
 private void OnCreated()
 {
     m_masterRoot              = null;
     m_rootStack               = new Stack <BTEditorGraphNode>();
     m_drawSelectionBox        = false;
     m_isBehaviourTreeReadOnly = false;
     m_selectionBoxStartPos    = Vector2.zero;
     SelectionBox              = null;
 }
Ejemplo n.º 16
0
        public void OnDeleteChild(int index)
        {
            BTEditorGraphNode child = GetChild(index);

            if (child != null)
            {
                child.OnDelete();
            }
        }
Ejemplo n.º 17
0
        private void SelectBranchRecursive(BTEditorGraphNode node)
        {
            m_selection.Add(node);
            node.OnSelected();

            for (int i = 0; i < node.ChildCount; i++)
            {
                SelectBranchRecursive(node.GetChild(i));
            }
        }
Ejemplo n.º 18
0
 public void OnNodeDrag(BTEditorGraphNode node, Vector2 position)
 {
     if (m_selection.Contains(node))
     {
         for (int i = 0; i < m_selection.Count; i++)
         {
             m_selection[i].OnDrag(position);
         }
     }
 }
Ejemplo n.º 19
0
        private static BTEditorGraphNode CreateExistingNode(BTEditorGraphNode parent, BehaviourNode node)
        {
            BTEditorGraphNode graphNode = BTEditorGraphNode.CreateEmptyNode();

            graphNode.m_parent = parent;
            graphNode.m_graph  = parent.Graph;
            graphNode.SetExistingNode(node);

            return(graphNode);
        }
Ejemplo n.º 20
0
        public UndoNodeDeleted(BTEditorGraphNode node, int childIndex)
        {
            m_graph          = node.Graph;
            m_parentNodeHash = m_graph.GetNodeHash(node.Parent);
            m_serializedNode = BTUtils.SerializeNode(node.Node);
            m_childIndex     = childIndex;
            Title            = "Deleted " + node.Node.Title;

            m_createdNodeHash = null;
        }
Ejemplo n.º 21
0
        public void OnPushNodeGroup(BTEditorGraphNode node)
        {
            if (node != null && node.Node is NodeGroup)
            {
                BTUndoSystem.RegisterUndo(new UndoNodeGroupPush(node));
                m_rootStack.Push(node);

                SelectSingle(node);
            }
        }
Ejemplo n.º 22
0
        public UndoNodeGroupPush(BTEditorGraphNode node)
        {
            if (!(node.Node is NodeGroup))
            {
                throw new System.ArgumentException("BT graph node is not of type NodeGroup", "node");
            }

            m_graph         = node.Graph;
            m_nodeGroupHash = m_graph.GetNodeHash(node);
            Title           = "Open " + node.Node.Title;
        }
Ejemplo n.º 23
0
 private void DeleteBreakpointsRecursive(BTEditorGraphNode node)
 {
     if (node != null && node.Node != null)
     {
         node.Node.Breakpoint = Breakpoint.None;
         for (int i = 0; i < node.ChildCount; i++)
         {
             DeleteBreakpointsRecursive(node.GetChild(i));
         }
     }
 }
Ejemplo n.º 24
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));
         }
     }
 }
Ejemplo n.º 25
0
 private void OnEnable()
 {
     m_graphNode = target as BTEditorGraphNode;
     if (m_graphNode != null)
     {
         m_nodeInspector = BTNodeInspectorFactory.CreateInspectorForNode(m_graphNode);
     }
     else
     {
         m_nodeInspector = null;
     }
 }
Ejemplo n.º 26
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();
            }
        }
Ejemplo n.º 27
0
        public string GetNodeHash(BTEditorGraphNode node)
        {
            List <byte> path = new List <byte>();

            for (BTEditorGraphNode n = node; n != null && n.Parent != null; n = n.Parent)
            {
                path.Add((byte)n.Parent.GetChildIndex(n));
            }
            path.Reverse();

            return(Convert.ToBase64String(path.ToArray()));
        }
Ejemplo n.º 28
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);
         }
     }
 }
Ejemplo n.º 29
0
        public override void Undo()
        {
            if (CanUndo)
            {
                BTEditorGraphNode createdNode = m_graph.GetNodeByHash(m_createdNodeHash);

                m_parentNodeHash = m_graph.GetNodeHash(createdNode.Parent);
                m_serializedNode = BTUtils.SerializeNode(createdNode.Node);

                createdNode.OnDelete();
                m_createdNodeHash = null;
            }
        }
Ejemplo n.º 30
0
        public override void Redo()
        {
            if (CanRedo)
            {
                BTEditorGraphNode parentNode  = m_graph.GetNodeByHash(m_parentNodeHash);
                BehaviourNode     node        = BTUtils.DeserializeNode(m_serializedNode);
                BTEditorGraphNode createdNode = parentNode.OnCreateChild(node);

                m_createdNodeHash = m_graph.GetNodeHash(createdNode);
                m_parentNodeHash  = null;
                m_serializedNode  = null;
            }
        }