実装はこう。
#include <Kismet/GameplayStatics.h>
#include <Blueprint/WidgetLayoutLibrary.h>
#include "Components/LineBatchComponent.h"
ULineBatchComponent* UDrawScreen::GetDebugLineBatcher(const UWorld* InWorld, bool bPersistentLines, float LifeTime, bool bDepthIsForeground)
{
return (InWorld ? (bDepthIsForeground ? InWorld->ForegroundLineBatcher : ((bPersistentLines || (LifeTime > 0.f)) ? InWorld->PersistentLineBatcher : InWorld->LineBatcher)) : nullptr);
}
void UDrawScreen::ClearScreen(UObject* context)
{
UWorld* world = context->GetWorld();
if (world)
{
ULineBatchComponent* const LineBatcher = GetDebugLineBatcher(world, false, 0 , true);
LineBatcher->Flush();
}
}
void UDrawScreen::DrawOrbitLine(UPARAM(ref) const UObject* context, const TArray<FCartesianElements>& OrbitPoints, const FVector& Offset, FLinearColor Color, float Thickness)
{
if (!context) {
return;
}
UWorld* world = context->GetWorld();
if (!world) {
return;
}
ULineBatchComponent* const LineBatcher = GetDebugLineBatcher(world, false, 0, true);
for (int32 Index = 0; Index < OrbitPoints.Num(); Index++) {
FVector StartPoint = OrbitPoints[Index].Coordinates - Offset;
FVector EndPoint = (OrbitPoints.Num() - 1 != Index ? OrbitPoints[Index + 1].Coordinates : OrbitPoints[0].Coordinates) - Offset;
LineBatcher->DrawLine(StartPoint, EndPoint, Color, SDPG_World, Thickness, -1);
}
}