public EBTStatus exec(Agent pAgent) { bool flag; if (this.m_status == EBTStatus.BT_RUNNING) { flag = true; } else { this.m_status = EBTStatus.BT_INVALID; flag = this.onenter_action(pAgent); bool flag2 = this.isContinueTicking(); if (flag2) { BranchTask parentBranch = this.GetParentBranch(); if (parentBranch != null && parentBranch != this) { parentBranch.SetCurrentTask(this); } } } if (flag) { EBTStatus returnStatus = this.GetReturnStatus(); if (returnStatus == EBTStatus.BT_INVALID) { this.m_status = this.update(pAgent, EBTStatus.BT_RUNNING); } else { this.m_status = returnStatus; } if (this.m_status != EBTStatus.BT_RUNNING) { bool flag3 = this.isContinueTicking(); if (flag3) { BranchTask parentBranch2 = this.GetParentBranch(); if (parentBranch2 != null && parentBranch2 != this) { parentBranch2.SetCurrentTask(null); } } this.onexit_action(pAgent, this.m_status); } } else { this.m_status = EBTStatus.BT_FAILURE; } EBTStatus status = this.m_status; if (this.m_status != EBTStatus.BT_RUNNING && this.NeedRestart()) { this.m_status = EBTStatus.BT_INVALID; this.SetReturnStatus(EBTStatus.BT_INVALID); } return(status); }
public EBTStatus exec(Agent pAgent, EBTStatus childStatus) { #if !BEHAVIAC_RELEASE Debug.Check(this.m_node == null || this.m_node.IsValid(pAgent, this), string.Format("Agent In BT:{0} while the Agent used for: {1}", this.m_node.GetAgentType(), pAgent.GetClassTypeName())); #endif//#if !BEHAVIAC_RELEASE bool bEnterResult = false; if (this.m_status == EBTStatus.BT_RUNNING) { bEnterResult = true; } else { //reset it to invalid when it was success/failure this.m_status = EBTStatus.BT_INVALID; bEnterResult = this.onenter_action(pAgent); } if (bEnterResult) { #if !BEHAVIAC_RELEASE if (Config.IsLoggingOrSocketing) { string btStr = BehaviorTask.GetTickInfo(pAgent, this, "update"); //empty btStr is for internal BehaviorTreeTask if (!string.IsNullOrEmpty(btStr)) { LogManager.Instance.Log(pAgent, btStr, EActionResult.EAR_none, LogMode.ELM_tick); } } #endif bool bValid = this.CheckParentUpdatePreconditions(pAgent); if (bValid) { this.m_status = this.update_current(pAgent, childStatus); } else { this.m_status = EBTStatus.BT_FAILURE; if (this.GetCurrentTask() != null) { this.update_current(pAgent, EBTStatus.BT_FAILURE); } } if (this.m_status != EBTStatus.BT_RUNNING) { //clear it this.onexit_action(pAgent, this.m_status); //this node is possibly ticked by its parent or by the topBranch who records it as currrent node //so, we can't here reset the topBranch's current node } else { BranchTask tree = this.GetTopManageBranchTask(); if (tree != null) { tree.SetCurrentTask(this); } } } else { this.m_status = EBTStatus.BT_FAILURE; } return(this.m_status); }
public EBTStatus exec(Agent pAgent) { #if !BEHAVIAC_RELEASE Debug.Check(this.m_node == null || this.m_node.IsValid(pAgent, this), string.Format("Agent In BT:{0} while the Agent used for: {1}", this.m_node.GetAgentType(), pAgent.GetClassTypeName())); #endif//#if !BEHAVIAC_RELEASE bool bEnterResult = false; if (this.m_status == EBTStatus.BT_RUNNING) { bEnterResult = true; } else { //reset it to invalid when it was success/failure this.m_status = EBTStatus.BT_INVALID; bEnterResult = this.onenter_action(pAgent); //for continue ticking task, to set it as the cached current task bool bIsContinueTicking = this.isContinueTicking(); if (bIsContinueTicking) { BranchTask pBranch = this.GetParentBranch(); if (pBranch != null && pBranch != this) { //if 'this' is a tree, don't set it into it parent's current node Debug.Check(!(this is BehaviorTreeTask)); pBranch.SetCurrentTask(this); } } } if (bEnterResult) { #if !BEHAVIAC_RELEASE if (Config.IsLoggingOrSocketing) { string btStr = BehaviorTask.GetTickInfo(pAgent, this, "update"); //empty btStr is for internal BehaviorTreeTask if (!string.IsNullOrEmpty(btStr)) { LogManager.Log(pAgent, btStr, EActionResult.EAR_none, LogMode.ELM_tick); } } #endif EBTStatus returnStatus = this.GetReturnStatus(); if (returnStatus == EBTStatus.BT_INVALID) { this.m_status = this.update(pAgent, EBTStatus.BT_RUNNING); } else { this.m_status = returnStatus; } if (this.m_status != EBTStatus.BT_RUNNING) { //clear it bool bIsContinueTicking = this.isContinueTicking(); if (bIsContinueTicking) { BranchTask pBranch = this.GetParentBranch(); if (pBranch != null && pBranch != this) { //if 'this' is a tree, don't set it into it parent's current node Debug.Check(!(this is BehaviorTreeTask)); pBranch.SetCurrentTask(null); } } this.onexit_action(pAgent, this.m_status); //this node is possibly ticked by its parent or by the topBranch who records it as currrent node //so, we can't here reset the topBranch's current node } } else { this.m_status = EBTStatus.BT_FAILURE; } EBTStatus currentStatus = this.m_status; if (this.m_status != EBTStatus.BT_RUNNING && this.NeedRestart()) { //reset it to invalid when it needs restarting //don't need to reset the sub tree this.m_status = EBTStatus.BT_INVALID; this.SetReturnStatus(EBTStatus.BT_INVALID); } return(currentStatus); }