1 2 3 4 | T CreateState<T>(string animBoolName) where T : PlayerState, new() { return new T(this, StateMachine, playerData, animBoolName); } | cs |
지금 T는 PlayerState를 상속 받는 다른 클래스들에 해당하고, 다른 클래스들을 생성할 때마다 죄다 클래스 이름쓰고 변수 넘겨주는게 귀찮아서 위와 같이 코딩을 하려고 하니 "CS0417 'T': 변수 형식의 인스턴스를 만들 때에는 인수를 지정할 수 없습니다."라고 하면서 오류가 납니다. 최종적으로 아래처럼 코딩이 가능한지 여쭤보고 싶어요.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | //원본 IdleState = new PlayerIdleState(this, StateMachine, playerData, "idle"); MoveState = new PlayerMoveState(this, StateMachine, playerData, "move"); JumpState = new PlayerJumpState(this, StateMachine, playerData, "inAir"); InAirState = new PlayerInAirState(this, StateMachine, playerData, "inAir"); LandState = new PlayerLandState(this, StateMachine, playerData, "land"); -> //수정본 IdleState = CreateState<PlayerIdleState>("idle"); MoveState = CreateState<PlayerMoveState>("move"); JumpState = CreateState<PlayerJumpState>("inJump"); InAirState = CreateState<PlayerInAirState>("inAir"); LandState = CreateState<PlayerLandState>("land"); | cs |