//State Related Methods//////////////////// public void SetState(Type state) { if (_currentState.GetType() == state) { return; } Debug.Log("Player Changing from: " + _currentState.GetType() + " to: " + state); _currentState.EndState(); _currentState = _states[state]; _currentState.BeginState(); }
//添加新状态到集合 void AddState <T>() where T : PlayerStateBase { //添加状态类脚本到物体 PlayerStateBase state = gameObject.AddComponent <T>(); state.OnInit(); //初始化状态 states.Add(state.GetType(), state); //添加到状态集合 }
public Type GetStateType() => state.GetType();