Пример #1
0
        private IBehavior GetBehavior()
        {
            foreach (var behavior in Behaviors)
            {
                if (behavior == _currentBehavior)
                {
                    if (behavior.CanContinue())
                    {
                        return(behavior);
                    }

                    behavior.OnEnd();
                    _currentBehavior = null;
                }

                if (behavior.ShouldStart())
                {
                    if (_currentBehavior == null || Behaviors.IndexOf(_currentBehavior) > Behaviors.IndexOf(behavior))
                    {
                        _currentBehavior?.OnEnd();
                        return(behavior);
                    }
                }
            }

            return(null);
        }