コード例 #1
0
        public void OnUpdate()
        {
            if (CurState == null)
            {
                return;
            }

            CurState.OnUpdate();
            if (CurState.IsFinished)
            {
                CurState.OnExit();
                CurState = DefState;
                CurState.OnEnter();
            }
            else if (_curEvent != null)
            {
                FSMState next = StateFromEvent(_curEvent);
                if (next == null)
                {
                    UnityEngine.Debug.Log(string.Format("fail to transfer next FSMState via event code {0}", _curEvent.EventCode));
                    _curEvent = null;
                    return;
                }

                CurState.OnExit();
                CurState = next;
                CurState.OnEnter(_curEvent);
                _curEvent = null;
            }
        }
コード例 #2
0
ファイル: StateMachine.cs プロジェクト: sheenli/StateMachine
        public bool SwitchState(uint newStateId, object param1 = null, object param2 = null)
        {
            bool ret = false;

            if (CurState != null && CurState.StateId == newStateId)
            {
                ret = false;
            }
            else
            {
                IState newState;
                mStateDic.TryGetValue(newStateId, out newState);
                if (newState != null)
                {
                    IState oldState = CurState;
                    CurState = newState;

                    if (oldState != null)
                    {
                        oldState.OnLeave(newState, param1, param2);
                    }
                    CurState.OnEnter(oldState, param1, param2);
                    StateChanged(newState, oldState, param1, param2);
                    ret = true;
                }
            }

            return(ret);
        }
コード例 #3
0
        internal void ChangeState(string stateName, object userData = null)
        {
            //string tempStateName = stateName + FsmId.ToString();
            var s = mFsmStateLst.Find(state => ReferenceEquals(state.StateName, stateName));//地址比较的基础是名字字符串是固定地址!!

            if (s != null)
            {
                CurState.OnLeave();
                CurState = s;
                CurState.OnEnter(userData);
            }
            else
            {
                Z.Debug.Error("切换状态机状态失败:未找到对应状态 " + stateName);
            }
        }
コード例 #4
0
        //改变状态
        public bool ChangeState(string _name, params object[] param)
        {
            //要改变的状态
            IProcedureState _tmpState = GetState(_name);

            if (_tmpState == null)
            {
                return(false);
            }
            //当前状态不为空
            if (CurState != null)
            {
                CurState.OnExit();
            }
            //把要改变的状态赋值给当前状态
            CurState = _tmpState;
            CurState.OnEnter(param);//启动当前状态的OnEnter
            return(true);
        }
コード例 #5
0
        }                                               // 默认状态

        public FSM(List <FSMState> states, FSMState defState)
        {
            _states  = states;
            CurState = DefState = defState;
            CurState.OnEnter();
        }