Exemplo n.º 1
0
        override public void OnLogic()
        {
            if (activeState == null)
            {
                throw new System.Exception("The FSM has not been initialised yet! "
                                           + "Call fsm.SetStartState(...) and fsm.OnEnter() to initialise");
            }
            foreach (TransitionBase transition in activeTransitions)
            {
                if (!transition.ShouldTransition())
                {
                    continue;
                }

                if (!activeState.needsExitTime || transition.forceInstantly)
                {
                    ChangeState(transition.to);
                }
                else
                {
                    RequestStateChange(transition.to);
                }

                break;
            }

            activeState.OnLogic();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Runs one logic step. It does at most one transition itself and
        /// calls the active state's logic function (after the state transition, if
        /// one occurred).
        /// </summary>
        override public void OnLogic()
        {
            if (activeState == null)
            {
                throw new System.Exception("The FSM has not been initialised yet! "
                                           + "Call fsm.SetStartState(...) and fsm.OnEnter() or fsm.Init() to initialise");
            }

            // Try the "global" transitions that can transition from any state
            for (int i = 0; i < transitionsFromAny.Count; i++)
            {
                TransitionBase transition = transitionsFromAny[i];

                // Don't transition to the "to" state, if that state is already the active state
                if (transition.to == activeState.name)
                {
                    continue;
                }

                if (TryTransition(transition))
                {
                    activeState.OnLogic();
                    return;
                }
            }

            // Try the "normal" transitions that transition from one specific state to another
            for (int i = 0; i < activeTransitions.Count; i++)
            {
                TransitionBase transition = activeTransitions[i];

                if (TryTransition(transition))
                {
                    activeState.OnLogic();
                    return;
                }
            }

            activeState.OnLogic();
        }
Exemplo n.º 3
0
 public override void OnLogic()
 {
     beforeOnLogic?.Invoke(this);
     state.OnLogic();
     afterOnLogic?.Invoke(this);
 }