private void SwitchToState(States state)
 {
     _errorProvider.DoWith(() =>
     {
         DeactivateCurrent();
         _currentState = _stateProvider(state);
         _currentState.Activate(_currentUser, _currentItem);
         RaiseStateChanged();
     });
 }
Esempio 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);
        }
Esempio 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);
        }
Esempio 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);
            }
        }
Esempio n. 5
0
 /// <summary>
 /// 激活使用,此时排除其他对象对该实例的使用
 /// </summary>
 public virtual void Activate()
 {
     state.Activate(this);
 }
Esempio n. 6
0
 public void Activate(IAccountIdentity account)
 {
     state.Activate(this, account);
 }
Esempio 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);
     }
 }
Esempio n. 8
0
 public void SetState(IState state)
 {
     _currentState?.Deactivate();
     _currentState = state;
     _currentState?.Activate();
 }