Agrarsense
Walker.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
6#include "Walker.h"
7
8#include "NavigationSystem.h"
9#include "Kismet/KismetMathLibrary.h"
10#include "AIController.h"
11#include "Navigation/PathFollowingComponent.h"
13
14#ifdef WITH_EDITOR
15#include "DrawDebugHelpers.h"
16#endif
17
19{
20 PrimaryActorTick.bCanEverTick = false;
21 InteractableName = NSLOCTEXT("Agrarsense", "WalkerInteractableName", "Walker");
22}
23
25{
26 Super::BeginPlay();
27}
28
29void AWalker::EndPlay(const EEndPlayReason::Type EndPlayReason)
30{
31 Super::EndPlay(EndPlayReason);
32}
33
35{
38 SetIgnoreInput(true);
40}
41
43{
45 {
47 SetIgnoreInput(false);
49 }
50}
51
52void AWalker::SetIgnoreInput(bool IgnoreInput)
53{
54 WalkerIsPaused = IgnoreInput;
55
56 AAIController* AIControllerPtr = Cast<AAIController>(GetController());
57 if (AIControllerPtr)
58 {
59 AIControllerPtr->SetIgnoreMoveInput(WalkerIsPaused);
60 }
61}
62
63FString AWalker::ExportToJsonFile(const FString& FileName)
64{
65 return USimulatorJsonExporter::ExportWalkerToJSON(FileName, this);
66}
67
69{
70#ifdef WITH_EDITOR
72 {
73 return;
74 }
75
76 TArray<FTransform>& Transforms = WalkerParameters.Points;
77
78 // Draw lines between the points
79 for (int32 i = 0; i < Transforms.Num() - 1; ++i)
80 {
81 const FVector Start = Transforms[i].GetLocation();
82 const FVector End = Transforms[i + 1].GetLocation();
83 DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, LifeTime, 0, 5);
84 }
85#endif
86}
FWalkerParameters PreviousParameters
Definition: Walker.h:179
bool WalkerIsPaused
Definition: Walker.h:174
void DebugDrawLinesBetweenPoints(float LifeTime=10.0f)
Definition: Walker.cpp:68
FWalkerParameters WalkerParameters
Definition: Walker.h:177
virtual void SetIgnoreInput(bool IgnoreInput)
Definition: Walker.cpp:52
virtual void ResumeWalker()
Definition: Walker.cpp:42
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override
Definition: Walker.cpp:29
virtual void PauseWalker()
Definition: Walker.cpp:34
virtual void BeginPlay() override
Definition: Walker.cpp:24
void ChangeWalkerParameters(const FWalkerParameters &newParameters)
Definition: Walker.h:56
AWalker()
Definition: Walker.cpp:18
FText InteractableName
Definition: Walker.h:157
FString ExportToJsonFile(const FString &FileName)
Definition: Walker.cpp:63
static FString ExportWalkerToJSON(const FString &FileName, AWalker *Walker)
EWalkerAction WalkerAction
TArray< FTransform > Points