private void SwitchToState(States state)
 {
     _errorProvider.DoWith(() =>
     {
         DeactivateCurrent();
         _currentState = _stateProvider(state);
         _currentState.Activate(_currentUser, _currentItem);
         RaiseStateChanged();
     });
 }
Ejemplo n.º 2
0
        public void Start()
        {
            //Clean up
            activeStates.Clear();

            //Set up
            activeStates.AddLast(startState);
            startState.Activate();

            //invoke the OnStart event which allows the user to add more functionality to the Start method
            Starting?.Invoke(this, EventArgs.Empty);
        }
Ejemplo n.º 3
0
        public void ChangeState(Squad squad, IState newState, bool rememberPrevious)
        {
            if (rememberPrevious)
            {
                previousState = currentState;
            }

            currentState?.Deactivate(squad);

            if (newState != null)
            {
                currentState = newState;
            }

            currentState?.Activate(squad);
        }
Ejemplo n.º 4
0
        private void StartState(string stateName)
        {
            //deactivate the currently active state
            if (_activeState != null && _activeState.IsActive)
            {
                _activeState.Deactivate();
            }
            _previousState = _activeState;

            //try activate desired one
            try
            {
                _activeState = _states[stateName];
                _activeState.Activate();
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// 激活使用,此时排除其他对象对该实例的使用
 /// </summary>
 public virtual void Activate()
 {
     state.Activate(this);
 }
Ejemplo n.º 6
0
 public void Activate(IAccountIdentity account)
 {
     state.Activate(this, account);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Активирует состояние, принуждая к деактивации допустимые конфликтующие с ним. 
 /// </summary>
 /// <param name="state"> Состояние. </param>
 public void ActivateState(IState state)
 {
     if (!current.Contains(state))
         return;
     if (!current.Contains(state))
         return;
     if (state.IsActivated())
         return;
     if (state.IsCanActivate(this))
     {
         ForceConflictResolvingFor(state);
         state.Activate(this);
     }
 }
Ejemplo n.º 8
0
 public void SetState(IState state)
 {
     _currentState?.Deactivate();
     _currentState = state;
     _currentState?.Activate();
 }