Пример #1
0
        protected override BTNodeStatus OnUpdate(IAgent agent, Blackboard bb)
        {
            //内部条件检测未通过
            if (InternalCondition(agent, bb) == false)
            {
                return(BTNodeStatus.Failed);
            }

            //第一次执行此行为
            if (mCurrentState == ActionStateEnum.FirstIn)
            {
                OnEnter(agent, bb);
                mCurrentState = ActionStateEnum.NotFirstIn;
            }
            BTNodeStatus status = BTNodeStatus.Finished;

            //非第一次执行此行为
            if (mCurrentState == ActionStateEnum.NotFirstIn)
            {
                status = OnExcute(agent, bb);
            }
            //若当前行为为持续性行为
            if (status == BTNodeStatus.Running)
            {
                return(status);//返回 Running
            }
            //当前行为已结束(非持续性行为)
            else
            {
                //善后工作(执行退出 + 标志位重置)
                OnReset(agent, bb);
                return(status);//返回 Finished
            }
        }
Пример #2
0
 protected override void OnReset(IAgent agent, Blackboard bb)
 {
     if (mCurrentState == ActionStateEnum.NotFirstIn)
     {
         OnExit(agent, bb);                       //执行退出
         mCurrentState = ActionStateEnum.FirstIn; //标志位重置
     }
 }
Пример #3
0
 private void BecomeState(ActionStateEnum stateEnum, Action action)
 {
     if (_currentState != stateEnum)
     {
         _currentState = stateEnum;
         action();
     }
 }
Пример #4
0
 public void SetSuccess()
 {
     status = ActionStateEnum.NoError;
     result = string.Empty;
 }
Пример #5
0
 public void SetFail(ActionStateEnum errCode, string errorMessage)
 {
     this.status = errCode;
     result = errorMessage;
 }