Warning: Declaration of action_plugin_linebreak::register(&$controller) should be compatible with DokuWiki_Action_Plugin::register(Doku_Event_Handler $controller) in /home/stepism/www/ue4/wiki/lib/plugins/linebreak/action.php on line 41

Warning: Declaration of action_plugin_markdownextra::register(&$controller) should be compatible with DokuWiki_Action_Plugin::register(Doku_Event_Handler $controller) in /home/stepism/www/ue4/wiki/lib/plugins/markdownextra/action.php on line 16

Warning: Declaration of action_plugin_syntaxhighlighter3_action::register(Doku_Event_Handler &$controller) should be compatible with DokuWiki_Action_Plugin::register(Doku_Event_Handler $controller) in /home/stepism/www/ue4/wiki/lib/plugins/syntaxhighlighter3/action/action.php on line 28

Warning: Cannot modify header information - headers already sent by (output started at /home/stepism/www/ue4/wiki/lib/plugins/linebreak/action.php:0) in /home/stepism/www/ue4/wiki/inc/auth.php on line 430

Warning: Cannot modify header information - headers already sent by (output started at /home/stepism/www/ue4/wiki/lib/plugins/linebreak/action.php:0) in /home/stepism/www/ue4/wiki/inc/Action/Export.php on line 103

Warning: Cannot modify header information - headers already sent by (output started at /home/stepism/www/ue4/wiki/lib/plugins/linebreak/action.php:0) in /home/stepism/www/ue4/wiki/inc/Action/Export.php on line 103

Warning: Cannot modify header information - headers already sent by (output started at /home/stepism/www/ue4/wiki/lib/plugins/linebreak/action.php:0) in /home/stepism/www/ue4/wiki/inc/Action/Export.php on line 103
====== 割り当てたキーに処理を割り当てる(4.7.5) ====== [[wiki:ue4:input:001]]で割り当てたキーに対して、処理を割り当ててみます。 ここでは仮にMyPawnクラスを用意してログを出力するだけの物を実装します。 ===== ブループリントで対応する ===== MyPawnブループリントの中身はこんな感じになっています。 {{:wiki:ue4:input:ue4_input_action_bind_test.png?300|}} 赤いノードが入力結果を受け取りイベントを発行し、各種関数を呼び出しています。 押しっぱなし判定はこんな感じ。 {{:wiki:ue4:input:ue4_input_hold_key.png?300|}} ===== C++で対応する ===== まず、割り当てる関数を準備しておきます。 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); } これで、割り当てた関数が呼ばれる様になります。 ==== 既知の問題 ==== * BindActionに E_Repeat を指定すると関数が呼ばれない。 ==== 押しっぱなし判定について ==== * ボタンアクションにE_Repeatが使えないので、フラグを用いて代替え案。 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; }