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);
}
相关推荐
Q***f6351 小时前
后端消息队列学习资源,RabbitMQ+Kafka
学习·kafka·rabbitmq
循环过三天2 小时前
7.7、Python-常用内置函数
笔记·python·学习
烤麻辣烫2 小时前
23种设计模式(新手)-5里氏替换原则
java·学习·设计模式·intellij-idea·里氏替换原则
AA陈超4 小时前
ASC学习笔记0007:用于与GameplayAbilities系统交互的核心ActorComponent
c++·笔记·学习·ue5·虚幻引擎
老蒋新思维6 小时前
紧跟郑滢轩,以 “学习力 +” 驱动 AI 与 IP 商业变革
网络·人工智能·学习·tcp/ip·企业管理·创始人ip·创客匠人
做cv的小昊7 小时前
科研论文PPT绘图技巧:绘制任意曲线三角形(胖三角形)并制作效果对比图
经验分享·笔记·学习·微软·ai绘画·数据可视化
小呀小萝卜儿8 小时前
2025-11-14 学习记录--Python-使用sklearn+检测 .csv 文件的编码+读取 .csv 文件
python·学习
月下倩影时8 小时前
视觉学习篇——模型推理部署:从“炼丹”到“上桌”
人工智能·深度学习·学习
河铃旅鹿9 小时前
Android开发-java版:SQLite数据库
android·数据库·笔记·学习·sqlite