Added autopilot spectator

This commit is contained in:
Manuel Wagner 2022-11-02 11:42:10 +01:00
parent c3318e806a
commit 3bfe5ec9d1
6 changed files with 102 additions and 0 deletions

View File

@ -19,6 +19,7 @@
#include "Development/LyraDeveloperSettings.h" #include "Development/LyraDeveloperSettings.h"
#include "Player/LyraPlayerSpawningManagerComponent.h" #include "Player/LyraPlayerSpawningManagerComponent.h"
#include "TimerManager.h" #include "TimerManager.h"
#include "Player/LyraSpectatorPawn.h"
ALyraGameMode::ALyraGameMode(const FObjectInitializer& ObjectInitializer) ALyraGameMode::ALyraGameMode(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer) : Super(ObjectInitializer)
@ -29,6 +30,7 @@ ALyraGameMode::ALyraGameMode(const FObjectInitializer& ObjectInitializer)
ReplaySpectatorPlayerControllerClass = ALyraReplayPlayerController::StaticClass(); ReplaySpectatorPlayerControllerClass = ALyraReplayPlayerController::StaticClass();
PlayerStateClass = ALyraPlayerState::StaticClass(); PlayerStateClass = ALyraPlayerState::StaticClass();
DefaultPawnClass = ALyraCharacter::StaticClass(); DefaultPawnClass = ALyraCharacter::StaticClass();
SpectatorClass = ALyraSpectatorPawn::StaticClass();
HUDClass = ALyraHUD::StaticClass(); HUDClass = ALyraHUD::StaticClass();
} }

View File

@ -71,6 +71,8 @@ public class LyraGame : ModuleRules
"ClientPilot", "ClientPilot",
"AudioModulation", "AudioModulation",
"EngineSettings", "EngineSettings",
"UnrealEd",
"LevelEditor",
} }
); );

View File

@ -14,7 +14,9 @@
#include "GameFramework/Pawn.h" #include "GameFramework/Pawn.h"
#include "AbilitySystemGlobals.h" #include "AbilitySystemGlobals.h"
#include "CommonInputSubsystem.h" #include "CommonInputSubsystem.h"
#include "LevelEditorSubsystem.h"
#include "LyraLocalPlayer.h" #include "LyraLocalPlayer.h"
#include "Character/LyraCharacter.h"
#include "Settings/LyraSettingsShared.h" #include "Settings/LyraSettingsShared.h"
#include "Development/LyraDeveloperSettings.h" #include "Development/LyraDeveloperSettings.h"
@ -44,6 +46,31 @@ void ALyraPlayerController::EndPlay(const EEndPlayReason::Type EndPlayReason)
Super::EndPlay(EndPlayReason); Super::EndPlay(EndPlayReason);
} }
void ALyraPlayerController::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
ULevelEditorSubsystem* LevelEditorSubsystem = GEditor->GetEditorSubsystem<ULevelEditorSubsystem>();
AActor* ActorToPilot = LevelEditorSubsystem->GetPilotLevelActor();
if (Cast<ALyraCharacter>(ActorToPilot))
return;
for (ALyraCharacter* LyraCharacter : TActorRange<ALyraCharacter>(GetWorld()))
{
if(Cast<ALyraPlayerController>(LyraCharacter->GetController()))
continue;
ActorToPilot = LyraCharacter;
break;
}
if (!IsValid(ActorToPilot))
return;
LevelEditorSubsystem->PilotLevelActor(ActorToPilot);
}
void ALyraPlayerController::ReceivedPlayer() void ALyraPlayerController::ReceivedPlayer()
{ {
Super::ReceivedPlayer(); Super::ReceivedPlayer();

View File

@ -61,6 +61,7 @@ public:
virtual void PreInitializeComponents() override; virtual void PreInitializeComponents() override;
virtual void BeginPlay() override; virtual void BeginPlay() override;
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override; virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
virtual void Tick(float DeltaSeconds) override;
//~End of AActor interface //~End of AActor interface
//~AController interface //~AController interface

View File

@ -0,0 +1,48 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "LyraSpectatorPawn.h"
#include "Editor.h"
#include "EngineUtils.h"
#include "LevelEditorSubsystem.h"
#include "Character/LyraCharacter.h"
#include "Character/LyraPawn.h"
// Sets default values
ALyraSpectatorPawn::ALyraSpectatorPawn()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
void ALyraSpectatorPawn::BeginPlay()
{
Super::BeginPlay();
ULevelEditorSubsystem* LevelEditorSubsystem = GEditor->GetEditorSubsystem<ULevelEditorSubsystem>();
LevelEditorSubsystem->EjectPilotLevelActor();
}
// Called every frame
void ALyraSpectatorPawn::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
ULevelEditorSubsystem* LevelEditorSubsystem = GEditor->GetEditorSubsystem<ULevelEditorSubsystem>();
AActor* ActorToPilot = LevelEditorSubsystem->GetPilotLevelActor();
if (Cast<ALyraCharacter>(ActorToPilot))
return;
for (ALyraCharacter* Character : TActorRange<ALyraCharacter>(GetWorld()))
{
ActorToPilot = Character;
break;
}
if (!IsValid(ActorToPilot))
return;
LevelEditorSubsystem->PilotLevelActor(ActorToPilot);
}

View File

@ -0,0 +1,22 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "GameFramework/SpectatorPawn.h"
#include "LyraSpectatorPawn.generated.h"
UCLASS()
class LYRAGAME_API ALyraSpectatorPawn : public ASpectatorPawn
{
GENERATED_BODY()
public:
ALyraSpectatorPawn();
virtual void BeginPlay() override;
virtual void Tick(float DeltaTime) override;
};