Beispiel #1
0
        /// <summary>
        /// fires some trigger
        /// changes the state if needed
        ///
        /// returns true if a valid transition is called
        ///
        /// </summary>
        /// <param name="trigger"></param>
        public bool Fire(TTrigger trigger)
        {
            object fromState = fsm.CurrentStateMap.state;

            if (!dict.ContainsKey(fromState))
            {
                return(false);
            }

            Transition <TTrigger, TState> transition = dict[fromState].ProcessTrigger(trigger);

            if (transition == null)
            {
                return(false);
            }

            if (transition != null && BeforeTriggered != null)
            {
                BeforeTriggered.Invoke(transition);
            }

            fsm.ChangeState(transition.toState, transition.overrideSetting);

            if (Triggered != null)
            {
                Triggered.Invoke(transition);
            }

            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// fires some trigger
        /// changes the state if needed
        ///
        /// returns true if a valid transition is called
        ///
        /// </summary>
        /// <param name="trigger"></param>
        public bool Fire(TTrigger trigger)
        {
            try
            {
                object fromState = fsm.CurrentStateMap.state;
                Transition <TTrigger, TState> transition = dict[fromState].ProcessTrigger(trigger);

                if (transition != null && BeforeTriggered != null)
                {
                    BeforeTriggered.Invoke(transition);
                }

                fsm.ChangeState(transition.toState, transition.overrideSetting);

                if (Triggered != null)
                {
                    Triggered.Invoke(transition);
                }

                return(true);
            }
            catch
            {
                // does not find valid transition regarding this state
                return(false);
            }
        }