예제 #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);
                }
            }
        }
예제 #2
0
 public MonoStateMachine(T _root)
 {
     root          = _root;
     currentState  = null;
     previousState = null;
     globalStates  = new List <MonoState <T> >();
 }
예제 #3
0
 public void RemoveGlobalState(MonoState <T> state)
 {
     if (globalStates.Contains(state))
     {
         state.Exit(root);
         globalStates.Remove(state);
     }
 }
예제 #4
0
 public void SetGlobalState(MonoState <T> state)
 {
     if (!globalStates.Contains(state))
     {
         state.Enter(root);
         globalStates.Add(state);
     }
 }
예제 #5
0
 public void SetCurrentState(MonoState <T> state)
 {
     currentState = state;
     currentState.Enter(root);
 }