示例#1
0
        public virtual void OnEnterStateMachine()
        {
            FsmController.UpdateFSMInfor(this, DefaultState);  //更新状态机控制器状态

            Debug.Log("OnEnterStateMachine  name=" + StateMachineName + "  DefaultState=" + DefaultState);

            CurrentState = DefaultState;
            if (CurrentState != null)
            {
                CurrentState.OnEnterState();
            }
        }
示例#2
0
        /// <summary>
        /// Try Any  First Possible FsmState  From This State
        /// </summary>
        public void TryTransLateAny()
        {
            if (CurrentState == null)
            {
                Debug.LogError("CurrentState is Null,StateMachine : " + StateMachineName);
                return;
            }

            IFSMState _TransToState = null;

            //different State of This Statemachine  Switch Check
            foreach (var state in AllFsmStates)
            { //当前状态机的状态切换
                _TransToState = state.Value.TryTranslateToAny();
                if (_TransToState != null)
                {
                    Debug.Log("StateMachine: " + StateMachineName + " TryTransLateAny Success  :    CurrentState=" + CurrentState.StateName + "  " + _TransToState.StateName);
                    CurrentState.OnExitState();
                    CurrentState = (FsmState)_TransToState;           //更新状态
                    _TransToState.OnEnterState();
                    FsmController.UpdateFSMInfor(this, CurrentState); //更新状态机控制器状态
                    // Debug.Log("StateMachine: " + StateMachineName + "  TryTransLateAny Success  :  StateName=" + CurrentState.StateName);
                    return;
                }
            }

            if (AllGetOutStateMachine == null || AllGetOutStateMachine.Count == 0)
            {
                Debug.Log("StateMachine: " + StateMachineName + "  TryTransLateAny Fai   :  No GetOut StateMachine");
                return;
            }
            //Different StateMchine Switch Check
            foreach (var stateMachine in AllGetOutStateMachine.Values)
            {
                if (stateMachine.TryEnterStateMachine())
                {
                    Debug.Log("StateMachine: " + StateMachineName + "  TryTransLateAny Success  :  StateMachineName=" + stateMachine.StateMachineName);
                    CurrentState.OnExitState();
                    OnExitStateMachine();               //离开当前状态i
                    stateMachine.OnEnterStateMachine(); //进入下一个状态机

                    return;
                }
            }
        }
示例#3
0
        /// <summary>
        /// Try To Translate To _toState
        /// </summary>
        /// <param name="_toState"></param>
        public void TryTransLateOne(string _toState)
        {
            if (CurrentState == null)
            {
                Debug.LogError("CurrentState is Null,StateMachine : " + StateMachineName);
                return;
            }

            IFSMState _TransToState = CurrentState.TryTranslateToSpecial(_toState);

            if (_TransToState == null)
            {
                Debug.Log("StateMachine: " + StateMachineName + "  TryTransLateOne  Fai   :  Can't Trans " + _toState);
                return;
            }
            Debug.Log("StateMachine: " + StateMachineName + "CurrentState=" + CurrentState.StateName + "  " + _TransToState.StateName);
            CurrentState.OnExitState();
            CurrentState = (FsmState)_TransToState;           //更新状态
            _TransToState.OnEnterState();
            FsmController.UpdateFSMInfor(this, CurrentState); //更新状态机控制器状态
            Debug.Log("StateMachine: " + StateMachineName + "  TryTransLateOne Success  :  StateName=" + CurrentState.StateName);
            return;
        }