public override void Tick() { if (activeChild == -1) // no child ticked, ignore LastStatus, tick first child { try { activeChild = 0; BehaviorTree.path.Push(Children[activeChild]); } catch { Debug.LogError("Empty Children[]"); } } else // some child already ticked, check result { if (BehaviorTree.lastStatus == NodeStatus.Failure) // fail if any failure { activeChild = -1; BehaviorTree.Finish(NodeStatus.Failure); } else // no failure yet { if (activeChild < Children.Length - 1) // if last activeChild was not the last { activeChild++; BehaviorTree.path.Push(Children[activeChild]); } else // reached the last, still no failure { activeChild = -1; BehaviorTree.Finish(NodeStatus.Success); } } } }
public override void Tick() { if (!started) { BehaviorTree.path.Push(Child); } else { NodeStatus inverted = BehaviorTree.lastStatus == NodeStatus.Success ? NodeStatus.Failure : NodeStatus.Success; BehaviorTree.Finish(inverted); } }
// If condition met, push child // Return Success when child succeeds, Failure otherwise // Ticked only twice: when pushed and when poped public override void Tick() { if (!started) { started = true; if (Fn()) { BehaviorTree.path.Push(Child); } else { BehaviorTree.Finish(NodeStatus.Failure); } } else { BehaviorTree.Finish(BehaviorTree.lastStatus); } }
public override void Tick() { // this condition is most frequently used, so put it first if (!started) { started = true; BehaviorTree.path.Push(Child); } else { if (BehaviorTree.lastStatus == NodeStatus.Success) { BehaviorTree.path.Push(Child); } else { BehaviorTree.Finish(NodeStatus.Failure); } } }
// use global variable to pass status public override void Tick() { if (activeChild == -1) { // no child ticked, ignore LastStatus, tick first child // assuming Children.Length > 0 try { activeChild = 0; BehaviorTree.path.Push(Children[activeChild]); } catch { Debug.LogError("Empty Children[]"); } } else { // some child ticked if (BehaviorTree.lastStatus == NodeStatus.Success) { // succeed if any success activeChild = -1; BehaviorTree.Finish(NodeStatus.Success); } else { // no success yet if (activeChild < Children.Length - 1) { // if last activeChild is not the last activeChild++; BehaviorTree.path.Push(Children[activeChild]); } else { // reached the last, still no success activeChild = -1; BehaviorTree.Finish(NodeStatus.Failure); } } } }
public override void Tick() { if (scores == null) { scores = new List <int>(new int[Children.Length]); } else { Debug.LogWarning("Scores not initialized"); } if (!ticked) { int largest = 0; for (int i = 1; i != scores.Count; i++) { if (scores[i] > scores[largest]) { largest = i; } } lastTicked = largest; BehaviorTree.path.Push(Children[largest]); } else { if (BehaviorTree.lastStatus == NodeStatus.Success) { scores[lastTicked] += 1; } if (BehaviorTree.lastStatus == NodeStatus.Failure) { scores[lastTicked] -= 1; } BehaviorTree.Finish(BehaviorTree.lastStatus); } }