public ExecutionResult IfChaseGotKid(BehaviourTreeInstance instance) { if (instance.HasToStart()) { Debug.Log("running after kid"); instance.WaitUntil(() => { // Here we are using Unity's implementation of asynchronous calls. // You will have to use a different one in different contexts. StartCoroutine(Chasing(instance)); }); } else if (instance.HasToComplete()) { bool b = Random.Range(0f, 1f) > 0.49; Debug.Log(instance.Actor.Name() + ": " + " got child: " + b); return(new ExecutionResult(b)); } else { Debug.Log("running after kid doing nothing"); } return(new ExecutionResult(true)); }
public static IEnumerator DoNap(BehaviourTreeInstance behaviourTreeInstanceState, Action callback = null) { yield return(new WaitForSeconds(3f)); behaviourTreeInstanceState.CompletedAsync(); if (callback != null) { callback(); } }
public static IEnumerator Chasing(BehaviourTreeInstance behaviourTreeInstanceState, Action callback = null) { yield return(new WaitForSeconds(3f)); Debug.Log("End chase"); behaviourTreeInstanceState.CompletedAsync(); if (callback != null) { callback(); } }
public ExecutionResult ActionBringChildToStation(BehaviourTreeInstance instance) { if (instance.HasToStart()) { Debug.Log(instance.Actor.Name() + ": " + "Bring child to station"); instance.WaitUntil(() => { // Here we are using Unity's implementation of asynchronous calls. // You will have to use a different one in different contexts. StartCoroutine(DoNap(instance, () => { Debug.Log("Completed: child in station"); totalKidsWondering--; })); }); } return(new ExecutionResult(true)); }
public static BehaviourTreeInstance Exemplify(PoliceManager pm) { Policeman p = new Policeman("Bobby"); var patrollingPoliceBehaviourTreeTwoResults = new SelectorNode( pm.IfChaseGotKid, new ActionNode(pm.ActionBringChildToStation), new SequencerNode(new BehaviourTreeNode[] { new ActionNode(pm.ActionWander), new ActionNode(pm.ActionSmoke) }) ); var patrollingPoliceBehaviourTreeTwoResultsSimple = new SelectorNode( pm.IfChaseGotKid, new ActionNode(pm.ActionBringChildToStation), new ActionNode(pm.ActionSmoke) ); var patrollingPoliceBehaviourArrayResults = new SelectorArrayNode( pm.IfChaseGotKidCases, new BehaviourTreeNode[] { new ActionNode(pm.ActionBringChildToStation), new ActionNode(pm.ActionWander), new ActionNode(pm.ActionSmoke) } ); BehaviourTreeInstance instance = new BehaviourTreeInstance(patrollingPoliceBehaviourArrayResults, p, 1); return(instance); }
public ExecutionResult IfChaseGotKidCases(BehaviourTreeInstance instance) { if (instance.HasToStart()) { Debug.Log("running after kid"); instance.WaitUntil(() => { StartCoroutine(DoNap(instance)); }); } else if (instance.HasToComplete()) { var random = Random.Range(0f, 1f); var b = random > 0.6 ? 2 : (random > 0.3 ? 1 : 0); Debug.Log(instance.Actor.Name() + ": " + " got child: " + b); return(new ExecutionResult(b)); } else { Debug.Log("running after kid doing nothing"); } return(new ExecutionResult(true)); }
void Start() { bti = Examples.Exemplify(pm); }
public ExecutionResult ActionWander(BehaviourTreeInstance instance) { Debug.Log(instance.Actor.Name() + ": " + "Wander around"); return(new ExecutionResult(true)); }
public ExecutionResult ActionSmoke(BehaviourTreeInstance instance) { Debug.Log(instance.Actor.Name() + ": " + "Smoke"); return(new ExecutionResult(true)); }
public ExecutionResult ActionBringChildHome(BehaviourTreeInstance instance) { totalKidsWondering--; Debug.Log(instance.Actor.Name() + ": " + "Bring child home"); return(new ExecutionResult(true)); }