public BTConditionEvaluator (BTLogic logicOpt, bool reevaluateEveryTick, ClearChildOpt clearOpt, BTNode child = null) : base (child) { this._conditionals = new List<BTConditional>(); this._conditionalInverts = new List<bool>(); this.logicOpt = logicOpt; this.reevaludateEveryTick = reevaluateEveryTick; this.clearOpt = clearOpt; }
public void AddChild(BTNode node, bool selectForClear) { AddChild(node); if (selectForClear) { selectedChildrenForClear.Add(node); } }
public override void Clear () { if (_activeChild != null) { _activeChild.Clear(); _activeChild = null; } }
public virtual void AddChild (BTNode aNode) { if (_children == null) { _children = new List<BTNode>(); } if (aNode != null) { _children.Add(aNode); } }
void Start() { _root = Init(); if (_root.name == null) { _root.name = "Root"; } _root.Activate(_database); }
public void SetPrimaryChild (BTNode node, bool selectForClear = false) { if (_primaryChild != null) { selectedChildrenForClear.Remove(_primaryChild); } _primaryChild = node; if (selectForClear) { selectedChildrenForClear.Add(_primaryChild); } }
public override void Clear () { if (_activeChild != null) { _activeChild = null; _activeIndex = -1; } foreach (BTNode child in children) { child.Clear(); } }
public override BTResult Tick () { if (_activeChild == null) { return BTResult.Ended; } BTResult result = _activeChild.Tick(); if (result != BTResult.Running) { _activeChild.Clear(); _activeChild = null; } return result; }
protected override bool DoEvaluate () { if (_activeChild != null) { bool result = _activeChild.Evaluate(); if (!result) { _activeChild.Clear(); _activeChild = null; _activeIndex = -1; } return result; } else { return children[0].Evaluate(); } }
// selects the active child protected override bool DoEvaluate () { foreach (BTNode child in children) { if (child.Evaluate()) { if (_activeChild != null && _activeChild != child) { _activeChild.Clear(); } _activeChild = child; return true; } } if (_activeChild != null) { _activeChild.Clear(); _activeChild = null; } return false; }
public override BTResult Tick () { // first time if (_activeChild == null) { _activeChild = children[0]; _activeIndex = 0; } BTResult result = _activeChild.Tick(); if (result == BTResult.Ended) { // Current active node over _activeIndex++; if (_activeIndex >= children.Count) { // sequence is over _activeChild.Clear(); _activeChild = null; _activeIndex = -1; } else { // next node _activeChild.Clear(); _activeChild = children[_activeIndex]; result = BTResult.Running; } } return result; }
public override void RemoveChild(BTNode aNode) { Debug.LogError("BTAction: Cannot remove a node into BTAction."); }
public override void AddChild(BTNode aNode) { base.AddChild(aNode); _activeList.Add(false); }
protected BTNodeType(BTNode node) { BelongNode = node; }
public Composite(BTNode node) : base(node) { }
public override void AddChild (BTNode aNode) { base.AddChild (aNode); _activeList.Add(false); }
Type CreateNodeTypeDropdown( BTNode node ) { int selectedType = ( node != null ? Array.IndexOf<Type>( nodeTypes, node.GetType() ) : Array.IndexOf<Type>( nodeTypes, typeof( BTActionBlank ) ) ); Rect rect = new Rect( 0, 0, _nodeWidth - 40.0f, 20.0f ); selectedType = EditorGUI.Popup( rect, selectedType, nodeTypeNames ); return nodeTypes[selectedType]; }
public void AddChild(BTNode pChild) { pChild.mParent = this; this.mChildren.Add(pChild); }
public BTTimer(float interval, BTNode child) : base(child) { this.mInterval = interval; }
public void AddOrphanNode(BTNode node) { OrphanNodeDict.Add(node.Guid, node); }
public void RemoveNode(BTNode node) { BTNodeDict.Remove(node.Guid); }
public void AddNode(BTNode node) { BTNodeDict.Add(node.Guid, node); }
public BTRepeater(bool endOnFailure, BTNode child = null) : this(0, true, endOnFailure, child) { }
public BTInverter(BTNode child) : base(child) { }
public virtual void RemoveChild (BTNode aNode) { if (_children != null && aNode != null) { _children.Remove(aNode); } }
public void DelChild(BTNode pChild) { this.mChildren.Remove(pChild); }
void DeleteNode( BTNode node, bool deleteEditorData = true ) { if ( node is BTDecorator && ( (BTDecorator)node ).child ) { DeleteNode( ( (BTDecorator)node ).child ); } else if ( node is BTComposite && ( (BTComposite)node ).children != null ) { foreach ( BTNode child in ( (BTComposite)node ).children ) { DeleteNode( child ); } } if ( deleteEditorData ) { // Remove the editor data from the list held by the behavior tree. _behaviorTree._editorData.Remove( _editorData[node.id] ); // Remove the data from the local dict. _editorData.Remove( node.id ); } DestroyImmediate( node, true ); }
public void RemoveChild(BTNode node) { ChildNodes.Remove(node); }
public BTRepeater(int count, bool endOnFailure, BTNode child = null) : this(count, false, endOnFailure, child) { }
private BTRepeater (int count, bool repeatForever, bool endOnFailure, BTNode child = null) : base (child) { this.count = count; this.repeatForever = repeatForever; this.endOnFailure = endOnFailure; }
public Task(BTNode node) : base(node) { }
public BTRepeater (int count, bool endOnFailure, BTNode child = null) : this (count, false, endOnFailure, child) {}
public Decorator(BTNode node) : base(node) { }
public BTRepeater (bool endOnFailure, BTNode child = null) : this (0, true, endOnFailure, child) {}
public BTTimer (float interval, BTNode child = null) : base (child) { this.interval = interval; }
public BTDecorator(BTNode node) { this.child = node; }
public override void AddChild(BTNode aNode) { Debug.LogError("BTAction: Cannot add a node into BTAction."); }
public override void AddChild (BTNode aNode) { base.AddChild (aNode); _results.Add(BTResult.Running); }
public void RemoveChild(BTNode node) { children.Remove(node); selectedChildrenForClear.Remove(node); }
public override void RemoveChild (BTNode aNode) { int index = _children.IndexOf(aNode); _results.RemoveAt(index); base.RemoveChild (aNode); }
public void RemoveChild (BTNode node) { children.Remove(node); selectedChildrenForClear.Remove(node); }
public BTInverter (BTNode child = null) : base (child) {}
void DrawNode( BTNode node ) { if ( !node ) { Debug.LogError( "Node is null!" ); return; } // Handle children. if ( node is BTDecorator ) { DrawDecorator( (BTDecorator)node ); } else if ( node is BTComposite ) { DrawCompositor( (BTComposite)node ); } else { DrawLeaf( (BTLeaf)node ); } }
public override void RemoveChild (BTNode aNode) { Debug.LogError("BTAction: Cannot remove a node into BTAction."); }
BTNode CreateNodeWithParent( Type nodeType, BTNode parent ) { BTNode newNode = CreateNode( nodeType ); EditorData nodeData = new EditorData( newNode, parent ); nodeData.rect.position = _editorData[parent.id].rect.position + new Vector2( 0.0f, 100.0f ); _behaviorTree._editorData.Add( nodeData ); BuildEditorData(); return newNode; }
public BTNode(int d) { data = d; left = right = null; }
public EditorData( BTNode node, BTNode parent ) { this.node = node; this.parent = parent; this.id = node.id; if ( parent is BTComposite ) { // EditorData is always created before adding the node // to the parent's list of children, so we can assume its // index with be _children.Count. parentIndex = ( (BTComposite)parent ).children.Count; } }
public Root(BTNode node) : base(node) { }
public override void RemoveChild (BTNode aNode) { int index = _children.IndexOf(aNode); _activeList.RemoveAt(index); base.RemoveChild (aNode); }
private BTRepeater(int count, bool repeatForever, bool endOnFailure, BTNode child = null) : base(child) { this.count = count; this.repeatForever = repeatForever; this.endOnFailure = endOnFailure; }
public override void AddChild (BTNode aNode) { Debug.LogError("BTAction: Cannot add a node into BTAction."); }
void ReplaceNode(EditorData nodeData, Type newType) { BTNode oldNode = nodeData.node; BTNode newNode = CreateNode(newType); // Transfer editor data. newNode.id = nodeData.id; nodeData.node = newNode; // Swap children, then delete old node. if (oldNode is BTDecorator && newNode is BTDecorator) { ((BTDecorator)newNode).child = ((BTDecorator)oldNode).child; ((BTDecorator)oldNode).child = null; _editorData[((BTDecorator)newNode).child.id].parent = ((BTDecorator)newNode); } else if (oldNode is BTComposite && newNode is BTComposite) { ((BTComposite)newNode).children = ((BTComposite)oldNode).children; ((BTComposite)oldNode).children = null; for (int i = 0; i < ((BTComposite)newNode).children.Count; i++) { _editorData[((BTComposite)newNode).children[i].id].parent = ((BTComposite)newNode); } } else if (oldNode is BTDecorator && newNode is BTComposite) { ((BTComposite)newNode).children = new List <BTNode> { ((BTDecorator)oldNode).child }; ((BTDecorator)oldNode).child = null; _editorData[((BTComposite)newNode).children[0].id].parent = ((BTComposite)newNode); } else if (oldNode is BTComposite && newNode is BTDecorator) { if (((BTComposite)oldNode).children.Count > 0) { ((BTDecorator)newNode).child = ((BTComposite)oldNode).children[0]; _editorData[((BTDecorator)newNode).child.id].parent = ((BTDecorator)newNode); } ((BTComposite)oldNode).children = null; } DeleteNode(oldNode, false); // Update parent's reference to the node. if (nodeData.parent) { if (nodeData.parent is BTDecorator) { BTDecorator parentDecorator = (BTDecorator)nodeData.parent; parentDecorator.child = nodeData.node; } else if (nodeData.parent is BTComposite) { BTComposite parentCompositor = (BTComposite)nodeData.parent; parentCompositor.children[nodeData.parentIndex] = nodeData.node; } else { Debug.LogError("Parent node is neither a Decorator nor a Compositor!"); } } else { // Node is root node. _behaviorTree.root = nodeData.node; } // Editor data will have changed, so we must rebuild // it before continuing with rendering the GUI. BuildEditorData(); }
public BTDecorator (BTNode node) { this.child = node; }
public void AddChild(BTNode child) { NameDisambiguation(child.Name); children.Add(child); }