BradleyUffner

Untitled

Nov 1st, 2017
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1.     public class Sequence<TSubject> : CompositeBehavior<TSubject>
  2.     {
  3.         public override BehaviorStatus Update(TSubject subject, IBehaviorState state, TimeSpan ellapsedTime)
  4.         {
  5.             var status = CurrentBehavior.Update(subject, state, ellapsedTime);
  6.             if (status == BehaviorStatus.Success)
  7.             {
  8.                 _currentChildIndex++;
  9.                 if (_currentChildIndex >= Children.Count)
  10.                 {
  11.                     return BehaviorStatus.Success;
  12.                 }
  13.                 CurrentBehavior.OnEnter(subject, state);
  14.             }
  15.             else if (status == BehaviorStatus.Failure)
  16.             {
  17.                 return BehaviorStatus.Failure;
  18.             }
  19.             return BehaviorStatus.Running;
  20.         }
  21.  
  22.         public override void OnEnter(TSubject subject, IBehaviorState state)
  23.         {
  24.             base.OnEnter(subject, state);
  25.             _currentChildIndex = 0;
  26.         }
  27.  
  28.         private int _currentChildIndex;
  29.  
  30.         protected Behavior<TSubject> CurrentBehavior => Children[_currentChildIndex];
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment