Esempio n. 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;
            }
        }
Esempio n. 2
0
 //移除所有状态
 public void RemoveAllState()
 {
     if (CurState != null)
     {
         CurState.OnExit();
         CurState = null;
     }
     mList.Clear();
 }
Esempio n. 3
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);
        }
Esempio n. 4
0
        void TransferTo(FSMState state, FSMEvent ev)
        {
            if (state == null)
            {
                return;
            }

            if (state == CurState)
            {
                return;
            }

            if (CheckTransfer(state) == false)
            {
                return;
            }

            CurState.OnExit();
            CurState = state;
            CurState.OnEnter(ev);
        }