Files
unrealtest/Source/first/Variant_Horror/HorrorPlayerController.cpp
T
2026-08-02 22:34:52 +03:00

93 lines
2.3 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "Variant_Horror/HorrorPlayerController.h"
#include "EnhancedInputSubsystems.h"
#include "Engine/LocalPlayer.h"
#include "InputMappingContext.h"
#include "firstCameraManager.h"
#include "HorrorCharacter.h"
#include "HorrorUI.h"
#include "first.h"
#include "Widgets/Input/SVirtualJoystick.h"
AHorrorPlayerController::AHorrorPlayerController()
{
// set the player camera manager class
PlayerCameraManagerClass = AfirstCameraManager::StaticClass();
}
void AHorrorPlayerController::BeginPlay()
{
Super::BeginPlay();
// only spawn touch controls on local player controllers
if (SVirtualJoystick::ShouldDisplayTouchInterface() && IsLocalPlayerController())
{
// spawn the mobile controls widget
MobileControlsWidget = CreateWidget<UUserWidget>(this, MobileControlsWidgetClass);
if (MobileControlsWidget)
{
// add the controls to the player screen
MobileControlsWidget->AddToPlayerScreen(0);
} else {
UE_LOG(Logfirst, Error, TEXT("Could not spawn mobile controls widget."));
}
}
}
void AHorrorPlayerController::OnPossess(APawn* aPawn)
{
Super::OnPossess(aPawn);
// only spawn UI on local player controllers
if (IsLocalPlayerController())
{
// set up the UI for the character
if (AHorrorCharacter* HorrorCharacter = Cast<AHorrorCharacter>(aPawn))
{
// create the UI
if (!HorrorUI)
{
HorrorUI = CreateWidget<UHorrorUI>(this, HorrorUIClass);
HorrorUI->AddToViewport(0);
}
HorrorUI->SetupCharacter(HorrorCharacter);
}
}
}
void AHorrorPlayerController::SetupInputComponent()
{
Super::SetupInputComponent();
// only add IMCs for local player controllers
if (IsLocalPlayerController())
{
// Add Input Mapping Contexts
if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer()))
{
for (UInputMappingContext* CurrentContext : DefaultMappingContexts)
{
Subsystem->AddMappingContext(CurrentContext, 0);
}
// only add these IMCs if we're not using mobile touch input
if (!SVirtualJoystick::ShouldDisplayTouchInterface())
{
for (UInputMappingContext* CurrentContext : MobileExcludedMappingContexts)
{
Subsystem->AddMappingContext(CurrentContext, 0);
}
}
}
}
}