Exemplo n.º 1
0
        public void SendMessage(object FSMEventMessage, string ListenerType, GameObject gameObjectCaller, object caller)
        {
#if FSM_DEBUG
            FSMDebugHelper.FSMSendingMessage(gameObjectCaller, caller);
#endif
            var listenerEvent = MessageDispatcher[ListenerType];
            if (listenerEvent != null)
            {
                listenerEvent.Invoke(FSMEventMessage);
            }
        }
Exemplo n.º 2
0
        public void ReceiveMessage(object FSMEventMessage)
        {
            try
            {
                MessageHandling(FSMEventMessage);
            }
            catch (Exception e)
            {
                Debug.LogException(e, this);
#if FSM_DEBUG
                FSMDebugHelper.ReceivingMessageError(this, e);
#endif
            }
        }
Exemplo n.º 3
0
        public void OnLateUpdate(bool IsFixedUpdateExecuted)
        {
#if FSM_DEBUG
            try
            {
#endif
            CurrentFSMState.OnLateUpdate();
#if FSM_DEBUG
        }
        catch (FSMActionProcessingError e)
        {
            FSMDebugHelper.FSMActionProcessError(this, e);
        }
        catch (FSMTransitionProcessingError e)
        {
            FSMDebugHelper.FSMTransitionProcessError(this, e);
        }
#endif
        }
Exemplo n.º 4
0
        private void OnEnable()
        {
#if FSM_DEBUG
            try
            {
#endif
            ChangeState(StartingFSMState, false, false);
            FSMEngine.Instance.AddFSM(this);
#if FSM_DEBUG
        }
        catch (FSMActionProcessingError e)
        {
            FSMDebugHelper.FSMActionProcessError(this, e);
        }
        catch (FSMTransitionProcessingError e)
        {
            FSMDebugHelper.FSMTransitionProcessError(this, e);
        }
#endif
        }
Exemplo n.º 5
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);
                    }
                }
            }
        }