예제 #1
0
 public void OnNodeDeselect(BTEditorGraphNode node)
 {
     if (m_selection.Remove(node))
     {
         node.OnDeselected();
     }
 }
예제 #2
0
 public void IncreaseEditingDepth(BTEditorGraphNode node)
 {
     if (node != null && (node.Node is NodeGroup || node.Node is Root))
     {
         m_rootStack.Push(node);
     }
 }
예제 #3
0
 public void OnCopyNode(BTEditorGraphNode source)
 {
     if (CanCopy(source))
     {
         BTEditorCanvas.Current.Clipboard = BTUtils.SerializeNode(source.Node);
     }
 }
예제 #4
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);
                }
            }
        }
예제 #5
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);
        }
예제 #6
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);
         }
     }
 }
예제 #7
0
 public UndoNodeMoved(BTEditorGraphNode node)
 {
     m_graph         = node.Graph;
     m_nodeHash      = m_graph.GetNodeHash(node);
     m_startPosition = node.Node.Position;
     m_endPosition   = Vector2.zero;
 }
예제 #8
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;
 }
예제 #9
0
 public void OnNodeDelete(BTEditorGraphNode node)
 {
     if (node != null)
     {
         BTUndoSystem.RegisterUndo(new UndoNodeDeleted(node));
         node.OnDelete();
     }
 }
예제 #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
        public void OnDeleteChild(int index)
        {
            BTEditorGraphNode child = GetChild(index);

            if (child != null)
            {
                child.OnDelete();
            }
        }
예제 #13
0
        private static BTEditorGraphNode CreateEmptyNode()
        {
            BTEditorGraphNode graphNode = ScriptableObject.CreateInstance <BTEditorGraphNode>();

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

            return(graphNode);
        }
예제 #14
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);
            }
        }
예제 #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 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;
        }
예제 #17
0
        public void OnPushNodeGroup(BTEditorGraphNode node)
        {
            if (node != null && node.Node is NodeGroup)
            {
                BTUndoSystem.RegisterUndo(new UndoNodeGroupPush(node));
                m_rootStack.Push(node);

                SelectSingle(node);
            }
        }
예제 #18
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);
        }
예제 #19
0
        private void SelectBranchRecursive(BTEditorGraphNode node)
        {
            m_selection.Add(node);
            node.OnSelected();

            for (int i = 0; i < node.ChildCount; i++)
            {
                SelectBranchRecursive(node.GetChild(i));
            }
        }
예제 #20
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);
         }
     }
 }
예제 #21
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));
         }
     }
 }
예제 #22
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));
         }
     }
 }
예제 #23
0
        public UndoNodeGroupPop(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           = "Close " + (string.IsNullOrEmpty(node.Node.Name) ? node.Node.Title : node.Node.Name);
        }
 private void OnEnable()
 {
     m_graphNode = target as BTEditorGraphNode;
     if (m_graphNode != null)
     {
         m_nodeInspector = BTNodeInspectorFactory.CreateInspectorForNode(m_graphNode);
     }
     else
     {
         m_nodeInspector = null;
     }
 }
예제 #25
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);
         }
     }
 }
예제 #26
0
 private void MoveNonSelectedChildren(BTEditorGraphNode node, Vector2 delta)
 {
     for (int i = 0; i < node.ChildCount; i++)
     {
         var child = node.GetChild(i);
         if (m_selection.IndexOf(child) < 0)
         {
             child.NodePositon = child.NodePositon + delta;
             MoveNonSelectedChildren(child, delta);
         }
     }
 }
예제 #27
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();
            }
        }
예제 #28
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()));
        }
예제 #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;
            }
        }