[UE4] 使用 GUI 框架“Dear ImGui” 示例:ImguiLogWindow
Posted u010019717
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[UE4] 使用 GUI 框架“Dear ImGui” 示例:ImguiLogWindow相关的知识,希望对你有一定的参考价值。
要想从引擎那得到日志数据可以继承自 public FOutputDevice 。
其中一个重要的虚方法
virtual void Serialize(const TCHAR* V, ELogVerbosity::Type Verbosity, const class FName& Category) override;
#pragma once
#include "ImguiConsole.h"
#include "Subsystems/GameInstanceSubsystem.h"
#include "Misc/OutputDevice.h"
#include "UImguiLogSubsystem.generated.h"
#ifdef __clang__
#pragma clang diagnostic ignored "-Woverloaded-virtual"
#pragma clang diagnostic ignored "-Wformat-security"
#endif
UCLASS()
class MYDEMO_API UImguiLogSubsystem : public UGameInstanceSubsystem, public FOutputDevice
GENERATED_BODY()
public:
virtual void Initialize(FSubsystemCollectionBase& Collection) override;
virtual void Deinitialize() override;
virtual void Serialize(const TCHAR* V, ELogVerbosity::Type Verbosity, const class FName& Category) override;
void Draw(bool* bIsOpen);
protected:
FAppConsole Console;
;
#include "ImguiLogSubsystem.h"
void UImguiLogSubsystem::Initialize(FSubsystemCollectionBase& Collection)
check(GLog);
GLog->AddOutputDevice(this);
Console.InitImgui();
void UImguiLogSubsystem::Deinitialize()
GLog->RemoveOutputDevice(this);
void UImguiLogSubsystem::Draw(bool* bIsOpen)
Console.Draw("Console", bIsOpen);
void UImguiLogSubsystem::Serialize(const TCHAR* Message, ELogVerbosity::Type Verbosity, const class FName& Category)
Console.AddLog(Verbosity, TCHAR_TO_ANSI(*Category.ToString()), TCHAR_TO_ANSI(Message));
直接在之前的Tick 方法中驱动LogWindow 的绘制。
void AImGuiTest::ShowLogWindow() if (ImGui::BeginMainMenuBar()) if (ImGui::BeginMenu("Window")) if (ImGui::MenuItem("Log")) bShowLogWindow = !bShowLogWindow; ImGui::EndMenu(); ImGui::EndMainMenuBar(); if (bShowLogWindow) UImguiLogSubsystem* Logger = GetGameInstance()->GetSubsystem<UImguiLogSubsystem>(); Logger->Draw(&bShowLogWindow); void AImGuiTest::Tick(float DeltaTime) Super::Tick(DeltaTime); #if WITH_IMGUI ImGui::Begin("ImGui Debug Order Test"); ImGui::Text("Actor Tick: Actor = '%ls', World = '%ls', CurrentWorld = '%ls'", *GetNameSafe(this), *GetNameSafe(GetWorld()), *GetNameSafe(GWorld)); const FImGuiTextureHandle TextureHandle = FImGuiModule::Get().FindTextureHandle( FName(Texture->GetName()) ); ImGui::Image(TextureHandle, ImVec2( 200 , 200 )); ImGui::End(); ShowLogWindow(); if (ImGui::TreeNode("Basic")) static int clicked = 0; if (ImGui::Button("Button")) clicked++; if (clicked & 1) ImGui::SameLine(); ImGui::Text("Thanks for clicking me!");
以上是关于[UE4] 使用 GUI 框架“Dear ImGui” 示例:ImguiLogWindow的主要内容,如果未能解决你的问题,请参考以下文章