Agrarsense
Public Member Functions | Private Member Functions | Private Attributes | List of all members
UAgrarsenseConsoleCommands Class Reference

#include <AgrarsenseConsoleCommands.h>

Inheritance diagram for UAgrarsenseConsoleCommands:
Inheritance graph
[legend]
Collaboration diagram for UAgrarsenseConsoleCommands:
Collaboration graph
[legend]

Public Member Functions

 UAgrarsenseConsoleCommands ()
 
 ~UAgrarsenseConsoleCommands ()
 

Private Member Functions

void ToggleWorldRendering ()
 
void ToggleInstancedRendering ()
 
void SetInstancedActorsVisibilityEditor (bool Visible)
 
void SetInstacedTreesVisibilityEditor (bool Visible)
 

Private Attributes

TArray< TUniquePtr< FAutoConsoleCommand > > ConsoleCommands
 

Detailed Description

Definition at line 15 of file AgrarsenseConsoleCommands.h.

Constructor & Destructor Documentation

◆ UAgrarsenseConsoleCommands()

UAgrarsenseConsoleCommands::UAgrarsenseConsoleCommands ( )

Definition at line 23 of file AgrarsenseConsoleCommands.cpp.

24{
25 // Register custom console commands
26 ConsoleCommands.Add(MakeUnique<FAutoConsoleCommand>(
27 TEXT("r.WorldRendering"),
28 TEXT("Toggle World rendering"),
29 FExecuteAction::CreateLambda([this]() { ToggleWorldRendering(); })
30 ));
31
32 ConsoleCommands.Add(MakeUnique<FAutoConsoleCommand>(
33 TEXT("r.InstancedRendering"),
34 TEXT("Toggle Agrarsense Instanced rendering"),
35 FExecuteAction::CreateLambda([this]() { ToggleInstancedRendering(); })
36 ));
37
38#if WITH_EDITOR
39 // With following commands,
40 // you can hide/show all InstancedActors to improve Unreal Editor performance
41 ConsoleCommands.Add(MakeUnique<FAutoConsoleCommand>(
42 TEXT("r.HideInstancedActors"),
43 TEXT("Hide all Agrarsense Instanced actors"),
44 FExecuteAction::CreateLambda([this]() { SetInstancedActorsVisibilityEditor(false); })
45 ));
46
47 ConsoleCommands.Add(MakeUnique<FAutoConsoleCommand>(
48 TEXT("r.ShowInstancedActors"),
49 TEXT("Show all Agrarsense Instanced actors"),
50 FExecuteAction::CreateLambda([this]() { SetInstancedActorsVisibilityEditor(true); })
51 ));
52
53 ConsoleCommands.Add(MakeUnique<FAutoConsoleCommand>(
54 TEXT("r.HideTrees"),
55 TEXT("Hide all Agrarsense Instanced Trees"),
56 FExecuteAction::CreateLambda([this]() { SetInstacedTreesVisibilityEditor(false); })
57 ));
58
59 ConsoleCommands.Add(MakeUnique<FAutoConsoleCommand>(
60 TEXT("r.ShowTrees"),
61 TEXT("Show all Agrarsense Instanced Trees"),
62 FExecuteAction::CreateLambda([this]() { SetInstacedTreesVisibilityEditor(true); })
63 ));
64#endif
65}
TArray< TUniquePtr< FAutoConsoleCommand > > ConsoleCommands
void SetInstancedActorsVisibilityEditor(bool Visible)
void SetInstacedTreesVisibilityEditor(bool Visible)

References ConsoleCommands, SetInstacedTreesVisibilityEditor(), SetInstancedActorsVisibilityEditor(), ToggleInstancedRendering(), and ToggleWorldRendering().

◆ ~UAgrarsenseConsoleCommands()

UAgrarsenseConsoleCommands::~UAgrarsenseConsoleCommands ( )

Definition at line 67 of file AgrarsenseConsoleCommands.cpp.

68{
69 // Unregister all added console commands
70 for (TUniquePtr<FAutoConsoleCommand>& Command : ConsoleCommands)
71 {
72 Command.Reset();
73 }
74}

References ConsoleCommands.

Member Function Documentation

◆ SetInstacedTreesVisibilityEditor()

void UAgrarsenseConsoleCommands::SetInstacedTreesVisibilityEditor ( bool  Visible)
private

Definition at line 124 of file AgrarsenseConsoleCommands.cpp.

125{
126#if WITH_EDITOR
127
128 TArray<FString> TreeNames = { "birch", "spruce", "pine", "alder", "willow" };
129
130 UWorld* World = GEditor ? GEditor->GetEditorWorldContext().World() : nullptr;
131 if (!World)
132 {
133 return;
134 }
135
136 for (TActorIterator<AInstancedActor> ActorItr(World); ActorItr; ++ActorItr)
137 {
138 AInstancedActor* InstancedActor = *ActorItr;
139 if (InstancedActor)
140 {
141 UStaticMeshComponent* StaticMeshComponent = InstancedActor->GetStaticMeshComponent();
142 if (StaticMeshComponent)
143 {
144 // This is not that fast but this is fine this usage..
145 bool found = false;
146 UStaticMesh* Mesh = StaticMeshComponent->GetStaticMesh();
147 if (Mesh)
148 {
149 FString MeshName = Mesh->GetName().ToLower();
150 for (size_t i = 0; i < TreeNames.Num(); i++)
151 {
152 if (MeshName.Contains(TreeNames[i]))
153 {
154 found = true;
155 break;
156 }
157 }
158 }
159
160 if (found)
161 {
162 StaticMeshComponent->SetVisibility(Visible);
163 }
164 }
165 }
166 }
167#endif
168}
UStaticMeshComponent * GetStaticMeshComponent() const

References AInstancedActor::GetStaticMeshComponent().

Referenced by UAgrarsenseConsoleCommands().

◆ SetInstancedActorsVisibilityEditor()

void UAgrarsenseConsoleCommands::SetInstancedActorsVisibilityEditor ( bool  Visible)
private

Definition at line 100 of file AgrarsenseConsoleCommands.cpp.

101{
102#if WITH_EDITOR
103 UWorld* World = GEditor ? GEditor->GetEditorWorldContext().World() : nullptr;
104 if (!World)
105 {
106 return;
107 }
108
109 for (TActorIterator<AInstancedActor> ActorItr(World); ActorItr; ++ActorItr)
110 {
111 AInstancedActor* InstancedActor = *ActorItr;
112 if (InstancedActor)
113 {
114 UStaticMeshComponent* StaticMeshComponent = InstancedActor->GetStaticMeshComponent();
115 if (StaticMeshComponent)
116 {
117 StaticMeshComponent->SetVisibility(Visible);
118 }
119 }
120 }
121#endif
122}

References AInstancedActor::GetStaticMeshComponent().

Referenced by UAgrarsenseConsoleCommands().

◆ ToggleInstancedRendering()

void UAgrarsenseConsoleCommands::ToggleInstancedRendering ( )
private

Definition at line 84 of file AgrarsenseConsoleCommands.cpp.

85{
86 if (GEngine && GEngine->GameViewport)
87 {
88 UWorld* World = GEngine->GameViewport->GetWorld();
89 if (World)
90 {
91 auto* InstanceRenderer = UAgrarsenseStatics::GetInstancedRenderer(World);
92 if (InstanceRenderer)
93 {
94 InstanceRenderer->SetInstancedRendering(!InstanceRenderer->IsRendering());
95 }
96 }
97 }
98}
static AInstancedRenderer * GetInstancedRenderer(const UObject *WorldContextObject)

References UAgrarsenseStatics::GetInstancedRenderer().

Referenced by UAgrarsenseConsoleCommands().

◆ ToggleWorldRendering()

void UAgrarsenseConsoleCommands::ToggleWorldRendering ( )
private

Definition at line 76 of file AgrarsenseConsoleCommands.cpp.

77{
78 if (GEngine && GEngine->GameViewport)
79 {
80 GEngine->GameViewport->bDisableWorldRendering = !GEngine->GameViewport->bDisableWorldRendering;
81 }
82}

Referenced by UAgrarsenseConsoleCommands().

Member Data Documentation

◆ ConsoleCommands

TArray<TUniquePtr<FAutoConsoleCommand> > UAgrarsenseConsoleCommands::ConsoleCommands
private

The documentation for this class was generated from the following files: