Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Used to provide conditions before running other sub behaviors
- /// </summary>
- public abstract class Decorator : Behavior
- {
- private readonly Behavior _decorated;
- protected Decorator(Behavior decorated)
- {
- _decorated = decorated;
- }
- /// <summary>
- /// Condition used to check if it's possible to run this Behavior
- /// </summary>
- /// <param name="context"></param>
- /// <returns></returns>
- public abstract bool CanRun(object context);
- protected override IEnumerable<RunStatus> Execute(object context)
- {
- if (!CanRun(context))
- yield return RunStatus.Failed;
- else
- foreach (var status in _decorated.Execute(context))
- yield return status
- }
- }
Add Comment
Please, Sign In to add comment