109 lines
3.1 KiB
C++
109 lines
3.1 KiB
C++
// Copyright
|
|
|
|
|
|
#include "Player/VRPlayerController.h"
|
|
|
|
#include "AbilitySystemGlobals.h"
|
|
#include "EnhancedInputSubsystems.h"
|
|
#include "Logging.h"
|
|
#include "AbilitySystem/VRAbilitySystemComponent.h"
|
|
#include "Input/VRInputComponent.h"
|
|
|
|
AVRPlayerController::AVRPlayerController()
|
|
{
|
|
bReplicates = true;
|
|
}
|
|
|
|
void AVRPlayerController::PostProcessInput(const float DeltaTime, const bool bGamePaused)
|
|
{
|
|
if (UVRAbilitySystemComponent* VRAbilitySystemComponent = GetVRAbilitySystemComponent())
|
|
{
|
|
VRAbilitySystemComponent->ProcessAbilityInput(DeltaTime, bGamePaused);
|
|
}
|
|
|
|
Super::PostProcessInput(DeltaTime, bGamePaused);
|
|
}
|
|
|
|
void AVRPlayerController::SetupInputComponent()
|
|
{
|
|
Super::SetupInputComponent();
|
|
|
|
UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer());
|
|
// We could check the subsystem instead of doing an if statement
|
|
// check(Subsystem);
|
|
|
|
if (InputMappingContext)
|
|
{
|
|
Subsystem->AddMappingContext(InputMappingContext, 0);
|
|
}
|
|
else
|
|
{
|
|
UE_LOG(VRGAS_Log, Error, TEXT("AVRPlayerController::SetupInputComponent - Input Mapping Context not found!"))
|
|
}
|
|
|
|
if (UVRInputComponent* VRInputComponent = Cast<UVRInputComponent>(InputComponent))
|
|
{
|
|
VRInputComponent->BindAbilityActions(InputConfig, this,
|
|
&ThisClass::Input_AbilityTagPressed, &ThisClass::Input_AbilityTagReleased);
|
|
}
|
|
else
|
|
{
|
|
UE_LOG(VRGAS_Log, Error, TEXT("AVRPlayerController::SetupInputComponent - Input Component is not of VRGAS type!"))
|
|
}
|
|
}
|
|
|
|
void AVRPlayerController::OnPossess(APawn* InPawn)
|
|
{
|
|
Super::OnPossess(InPawn);
|
|
|
|
CachedAbilitySystemComponent = Cast<UVRAbilitySystemComponent>(
|
|
UAbilitySystemGlobals::GetAbilitySystemComponentFromActor(GetPawn()));
|
|
}
|
|
|
|
// UAbilitySystemComponent* AVRPlayerController::GetAbilitySystemComponent()
|
|
// {
|
|
// if (!CachedAbilitySystemComponent.IsValid())
|
|
// {
|
|
// CachedAbilitySystemComponent = Cast<UVRAbilitySystemComponent>(
|
|
// UAbilitySystemGlobals::GetAbilitySystemComponentFromActor(GetPawn()));
|
|
//
|
|
// if (!CachedAbilitySystemComponent.IsValid()) return nullptr;
|
|
// }
|
|
//
|
|
// return CachedAbilitySystemComponent.Get();
|
|
// }
|
|
|
|
UVRAbilitySystemComponent* AVRPlayerController::GetVRAbilitySystemComponent()
|
|
{
|
|
// return Cast<UVRAbilitySystemComponent>(GetAbilitySystemComponent());
|
|
if (!CachedAbilitySystemComponent.IsValid())
|
|
{
|
|
CachedAbilitySystemComponent = Cast<UVRAbilitySystemComponent>(
|
|
UAbilitySystemGlobals::GetAbilitySystemComponentFromActor(GetPawn()));
|
|
|
|
if (!CachedAbilitySystemComponent.IsValid()) return nullptr;
|
|
}
|
|
|
|
return CachedAbilitySystemComponent.Get();
|
|
}
|
|
|
|
void AVRPlayerController::Input_AbilityTagPressed(FGameplayTag InTag)
|
|
{
|
|
if (!GetVRAbilitySystemComponent())
|
|
{
|
|
UE_LOG(VRGAS_Log, Error, TEXT("AVRPlayerController::Input_AbilityTagPressed - No Vagabond Rose ASC present!"))
|
|
}
|
|
|
|
GetVRAbilitySystemComponent()->InputTagPressed(InTag);
|
|
}
|
|
|
|
void AVRPlayerController::Input_AbilityTagReleased(FGameplayTag InTag)
|
|
{
|
|
if (!GetVRAbilitySystemComponent())
|
|
{
|
|
UE_LOG(VRGAS_Log, Error, TEXT("AVRPlayerController::Input_AbilityTagReleased - No Vagabond Rose ASC present!"))
|
|
}
|
|
|
|
GetVRAbilitySystemComponent()->InputTagReleased(InTag);
|
|
}
|