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);
}
相关推荐
2303_Alpha2 天前
SpringBoot
笔记·学习
萘柰奈2 天前
Unity学习----【进阶】TextMeshPro学习(三)--进阶知识点(TMP基础设置,材质球相关,两个辅助工具类)
学习·unity
沐矢羽2 天前
Tomcat PUT方法任意写文件漏洞学习
学习·tomcat
好奇龙猫2 天前
日语学习-日语知识点小记-进阶-JLPT-N1阶段蓝宝书,共120语法(10):91-100语法+考え方13
学习
向阳花开_miemie2 天前
Android音频学习(十八)——混音流程
学习·音视频
工大一只猿2 天前
51单片机学习
嵌入式硬件·学习·51单片机
c0d1ng2 天前
量子计算学习(第十四周周报)
学习·量子计算
Hello_Embed2 天前
STM32HAL 快速入门(二十):UART 中断改进 —— 环形缓冲区解决数据丢失
笔记·stm32·单片机·学习·嵌入式软件
咸甜适中2 天前
rust语言 (1.88) 学习笔记:客户端和服务器端同在一个项目中
笔记·学习·rust
Magnetic_h2 天前
【iOS】设计模式复习
笔记·学习·ios·设计模式·objective-c·cocoa