Пример #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);
        }
Пример #2
0
 public void IncreaseEditingDepth(BTEditorGraphNode node)
 {
     if (node != null && (node.Node is NodeGroup || node.Node is Root))
     {
         m_rootStack.Push(node);
     }
 }
Пример #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);
                }
            }
        }
Пример #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);
         }
     }
 }
Пример #5
0
 public void OnNodeDeselect(BTEditorGraphNode node)
 {
     if (m_selection.Remove(node))
     {
         node.OnDeselected();
     }
 }
Пример #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;
 }
Пример #7
0
 public void OnCopyNode(BTEditorGraphNode source)
 {
     if (CanCopy(source))
     {
         BTEditorCanvas.Current.Clipboard = BTUtils.SerializeNode(source.Node);
     }
 }
Пример #8
0
 public void OnNodeDelete(BTEditorGraphNode node)
 {
     if (node != null)
     {
         BTUndoSystem.RegisterUndo(new UndoNodeDeleted(node));
         node.OnDelete();
     }
 }
Пример #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;
 }
Пример #10
0
 public void OnDelete()
 {
     if (m_parent != null)
     {
         m_parent.RemoveChild(this);
         BTEditorGraphNode.DestroyImmediate(this);
     }
 }
Пример #11
0
 private void OnDestroy()
 {
     m_graph.OnNodeDeselect(this);
     foreach (var child in m_children)
     {
         BTEditorGraphNode.DestroyImmediate(child);
     }
 }
Пример #12
0
        private void OnCopyNode()
        {
            BTEditorGraphNode targetNode = m_graph.GetLastSelectedNode();

            if (targetNode != null)
            {
                m_graph.OnCopyNode(targetNode);
            }
        }
Пример #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);
            }
        }
Пример #14
0
        private static BTEditorGraphNode CreateEmptyNode()
        {
            BTEditorGraphNode graphNode = ScriptableObject.CreateInstance <BTEditorGraphNode>();

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

            return(graphNode);
        }
Пример #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;
 }
Пример #16
0
        public void OnDeleteChild(int index)
        {
            BTEditorGraphNode child = GetChild(index);

            if (child != null)
            {
                child.OnDelete();
            }
        }
Пример #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));
            }
        }
Пример #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);
         }
     }
 }
Пример #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);
        }
Пример #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;
        }
Пример #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);
            }
        }
Пример #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;
        }
Пример #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));
         }
     }
 }
Пример #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));
         }
     }
 }
Пример #25
0
 private void OnEnable()
 {
     m_graphNode = target as BTEditorGraphNode;
     if (m_graphNode != null)
     {
         m_nodeInspector = BTNodeInspectorFactory.CreateInspectorForNode(m_graphNode);
     }
     else
     {
         m_nodeInspector = null;
     }
 }
Пример #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();
            }
        }
Пример #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()));
        }
Пример #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);
         }
     }
 }
Пример #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;
            }
        }
Пример #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;
            }
        }