//切换状态 public void ChangeState <T>() where T : PlayerStateBase { //旧状态离开回调 if (currentState != null) { currentState.OnExit(); } currentState = states[typeof(T)]; //切换状态 currentState.OnEnter(); //新状态进入回调 //Debug.Log("进入" + CurrentState.PlayerState); }
// ステート変更 private void ChangeState(PlayerStateBase nextState) { currentState.OnExit(this, nextState); nextState.OnEnter(this, currentState); currentState = nextState; }
// Start()から呼ばれる private void OnStart() { currentState.OnEnter(this, null); }