public BehaviourTree(BT_Node _root) { root = _root; interrupts = new List <BT_Interrupt>(); timings = new List <Timing>(); continueNodes = new Queue <BT_Node>(); }
public BT_While(BT_Node _c, BT_Node _p, IfEvent _e) { children = new List <BT_Node>(); children.Add(_c); parent = _p; condition = _e; }
public BT_Execute(BT_Node _c, BT_Node _p, NodeEvent _e) { nodeEvent = _e; children = new List <BT_Node>(); children.Add(_c); parent = _p; }
virtual public void AddChild(BT_Node c) { if (children == null) { children = new List <BT_Node>(); } children.Add(c); }
public BT_Node() { children = new List <BT_Node>(); parent = null; }
public BT_Sequence(List <BT_Node> cList, BT_Node parent) { children = cList; currentIndex = 0; }
public BT_Selector(List <BT_Node> cList, BT_Node _p) { children = cList; parent = _p; }
public Timer(BT_Node node, double _waitTime) : base(node) { startTime = 0; waitTime = _waitTime; }
public void Tick() { // Check Timings int timingLength = timings.Count; bool isTimingActivated = false; int activatedIndex = -1; for (int i = 0; i < timingLength; i++) { if (timings[i].Check() && !isTimingActivated) { isTimingActivated = true; activatedIndex = i; } } if (isTimingActivated && activatedIndex >= 0) { ResultContainer _result = timings[activatedIndex].Next(); ProcessResult(_result); timings.RemoveAt(activatedIndex); return; } bool isInterruptActivated = false; if (!isTimingActivated) { // Check Interrupts foreach (BT_Interrupt interrupt in interrupts) { if (interrupt.IsInterrupt()) { ResultContainer _result = interrupt.Next(); ProcessResult(_result); isInterruptActivated = true; return; } } } if (!isTimingActivated && !isInterruptActivated) { ResultContainer result = new ResultContainer(); if (continueNodes.Count > 0) { do { BT_Node nextNode = continueNodes.Dequeue(); result = nextNode.Next(); } while (result.Result == BT_Result.FAILURE && continueNodes.Count > 0); if (result.Result == BT_Result.FAILURE) { result = root.Next(); } } else { result = root.Next(); } ProcessResult(result); } }