67 lines
2.3 KiB
C++
67 lines
2.3 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "Player/LMPlayerController.h"
|
|
#include "EnhancedInputSubsystems.h"
|
|
#include "EnhancedInputComponent.h"
|
|
#include "GameFramework/Character.h"
|
|
#include "Player/LMPlayer.h"
|
|
#include "Weapon/LMWeaponManager.h"
|
|
|
|
void ALMPlayerController::BeginPlay()
|
|
{
|
|
Super::BeginPlay();
|
|
EnhancedInputSubsystem = GetLocalPlayer()->GetSubsystem<UEnhancedInputLocalPlayerSubsystem>();
|
|
EnhancedInputSubsystem->AddMappingContext(DefaultMappingContext, 0);
|
|
LegumixPlayer = Cast<ALMPlayer>(GetPawn());
|
|
}
|
|
|
|
void ALMPlayerController::SetupInputComponent()
|
|
{
|
|
Super::SetupInputComponent();
|
|
if(UEnhancedInputComponent* Input = Cast<UEnhancedInputComponent>(InputComponent))
|
|
{
|
|
Input->BindAction(MoveAction, ETriggerEvent::Triggered, this, &ALMPlayerController::Move);
|
|
Input->BindAction(JumpAction, ETriggerEvent::Triggered, this, &ALMPlayerController::Jump);
|
|
Input->BindAction(LookAction, ETriggerEvent::Triggered, this, &ALMPlayerController::Look);
|
|
Input->BindAction(FireAction, ETriggerEvent::Triggered, this, &ALMPlayerController::Fire);
|
|
Input->BindAction(ReloadAction, ETriggerEvent::Triggered, this, &ALMPlayerController::Reload);
|
|
Input->BindAction(ScrollAction, ETriggerEvent::Triggered, this, &ALMPlayerController::Scroll);
|
|
}
|
|
}
|
|
|
|
void ALMPlayerController::Move(const FInputActionValue& InputValue)
|
|
{
|
|
const FVector2d VectorDirection = InputValue.Get<FVector2d>();
|
|
GetPawn()->AddMovementInput(GetPawn()->GetActorForwardVector(), VectorDirection.X);
|
|
GetPawn()->AddMovementInput(GetPawn()->GetActorRightVector(), VectorDirection.Y);
|
|
}
|
|
|
|
void ALMPlayerController::Jump(const FInputActionValue& InputValue)
|
|
{
|
|
LegumixPlayer->Jump();
|
|
}
|
|
|
|
void ALMPlayerController::Look(const FInputActionValue& InputValue)
|
|
{
|
|
const FVector2d VectorDirection = InputValue.Get<FVector2d>();
|
|
AddYawInput(VectorDirection.X);
|
|
AddPitchInput(VectorDirection.Y);
|
|
}
|
|
|
|
void ALMPlayerController::Fire(const FInputActionValue& InputValue)
|
|
{
|
|
LegumixPlayer->GetWeaponManager()->Fire();
|
|
}
|
|
|
|
void ALMPlayerController::Reload(const FInputActionValue& InputValue)
|
|
{
|
|
LegumixPlayer->GetWeaponManager()->Reload();
|
|
}
|
|
|
|
void ALMPlayerController::Scroll(const FInputActionValue& InputValue)
|
|
{
|
|
const float ScrollAmount = InputValue.Get<float>();
|
|
LegumixPlayer->GetWeaponManager()->SwitchWeapon(ScrollAmount);
|
|
}
|