Files
video-record-ue-poc/Source/AudioVideoRecord/AudioVideoRecordPlayerController.cpp

71 lines
1.9 KiB
C++
Raw Normal View History

2026-03-11 11:25:15 +05:30
// Copyright Epic Games, Inc. All Rights Reserved.
#include "AudioVideoRecordPlayerController.h"
#include "EnhancedInputSubsystems.h"
#include "Engine/LocalPlayer.h"
#include "InputMappingContext.h"
#include "AudioVideoRecordCameraManager.h"
#include "Blueprint/UserWidget.h"
#include "AudioVideoRecord.h"
#include "Widgets/Input/SVirtualJoystick.h"
AAudioVideoRecordPlayerController::AAudioVideoRecordPlayerController()
{
// set the player camera manager class
PlayerCameraManagerClass = AAudioVideoRecordCameraManager::StaticClass();
}
void AAudioVideoRecordPlayerController::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(LogAudioVideoRecord, Error, TEXT("Could not spawn mobile controls widget."));
}
}
}
void AAudioVideoRecordPlayerController::SetupInputComponent()
{
Super::SetupInputComponent();
// only add IMCs for local player controllers
if (IsLocalPlayerController())
{
// Add Input Mapping Context
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);
}
}
}
}
}