public PlannerTask decomposeNode(BehaviorNode node, int depth) { try { // Ensure that the planner does not get stuck in an infinite loop if (depth >= 256) { Debug.LogError("Exceeded task nesting depth. Does the graph contain an invalid cycle?"); return null; } LogPlanNodeBegin(this.agent, node); int depth1 = this.agent.Variables.Depth; PlannerTask taskAdded = null; bool isPreconditionOk = node.CheckPreconditions(this.agent, false); if (isPreconditionOk) { bool bOk = true; taskAdded = PlannerTask.Create(node, this.agent); if (node is Action) { //nothing to do for action Debug.Check(true); } else { Debug.Check(taskAdded is PlannerTaskComplex); PlannerTaskComplex seqTask = taskAdded as PlannerTaskComplex; bOk = this.decomposeComplex(node, seqTask, depth); } if (bOk) { node.ApplyEffects(this.agent, Effector.EPhase.E_SUCCESS); } else { BehaviorTask.DestroyTask(taskAdded); taskAdded = null; } } else { //precondition failed LogPlanNodePreconditionFailed(this.agent, node); } LogPlanNodeEnd(this.agent, node, taskAdded != null ? "success" : "failure"); Debug.Check(this.agent.Variables.Depth == depth1); return taskAdded; } catch (Exception ex) { Debug.Check(false, ex.Message); } return null; }
public PlannerTask decomposeNode(BehaviorNode node, int depth) { try { // Ensure that the planner does not get stuck in an infinite loop if (depth >= 256) { Debug.LogError("Exceeded task nesting depth. Does the graph contain an invalid cycle?"); return(null); } LogPlanNodeBegin(this.agent, node); int depth1 = this.agent.Variables.Depth; PlannerTask taskAdded = null; bool isPreconditionOk = node.CheckPreconditions(this.agent, false); if (isPreconditionOk) { bool bOk = true; taskAdded = PlannerTask.Create(node, this.agent); if (node is Action) { //nothing to do for action Debug.Check(true); } else { Debug.Check(taskAdded is PlannerTaskComplex); PlannerTaskComplex seqTask = taskAdded as PlannerTaskComplex; bOk = this.decomposeComplex(node, seqTask, depth); } if (bOk) { node.ApplyEffects(this.agent, Effector.EPhase.E_SUCCESS); } else { BehaviorTask.DestroyTask(taskAdded); taskAdded = null; } } else { //precondition failed LogPlanNodePreconditionFailed(this.agent, node); } LogPlanNodeEnd(this.agent, node, taskAdded != null ? "success" : "failure"); Debug.Check(this.agent.Variables.Depth == depth1); return(taskAdded); } catch (Exception ex) { Debug.Check(false, ex.Message); } return(null); }