private EBTStatus UpdateFSM(Agent pAgent, EBTStatus childStatus) { Debug.Check(this.m_node != null); Debug.Check(this.m_currentNodeId != -1); EBTStatus status = childStatus; bool bLoop = true; while (bLoop) { BehaviorTask currentState = this.GetChildById(this.m_currentNodeId); currentState.exec(pAgent); if (currentState is State.StateTask) { State.StateTask pStateTask = (State.StateTask)currentState; if (pStateTask.IsEndState) { return(EBTStatus.BT_SUCCESS); } } int nextStateId = currentState.GetNextStateId(); if (nextStateId == -1) { //if not transitioned, don't go on next state, to exit bLoop = false; } else { //if transitioned, go on next state this.m_currentNodeId = nextStateId; } } return(status); }
private EBTStatus UpdateFSM(Agent pAgent, EBTStatus childStatus) { Debug.Check(this.m_node != null); Debug.Check(this.m_currentNodeId != -1); #if !BEHAVIAC_RELEASE int kMaxCount = 10; Dictionary <int, int> state_update_count = new Dictionary <int, int>(); #endif//#if !BEHAVIAC_RELEASE EBTStatus status = childStatus; bool bLoop = true; while (bLoop) { BehaviorTask currentState = this.GetChildById(this.m_currentNodeId); currentState.exec(pAgent); if (currentState is State.StateTask) { State.StateTask pStateTask = (State.StateTask)currentState; if (pStateTask.IsEndState) { return(EBTStatus.BT_SUCCESS); } } int nextStateId = currentState.GetNextStateId(); if (nextStateId == -1) { //if not transitioned, don't go on next state, to exit bLoop = false; } else { #if !BEHAVIAC_RELEASE if (state_update_count.ContainsKey(this.m_currentNodeId)) { state_update_count[this.m_currentNodeId]++; } else { state_update_count.Add(this.m_currentNodeId, 1); } if (state_update_count[this.m_currentNodeId] > kMaxCount) { string treeName = BehaviorTask.GetParentTreeName(pAgent, this.GetNode()); Debug.LogError(string.Format("{0} might be updating an FSM('{1}') endlessly, possibly a dead loop, please redesign it!\n", pAgent.GetName(), treeName)); Debug.Check(false); } #endif //if transitioned, go on next state this.m_currentNodeId = nextStateId; } } return(status); }