void Action() { //if (plan!=null) Debug.Log(plan.Count); if ((current == null || current == cooldown) && (plan == null || plan.Count == 0)) { plan = htn.GetPlan(); ShowPlan(plan); return; } // if we have a plan, but no current task if (current == null) { current = plan[plan.Count - 1]; plan.RemoveAt(plan.Count - 1); if (current.Prev(Global.ws)) { current.Start(this); } else { plan = null; current = cooldown; current.Start(this); } return; } if (current.Terminate(this)) { if (current == cooldown) { current = null; } else { current = cooldown; current.Start(this); } } }
void retrievePlanner() { while (true) //Loop continuously after started { waitHandle.WaitOne(); //Run only if the handle has been set in fixedUpdate (i.e every 1sec) plan = planner.GetPlan(currentState, isAggresive); //Retrieve updated plan based on currentState //Log generated plan frameGenerated = frameCounter; string debugPlan = ""; foreach (string timeStep in plan) { debugPlan += timeStep + ","; } debugPlan = debugPlan.Substring(0, debugPlan.Length - 1); //Debug.Log("Car:" + currentState.myCar.myUniqueID + " - " + debugPlan); //Wait for 1sec before calling the planner again waitHandle.Reset(); } }