// Update is called once per frame void Update() { curState.Execute(); if (!curState.CheckIsAlive()) { curState.Exit(); curState = GetNextState(); curState.Enter(); } RefreshUI(); }
void OnLeaveState(object p1, object p2) { Type t = (Type)p1; Debug.Log("OnLeaveState" + t.Name + ", will = " + _willStateType.Name); if (_nowState.GetType() == t) { _nowState = GetState(_willStateType); _nowState.Enter(_willStateParameter); _willStateType = null; } }
public void ChangePrevState() { if (savePrevState != null && curState.ID == savePrevState.ID) { return; } if (curState != null) { curState.Leave(); } curState = savePrevState; curState.Enter(); prevState = curState; }
// trocando o estado public void SwitchState(string newState) { BaseGameState state = FindState(newState); if (state == null) { Debug.LogError("Nao foi encontrado um estado com o nome " + newState); return; } stateStack[stateStack.Count - 1].Exit(state); state.Enter(stateStack[stateStack.Count - 1]); stateStack.RemoveAt(stateStack.Count - 1); stateStack.Add(state); }
public BaseGameState savePrevState; //上一个状态 public void ChangeState(BaseGameState newState) { if (curState != null && curState.ID == newState.ID) { return; } if (prevState != null) { savePrevState = prevState; prevState.Leave(); } curState = newState; curState.Enter(); prevState = curState; }
void ChangeState(Type type) { if (_nowState == null) { _nowState = GetState(type); _nowState.Enter(null); _willStateType = null; return; } if (_nowState.GetType() == type) { return; } if (_willStateType != null && _willStateType == type) { return; } _willStateType = type; _nowState.Leave(); }
// Start is called before the first frame update void Start() { curState = prepareState; curState.Enter(); }