void AHostPlayerController::UnRegisterInput()
{
int32 bind_num = InputComponent->GetNumActionBindings();
for (int i = bind_num - 1;
i >= 0;
--i)
{
FInputActionBinding bind_action = InputComponent->GetActionBinding(i);
bind_action.ActionDelegate.Unbind();
FName action_name = bind_action.GetActionName();
}
int32 axis_num = InputComponent->AxisBindings.Num();
for (int i = axis_num-1;
i>=0;
--i)
{
FInputAxisBinding bind_axis = InputComponent->AxisBindings[i];
bind_axis.AxisDelegate.Unbind();
}
}void AHostPlayerController::RegisterInput()
{
InputComponent->BindAction("Jump", IE_Pressed, this, &AHostPlayerController::Jump);
InputComponent->BindAction("Jump", IE_Released, this, &AHostPlayerController::StopJumping);
InputComponent->BindAction("Use", IE_Pressed, this, &AHostPlayerController::Use);
InputComponent->BindAction("Crouch", IE_Pressed, this, &AHostPlayerController::Crouch);
InputComponent->BindAction("Crouch", IE_Released, this, &AHostPlayerController::StopCrouch);
InputComponent->BindAction("Prone", IE_Pressed, this, &AHostPlayerController::Prone);
InputComponent->BindAction("Prone", IE_Released, this, &AHostPlayerController::StopProne);
InputComponent->BindAction("Accelerate", IE_Pressed, this, &AHostPlayerController::Accelerate);
InputComponent->BindAction("Accelerate", IE_Released, this, &AHostPlayerController::StopAccelerate);
InputComponent->BindAction("Kill", IE_Pressed, this, &AHostPlayerController::Kill);
InputComponent->BindAction("Revive", IE_Pressed, this, &AHostPlayerController::Revive);
InputComponent->BindAction("SwitchCamera", IE_Released, this, &AHostPlayerController::SwitchCamera);
InputComponent->BindAxis("MoveForward", this, &AHostPlayerController::MoveForward);
InputComponent->BindAxis("MoveRight", this, &AHostPlayerController::MoveRight);
InputComponent->BindAxis("Turn", this, &AHostPlayerController::Turn);
InputComponent->BindAxis("TurnRate", this, &AHostPlayerController::TurnAtRate);
InputComponent->BindAxis("LookUp", this, &AHostPlayerController::LookUp);
InputComponent->BindAxis("LookUpRate", this, &AHostPlayerController::LookUpAtRate);
InputComponent->BindAction("Interactive", IE_Pressed, this, &AHostPlayerController::ItemInteract);
}
【UE4-【C++】【UE4 Input Action/Axis事件注册和解注册】】
推荐阅读
- 使用虚幻引擎中的C++导论
- Scripting the Editor using Python
- 虚幻4DPI自适应缩放规则解析
- 【UE4_C++】<14-3>用户界面 UI和UMG——为UI创建屏幕尺寸自适应缩放
- UE4血条、名字面向相机
- UE4|UE4C++ 设置UMG控件的Slot
- UE4|AirSim里的那些坑
- UE4总结四