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);
}
相关推荐
繁花与尘埃19 分钟前
CSS引入方式(本文为个人学习笔记,内容整理自哔哩哔哩UP主【非学者勿扰】的公开课程。 > 所有知识点归属原作者,仅作非商业用途分享)
css·笔记·学习
Century_Dragon27 分钟前
新能源汽车故障诊断与排除虚拟实训软件:赋能职业教育利器
学习
m0_626535203 小时前
数据结构学习,一些知识点
数据结构·学习
猫梦www3 小时前
关于Mysql的学习三(事务)
学习·mysql
Yurko134 小时前
【C语言】程序控制结构
c语言·开发语言·学习
丰锋ff5 小时前
英一2013年真题学习笔记
笔记·学习
帅帅dl5 小时前
Git学习-5
学习
能不能别报错5 小时前
K8s学习笔记(二十二) 网络组件 Flannel与Calico
笔记·学习·kubernetes
老邓计算机毕设6 小时前
SSM基于的少儿编程学习系统2lsiy(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。
学习·ssm 框架·少儿编程学习系统·功能模块设计
阿民不加班6 小时前
【React】打卡笔记,入门学习01:点击事件
笔记·学习·react.js