// Copyright Epic Games, Inc. All Rights Reserved. #include "firstPlayerController.h" #include "EnhancedInputSubsystems.h" #include "Engine/LocalPlayer.h" #include "InputMappingContext.h" #include "firstCameraManager.h" #include "Blueprint/UserWidget.h" #include "first.h" #include "Widgets/Input/SVirtualJoystick.h" AfirstPlayerController::AfirstPlayerController() { // set the player camera manager class PlayerCameraManagerClass = AfirstCameraManager::StaticClass(); } void AfirstPlayerController::BeginPlay() { Super::BeginPlay(); // only spawn touch controls on local player controllers if (SVirtualJoystick::ShouldDisplayTouchInterface() && IsLocalPlayerController()) { // spawn the mobile controls widget MobileControlsWidget = CreateWidget(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 AfirstPlayerController::SetupInputComponent() { Super::SetupInputComponent(); // only add IMCs for local player controllers if (IsLocalPlayerController()) { // Add Input Mapping Context if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem(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); } } } } }