Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Sequence<TSubject> : CompositeBehavior<TSubject>
- {
- public override BehaviorStatus Update(TSubject subject, IBehaviorState state, TimeSpan ellapsedTime)
- {
- var status = CurrentBehavior.Update(subject, state, ellapsedTime);
- if (status == BehaviorStatus.Success)
- {
- _currentChildIndex++;
- if (_currentChildIndex >= Children.Count)
- {
- return BehaviorStatus.Success;
- }
- CurrentBehavior.OnEnter(subject, state);
- }
- else if (status == BehaviorStatus.Failure)
- {
- return BehaviorStatus.Failure;
- }
- return BehaviorStatus.Running;
- }
- public override void OnEnter(TSubject subject, IBehaviorState state)
- {
- base.OnEnter(subject, state);
- _currentChildIndex = 0;
- }
- private int _currentChildIndex;
- protected Behavior<TSubject> CurrentBehavior => Children[_currentChildIndex];
- }
Advertisement
Add Comment
Please, Sign In to add comment