Agrarsense
SimulationLevelManager.cpp
Go to the documentation of this file.
1// Copyright (c) 2023 FrostBit Software Lab at the Lapland University of Applied Sciences
2//
3// This work is licensed under the terms of the MIT license.
4// For a copy, see <https://opensource.org/licenses/MIT>.
5
11#include "Kismet/GameplayStatics.h"
12
14{
15 PrimaryActorTick.bCanEverTick = false;
16 SensorsManager = CreateDefaultSubobject<USensorsManagerComponent>(TEXT("SensorsManagerComp"));
17}
18
20{
21 Super::BeginPlay();
22}
23
25{
26 SimulationState = newState;
27
28 OnSimulationStateChanged.Broadcast(newState);
29}
30
32{
33 SimulationPhase = newPhase;
34
35 OnSimulationPhaseChanged.Broadcast(newPhase);
36}
37
39{
40 bool WasPossessed = false;
41
42 if (Vehicle)
43 {
45 APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
46
47 if (PlayerController)
48 {
49 PlayerController->Possess(Vehicle);
50 WasPossessed = true;
52 }
53 }
54
55 return WasPossessed;
56}
57
59{
61 {
62 APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
63
64 if (PlayerController)
65 {
66 ASpectator* Spectator = UAgrarsenseStatics::GetSpectator(GetWorld());
67 if (Spectator)
68 {
69 PlayerController->Possess(Spectator);
70 }
71 }
72
75 }
76}
ESimulationPhase
ESimulationState
TObjectPtr< AVehicle > ManuallyControlledVehicle
bool TakeManualControlOfVehicle(AVehicle *Vehicle)
virtual void BeginPlay() override
void SetSimulationPhase(ESimulationPhase newPhase)
FSimulationStateChanged OnSimulationStateChanged
TObjectPtr< USensorsManagerComponent > SensorsManager
void SetSimulationState(ESimulationState newState)
FSimulationPhaseChanged OnSimulationPhaseChanged
static ASpectator * GetSpectator(const UObject *WorldContextObject)