示例#1
0
        public void ChangeState(T nextState)
        {
            if (Equals(nextState, CurrentState))
            {
                return;
            }
            HashSet <OnExit> exitCallbacks;

            if (OnStateExit.TryGetValue(CurrentState, out exitCallbacks))
            {
                foreach (var callback in exitCallbacks)
                {
                    callback(nextState);
                }
            }
            PreviousState = CurrentState;
            CurrentState  = nextState;
            HashSet <OnEnter> enterCallbacks;

            if (OnStateEnter.TryGetValue(CurrentState, out enterCallbacks))
            {
                foreach (var callback in enterCallbacks)
                {
                    callback(PreviousState);
                }
            }
            StateEnterTime = TimeSlice.Create();
            StateChanged.Publish(PreviousState, CurrentState);
        }
示例#2
0
        protected override void State(Expression <Func <State> > propertyExpression)
        {
            var state = propertyExpression.Compile().Invoke();

            WhenEnter(state, x => x.Then(ctx =>
                                         OnStateEnter.Invoke(this, new StateChangedData <TSagaData>(state, ctx.Instance))));

            base.State(propertyExpression);
        }
 /// <summary>
 /// この関数がキックされる度に登録されたイベントをコールする。
 /// </summary>
 /// <remarks>
 /// Updateはインスタンスを持つMonoBehaviourで行う。
 /// </remarks>
 public void Update()
 {
     if (!isCalledEnter)
     {
         OnStateEnter?.Invoke(CurrentState);
         isCalledEnter = true;
     }
     else
     {
         OnStateStay?.Invoke(CurrentState);
     }
 }
        public void AddState(StateBase state)
        {
            var stateType = state.GetType();

            Debug.Assert(!States.ContainsKey(stateType));

            States.Add(stateType, state);
            state.Initialize(Context);

            state.OnEnter  += (enterState) => { OnStateEnter?.Invoke(enterState); };
            state.OnFinish += (finishState) => { OnStateFinish?.Invoke(finishState); };
        }
示例#5
0
        public void ChangeState(TKey key)
        {
            if (CurrentState != null)
            {
                OnStateExit?.Invoke(CurrentStateKey);
            }

            LogExtensions.Log($"State changed to <color=orange>{key}</color>");

            CurrentState    = states[key];
            CurrentStateKey = key;

            OnStateEnter?.Invoke(key);
        }
示例#6
0
        internal void EnterState()
        {
            IsCurrentState = true;
            if (OnStateEnter != null)
            {
                OnStateEnter.Invoke();
            }

            if (HasInnerState)
            {
                foreach (Orthogonal <S, T, G> ort in Orthogonals.Values)
                {
                    ort.SM.Initialize();
                }
            }
        }
示例#7
0
        private void HandleTransitionComplete(SkillFSMTransition transition)
        {
            CurrentTransition.OnComplete -= HandleTransitionComplete;

            PreviousState = CurrentState;
            CurrentState  = transition.ToState;

            CurrentTransition   = null;
            isInitialisingState = true;

            PreviousState.Exit();
            OnStateChange?.Invoke(PreviousState, CurrentState);

            CurrentState.Enter();
            OnStateEnter?.Invoke(CurrentState);

            isInitialisingState = false;
        }
示例#8
0
        protected virtual void EnterState(State targetState)
        {
            if (targetState == _currentState)
            {
                return;
            }

            _currentState = targetState;

            if (!_transitions.TryGetValue(_currentState.Id, out _currentStateTransitions))
            {
                _currentStateTransitions = _S_EMPTY_TRANSITIONS;
            }

            _timeEnteredState = Time.time;
            _currentState.OnEnterInvoke();
            _currentState.Enter();
            OnStateEnter?.Invoke(_currentState);
        }
示例#9
0
 public Machine(SimpleState initial) : base()
 {
     _activeState = initial;
     OnStateEnter.Add(StateEntered);
     OnStateExit.Add(StateExited);
 }
示例#10
0
 public virtual void Enter()
 {
     OnStateEnter?.Invoke();
 }
示例#11
0
 public string GetListeners()
 {
     return(OnStateEnter.GetInvocationList().Print());
 }
示例#12
0
 public void Enter(object data, CancellationToken ct)
 {
     OnStateEnter?.Invoke(data, ct);
 }
示例#13
0
 protected virtual void OnEnter()
 {
     _active = true;
     OnStateEnter?.Invoke();
 }