언리얼4 c++프로그래밍 - 키맵핑(바인딩) 설정
/*
UPlayerInput::AddEngineDefinedAxisMapping은 더이상 바꿀 수 없는 단일 엔진 키맵핑 설정이다.
캐릭터 하나나 컨트롤 값을 단일로만 사용할 경우 사용한다.
*/
//UPlayerInput::AddEngineDefinedAxisMapping(FInputAxisKeyMapping("NpcMoveForward", EKeys::W, 1.f));
//UPlayerInput::AddEngineDefinedAxisMapping(FInputAxisKeyMapping("NpcMoveForward", EKeys::S, -1.f));
//UPlayerInput::AddEngineDefinedAxisMapping(FInputAxisKeyMapping("NpcMoveRight", EKeys::D, 1.f));
//UPlayerInput::AddEngineDefinedAxisMapping(FInputAxisKeyMapping("NpcMoveRight", EKeys::A, -1.f));
//UPlayerInput::AddEngineDefinedAxisMapping(FInputAxisKeyMapping("NpcLookUp", EKeys::E, 1.f));
//UPlayerInput::AddEngineDefinedAxisMapping(FInputAxisKeyMapping("NpcLookUp", EKeys::Q, -1.f));
//UPlayerInput::AddEngineDefinedActionMapping(FInputActionKeyMapping("NpcRightMouse", EKeys::Zero));
//UPlayerInput::AddEngineDefinedActionMapping(FInputActionKeyMapping("NpcDelete", EKeys::Delete));
/*
컨트롤러에 있는 PlayerInput에 있는 키맵핑은 수정 가능한 설정이다.
캐릭마다 여러 컨트롤 값을 사용할 경우 유용하다.
*/
UPlayerInput* PlayerInput = GetWorld()->GetFirstPlayerController()->PlayerInput;
PlayerInput->AddAxisMapping(FInputAxisKeyMapping("NpcMoveForward", EKeys::W, 1.f));
PlayerInput->AddAxisMapping(FInputAxisKeyMapping("NpcMoveForward", EKeys::S, -1.f));
PlayerInput->AddAxisMapping(FInputAxisKeyMapping("NpcMoveRight", EKeys::D, 1.f));
PlayerInput->AddAxisMapping(FInputAxisKeyMapping("NpcMoveRight", EKeys::A, -1.f));
PlayerInput->AddAxisMapping(FInputAxisKeyMapping("NpcLookUp", EKeys::E, 1.f));
PlayerInput->AddAxisMapping(FInputAxisKeyMapping("NpcLookUp", EKeys::Q, -1.f));
PlayerInput->AddActionMapping(FInputActionKeyMapping("NpcUnpossess", EKeys::Zero));
PlayerInput->AddActionMapping(FInputActionKeyMapping("NpcDelete", EKeys::Delete));
//인풋컴포넌트에 함수 바인딩
InputComponent->BindAxis("NpcMoveForward", this, &ANpcCharacter::MoveForward);
InputComponent->BindAxis("NpcMoveRight", this, &ANpcCharacter::MoveRight);
InputComponent->BindAxis("NpcLookUp", this, &APawn::AddControllerPitchInput);
InputComponent->BindAction("NpcUnpossess", IE_Pressed, this, &ANpcCharacter::NpcUnpossess);
InputComponent->BindAction("NpcDelete", IE_Pressed, this, &ANpcCharacter::NpcDelete);
프로젝트 설정에서 하나하나 지정하는 것 말고
C++에서 처리 하는 방식을 찾아 정리하였다.
키맵핑을 삭제 하는 방법은 다음 글로 포스팅 하겠다.