【资料图】

1. 概述

相比各种打断点调试的办法,还是更习惯使用打印输出来进行调试。

2. 详论

2.1. 代码

这里写了三个函数:分别是输出到屏幕,输出到警告日志,输出错误日志。

Output.h:

#pragma oncenamespace Output{void PrintScreen(const char* lpszFormat, ...);void PrintLogWarning(const char* lpszFormat, ...);void PrintLogError(const char* lpszFormat, ...);};

Output.cpp:

#include "Output.h"#include #include #include namespace Output{void PrintScreen(const char* lpszFormat, ...){char szInfo[512];va_list argList;va_start(argList, lpszFormat);vsnprintf(szInfo, 512, lpszFormat, argList);va_end(argList);//GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, FString::Printf(TEXT("Print Message this is %f"), 2.3f));GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, FString(UTF8_TO_TCHAR(szInfo)));}void PrintLogWarning(const char* lpszFormat, ...){char szInfo[512];va_list argList;va_start(argList, lpszFormat);vsnprintf(szInfo, 512, lpszFormat, argList);va_end(argList);UE_LOG(LogTemp, Warning, TEXT("%s"), UTF8_TO_TCHAR(szInfo));}void PrintLogError(const char* lpszFormat, ...){char szInfo[512];va_list argList;va_start(argList, lpszFormat);vsnprintf(szInfo, 512, lpszFormat, argList);va_end(argList);GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, FString(UTF8_TO_TCHAR(szInfo)));UE_LOG(LogTemp, Error, TEXT("%s"), UTF8_TO_TCHAR(szInfo));}};

2.2. 解析

代码地址

推荐内容