-
Notifications
You must be signed in to change notification settings - Fork 1
/
DebugStrings.cpp
78 lines (61 loc) · 2.08 KB
/
DebugStrings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Fill out your copyright notice in the Description page of Project Settings.
#include "DebugStrings.h"
#include "Engine/Canvas.h"
FDebugSceneProxy::FDebugSceneProxy(const UPrimitiveComponent* InComponent, FDebugSceneProxyData* ProxyData)
: FDebugRenderSceneProxy(InComponent)
{
DrawType = EDrawType::SolidAndWireMeshes;
ViewFlagName = TEXT("DebugText");
this->ProxyData = *ProxyData;
for(const auto& Text : ProxyData->DebugLabels)
{
this->Texts.Add({
Text.Text,
Text.Location,
FColor::White
});
}
}
void FDebugTextDelegateHelper::DrawDebugLabels(UCanvas* Canvas, APlayerController* PlayerController)
{
if(!Canvas) return;
const FColor OldDrawColor = Canvas->DrawColor;
Canvas->SetDrawColor(FColor::White);
const FSceneView* View = Canvas->SceneView;
const UFont* Font = GEngine->GetSmallFont();
const FDebugSceneProxyData::FDebugText* DebugText = DebugLabels.GetData();
for(int32 i = 0; i < DebugLabels.Num(); ++i, ++DebugText)
{
if(View->ViewFrustum.IntersectSphere(DebugText->Location, 1.0f))
{
const FVector ScreenLoc = Canvas->Project(DebugText->Location);
Canvas->DrawText(Font, DebugText->Text, ScreenLoc.X, ScreenLoc.Y);
}
}
Canvas->SetDrawColor(OldDrawColor);
}
void FDebugTextDelegateHelper::SetupFromProxy(const FDebugSceneProxy* InSceneProxy)
{
DebugLabels.Reset();
DebugLabels.Append(InSceneProxy->ProxyData.DebugLabels);
}
UDebugStrings::UDebugStrings(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
FEngineShowFlags::RegisterCustomShowFlag(TEXT("DebugText"), false, SFG_Normal,
FText::FromString("Debug Text"));
}
FDebugRenderSceneProxy* UDebugStrings::CreateDebugSceneProxy()
{
FDebugSceneProxyData ProxyData;
ProxyData.DebugLabels.Add({
FVector(0, 0, 100),
TEXT("Hello World")
});
FDebugSceneProxy* DebugSceneProxy = new FDebugSceneProxy(this, &ProxyData);
DebugDrawDelegateManager.SetupFromProxy(DebugSceneProxy);
return DebugSceneProxy;
}
FBoxSphereBounds UDebugStrings::CalcBounds(const FTransform& LocalToWorld) const
{
return FBoxSphereBounds(FBox(FVector(-1000, -1000, -1000), FVector(1000, 1000, 1000)));
}