您好,欢迎访问代理记账网站
  • 价格透明
  • 信息保密
  • 进度掌控
  • 售后无忧

Unity行为树插件Behavior Tree Designer记录.Decorator装饰2

ReturnFailure

The return failure task will always return failure except when the child task is running.
子Task运行期间将一直返回失败。主要重载了Decorate函数。在父类中的意义是申请改变子Task的状态。从代码上看也是这样,子Task的状态是成功,那么久返回失败;如果是失败,那还是返回失败。需要注意的是,如果是子Task是Running那还是返回Running。也就是说对Running的子Task不起作用,比如内置的Idle 或者 Wait。
Decorator的设计目的就是改变子Task的状态,ReturnFailure是通过修改自身的状态来达到这一目的,而上一篇介绍的UntilFailure是直接修改自身是否能运行来达到这一目的。与之相反的另一个Decorator是ReturnSuccess

    public class ReturnFailure : Decorator
    {
        // The status of the child after it has finished running.
        private TaskStatus executionStatus = TaskStatus.Inactive;

        public override bool CanExecute()
        {
            // Continue executing until the child task returns success or failure.
            return executionStatus == TaskStatus.Inactive || executionStatus == TaskStatus.Running;
        }

        public override void OnChildExecuted(TaskStatus childStatus)
        {
            // Update the execution status after a child has finished running.
            executionStatus = childStatus;
        }

        public override TaskStatus Decorate(TaskStatus status)
        {
            // Return failure even if the child task returned success.
            if (status == TaskStatus.Success) {
                return TaskStatus.Failure;
            }
            return status;
        }

        public override void OnEnd()
        {
            // Reset the execution status back to its starting values.
            executionStatus = TaskStatus.Inactive;
        }
    }

 


分享:

低价透明

统一报价,无隐形消费

金牌服务

一对一专属顾问7*24小时金牌服务

信息保密

个人信息安全有保障

售后无忧

服务出问题客服经理全程跟进