UE4-【C++】【UE4 Input Action/Axis事件註冊和解註冊】

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);
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章