キーの割り当てについて(4.7.5)で割り当てたキーに対して、処理を割り当ててみます。
ここでは仮にMyPawnクラスを用意してログを出力するだけの物を実装します。
まず、割り当てる関数を準備しておきます。
void AMyPawn::MoveX(float AxisValue)
{
UE_LOG(LogTemp, Log, TEXT("AMyPawn::MoveX() called"));
}
void AMyPawn::MoveY(float AxisValue)
{
UE_LOG(LogTemp, Log, TEXT("AMyPawn::MoveY called"));
}
void AMyPawn::StartScaling()
{
UE_LOG(LogTemp, Log, TEXT("AMyPawn::StartScaling called"));
}
void AMyPawn::StopScaling()
{
UE_LOG(LogTemp, Log, TEXT("AMyPawn::StopScaling called"));
}
次に、ポーンクラスのSetupPlayerInputComponent等で、アクション(関数)を割り当てます。
void AMyPawn::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
Super::SetupPlayerInputComponent(InputComponent);
// 拡縮 キーアクション割り当て
InputComponent->BindAction("Scale", IE_Pressed, this, &AMyPawn::StartScaling); // 押した時
InputComponent->BindAction("Scale", IE_Released, this, &AMyPawn::StopScaling); // 離した時
// 移動キーアクションの割り当て
InputComponent->BindAxis("MoveX", this, &AMyPawn::MoveX);
InputComponent->BindAxis("MoveY", this, &AMyPawn::MoveY);
}
これで、割り当てた関数が呼ばれる様になります。
bIsDown = true;
void AMyPawn::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
// 押しっぱなし判定
if (bIsDown)
{
UE_LOG(LogTemp, Log, TEXT("bIsDown"));
}
}
void AMyPawn::StartScaling()
{
bIsDown = true;
}
void AMyPawn::StopScaling()
{
bIsDown = false;
}