ARPG----C++学习记录01日志和调试

多人射击有点难,发现这个更加基础,先学习这个

显示日志

可以在代码中插入这样一行来打印日志,蓝图里的printstring会在屏幕和日志里都显示。可以使用%f,d等来获取后边的输入值。对于打映字符串变量,传入需要*

cpp 复制代码
UE_LOG(LogTemp,Warning,TEXT("time:%f"), DeltaTime);
if (GEngine)
{	
	FString Name = GetName();
	FString Message = FString::Printf(TEXT("name:%s"), *Name);
	//显示位置,时间,颜色,文本
	GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Red,Message);
}

Draw a debug sphere

可以将画球的代码封装成宏,放到一个新的头文件里那么在别的代码里也能直接调用,同时引入头文件

Draw a debug Line

cpp 复制代码
if (World)
{	//获取向前的单位向量
	FVector Forward = GetActorForwardVector();
	//地图,起始点,终止点,颜色,时间
	DrawDebugLine(World,Location,Location+Forward*100.f,FColor::Red,false,60.f);
}

Draw a debug point

cpp 复制代码
if (World)
{
	DrawDebugPoint(World, Location + Forward * 100.f,15.f,FColor::Blue,true);
}

将它们都定义成宏来调用

cpp 复制代码
#define DRAW_SPHERE(Location) if(GetWorld()) DrawDebugSphere(GetWorld(), Location,25.f,24,FColor::Red,false,30.f);
#define DRAW_LINE(StartLocation,EndLocation) if(GetWorld()) DrawDebugLine(GetWorld(),StartLocation,EndLocation,FColor::Red,true,-1.f,0,1.f);
#define DRAW_POINT(Location) if(GetWorld()) DrawDebugPoint(GetWorld(),Location,15.f,FColor::Blue,true);
#define DRAW_VECTOR(StartLocation,EndLocation) if(GetWorld())\
	{\
		DrawDebugLine(GetWorld(),StartLocation,EndLocation,FColor::Red,true,-1.f,0,1.f);\
		DrawDebugPoint(GetWorld(), EndLocation, 15.f, FColor::Blue, true);}
cpp 复制代码
void Aitem::BeginPlay()
{
	Super::BeginPlay();

	UE_LOG(LogTemp,Warning,TEXT("BeginPLay"));
	if (GEngine)
	{
		//显示位置,时间,颜色,文本
		GEngine->AddOnScreenDebugMessage(-1,5,FColor::Red,TEXT("hello"));
	}

	//得到所在世界
	UWorld* World = GetWorld();
	//获取组件的位置
	FVector Location = GetActorLocation();
	//获取向前的单位向量
	FVector Forward = GetActorForwardVector();
	
	DRAW_SPHERE(Location);
	/*DRAW_LINE(Location,Location+Forward*100.f);
	DRAW_POINT(Location + Forward * 100.f);*/
	DRAW_VECTOR(Location, Location + Forward * 100.f);
}
相关推荐
aichitang20241 天前
希尔伯特空间中的正交性
人工智能·学习·机器学习·ai·泛函分析
for_ever_love__1 天前
python基础语法学习: 正则表达式
python·学习·正则表达式
佳児素花痴╮1 天前
STM32U575RIT6(USART)学习
stm32·嵌入式硬件·学习
sunshine22 girl1 天前
Angular7,9,学习笔记三 dom操作
笔记·学习·angular
春风解人意1 天前
从零开始学习嵌入式P28----线程
c语言·学习·算法
MartinYeung51 天前
[论文学习]MAC:多智能体宪章学习
人工智能·学习·macos
小+不通文墨1 天前
使用vscode里的U8G2 库编写OLED菜单控制
经验分享·笔记·单片机·嵌入式硬件·学习
摆烂老大1 天前
论文学习 | HESS2025 | 中亚寒区季节水文预报
学习·机器学习·水文
西西弗Sisyphus1 天前
模型训练 不同批次大小与学习率下的训练损失对比(1)
学习·batchsize·learning rate
知识分享小能手1 天前
概理论与数理统计学习教程,从入门到精通,平稳随机过程(27)
学习·数据挖掘·概率论