RealtimeStyleTransferRuntime/Source/LyraGame/Development/LyraBotCheats.cpp

57 lines
1.3 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "LyraBotCheats.h"
#include "Engine/World.h"
#include "GameFramework/GameStateBase.h"
#include "GameModes/LyraBotCreationComponent.h"
//////////////////////////////////////////////////////////////////////
// ULyraBotCheats
ULyraBotCheats::ULyraBotCheats()
{
#if WITH_SERVER_CODE && UE_WITH_CHEAT_MANAGER
if (HasAnyFlags(RF_ClassDefaultObject))
{
UCheatManager::RegisterForOnCheatManagerCreated(FOnCheatManagerCreated::FDelegate::CreateLambda(
[](UCheatManager* CheatManager)
{
CheatManager->AddCheatManagerExtension(NewObject<ThisClass>(CheatManager));
}));
}
#endif
}
void ULyraBotCheats::AddPlayerBot()
{
#if WITH_SERVER_CODE && UE_WITH_CHEAT_MANAGER
if (ULyraBotCreationComponent* BotComponent = GetBotComponent())
{
BotComponent->Cheat_AddBot();
}
#endif
}
void ULyraBotCheats::RemovePlayerBot()
{
#if WITH_SERVER_CODE && UE_WITH_CHEAT_MANAGER
if (ULyraBotCreationComponent* BotComponent = GetBotComponent())
{
BotComponent->Cheat_RemoveBot();
}
#endif
}
ULyraBotCreationComponent* ULyraBotCheats::GetBotComponent() const
{
if (UWorld* World = GetWorld())
{
if (AGameStateBase* GameState = World->GetGameState())
{
return GameState->FindComponentByClass<ULyraBotCreationComponent>();
}
}
return nullptr;
}