Added autopilot spectator
This commit is contained in:
parent
c3318e806a
commit
3bfe5ec9d1
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,8 @@ public class LyraGame : ModuleRules
|
||||||
"ClientPilot",
|
"ClientPilot",
|
||||||
"AudioModulation",
|
"AudioModulation",
|
||||||
"EngineSettings",
|
"EngineSettings",
|
||||||
|
"UnrealEd",
|
||||||
|
"LevelEditor",
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
|
@ -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;
|
||||||
|
|
||||||
|
};
|
Loading…
Reference in New Issue