コード例 #1
0
        public void ChangeState(FSMState newState, bool IsFixedUpdateExecuted, bool updateElligible)
        {
            if (newState == CurrentFSMState)
            {
                return;
            }

            if (CurrentFSMState != null)
            {
                CurrentFSMState.OnExit();
            }

            if (updateElligible)
            {
                FSMEngine.Instance.UpdateElligibleFSM(ref CurrentFSMState, ref newState, this);
            }

            CurrentFSMState = newState;

#if FSM_DEBUG
            FSMDebugHelper.EnterStateLog(this, newState);
#endif
            CurrentFSMState.OnEnter();

            var transitionTriggered = CurrentFSMState.OnTransition();
            if (transitionTriggered != null)
            {
#if FSM_DEBUG
                FSMDebugHelper.FSMTransitionSuccessful(this, transitionTriggered, "Enter");
#endif
                ChangeState(transitionTriggered.StateToMove, IsFixedUpdateExecuted, true);
            }
            else
            {
                if (CurrentFSMState.UpdateTheSameFrameOfEnter)
                {
                    OnUpdate(IsFixedUpdateExecuted);
                    var updateTransitionTriggered = CurrentFSMState.OnTransition();
                    if (updateTransitionTriggered != null)
                    {
#if FSM_DEBUG
                        FSMDebugHelper.FSMTransitionSuccessful(this, updateTransitionTriggered, "Enter");
#endif
                        ChangeState(updateTransitionTriggered.StateToMove, IsFixedUpdateExecuted, true);
                    }
                }

                if (CurrentFSMState.FixedUpdateTheSameFrameOfEnter && IsFixedUpdateExecuted)
                {
                    OnFixedUpdate();
                    var fixedUpdateTransitionTriggered = CurrentFSMState.OnTransition();
                    if (fixedUpdateTransitionTriggered != null)
                    {
#if FSM_DEBUG
                        FSMDebugHelper.FSMTransitionSuccessful(this, fixedUpdateTransitionTriggered, "Enter");
#endif
                        ChangeState(fixedUpdateTransitionTriggered.StateToMove, IsFixedUpdateExecuted, true);
                    }
                }
            }
        }
コード例 #2
0
 public static void EnterStateLog(FSM FSM, FSMState NewState)
 {
     FormatAndWriteLine("Entering in state : " + NewState.name, FSM);
 }