Exemplo n.º 1
0
 public virtual void Update(float interval)
 {
     if (_triggerTrans == null)
     {
         for (int i = 0; i < _toTransitionList.Count; i++)
         {
             var trans = _toTransitionList[i];
             if (trans.IsCanTrans())
             {
                 _triggerTrans            = trans;
                 _triggerTrans.TransState = FsmTransitionStateEnum.Transing;
                 OnExitState(trans.ToState);
                 break;
             }
         }
     }
     if (_triggerTrans == null)
     {
         UpdateEx(interval);
     }
     else
     {
         FsmTransitionStateEnum state = _triggerTrans.ExcuteTrans(this, _triggerTrans.ToState);
         if (state == FsmTransitionStateEnum.Finish)
         {
             _triggerTrans.TransState = FsmTransitionStateEnum.Transing;
             _machine.CurrentState.OnEnterState(this);
             _triggerTrans = null;
         }
     }
 }
Exemplo n.º 2
0
 public AbsFsmState(FsmMachine machine, string name)
 {
     _name         = name;
     _entity       = machine.Entity;
     _machine      = machine;
     _lastState    = null;
     _nextState    = null;
     _triggerTrans = null;
     _toTransitionList.Clear();
 }
Exemplo n.º 3
0
        public bool RemoveTransition(AbsFsmTransition trans)
        {
            var lastState = trans.FromState;
            var nextState = trans.ToState;

            if (lastState != this && nextState != this)
            {
                return(false);
            }
            if (nextState == this)
            {
                return(lastState.RemoveTransition(trans));
            }
            if (lastState == this && _toTransitionList.Contains(trans))
            {
                _toTransitionList.Remove(trans);
                return(true);
            }
            return(false);
        }
Exemplo n.º 4
0
        public bool AddTransition(AbsFsmTransition trans)
        {
            var lastState = trans.FromState;
            var nextState = trans.ToState;

            if (lastState != this && nextState != this)
            {
                return(false);
            }
            if (nextState == this)
            {
                return(lastState.AddTransition(trans));
            }
            if (lastState == this)
            {
                _toTransitionList.Add(trans);
                return(true);
            }
            return(false);
        }