Example #1
0
        public void ChangeState(MonoState <T> pNewState)
        {
            if (pNewState == null)
            {
                Debug.LogError("该状态不存在");
            }

            if (currentState != pNewState)
            {
                //退出之前状态
                if (currentState != null)
                {
                    currentState.Exit(root);
                }

                //保存之前状态
                previousState = currentState;

                //设置当前状态
                currentState = pNewState;

                //进入当前状态
                if (currentState != null)
                {
                    currentState.Enter(root);
                }
            }
        }
Example #2
0
 public MonoStateMachine(T _root)
 {
     root          = _root;
     currentState  = null;
     previousState = null;
     globalStates  = new List <MonoState <T> >();
 }
Example #3
0
 public void RemoveGlobalState(MonoState <T> state)
 {
     if (globalStates.Contains(state))
     {
         state.Exit(root);
         globalStates.Remove(state);
     }
 }
Example #4
0
 public void SetGlobalState(MonoState <T> state)
 {
     if (!globalStates.Contains(state))
     {
         state.Enter(root);
         globalStates.Add(state);
     }
 }
Example #5
0
 public void SetCurrentState(MonoState <T> state)
 {
     currentState = state;
     currentState.Enter(root);
 }