UE4 C++初探
来源:互联网 发布:控制网络流量软件 编辑:程序博客网 时间:2024/06/06 20:34
UE4 C++ 初探
声明:笔者引擎版本为 Unreal Engine 4.16.1
从打印 Hello World 和打印基本变量开始:
工程的建立和基本代码的编写就不再赘述了,网上有很多,我看的是这个:
http://blog.csdn.net/u011326794/article/details/47706959
可以在新建的AActor中的Tick
或者BeginPlay
中使用 GEngine 的 AddOnScreenDebugMessage 进行输出,GEngine 是 UEngine 类型的一个全局指针,被声明在 Engine.h 中,源代码如下:
Engine.h
/** Global engine pointer. Can be 0 so don't use without checking. */extern ENGINE_API class UEngine* GEngine;
在 Engine.cpp 中对 GEngine 进行了初始化:
Engine.cpp
/** * Global engine pointer. Can be 0 so don't use without checking. */ENGINE_API UEngine* GEngine = NULL;
- UE4 在屏幕上打印文字的函数原型如下:
void UEngine::AddOnScreenDebugMessage( uint64 Key, float TimeToDisplay, // 消息在屏幕上显示的时间 FColor DisplayColor, // 文字的颜色 const FString & DebugMessage, // 显示内容 bool bNewrOnTop, const FVector2D & TextScale)void UEngine::AddOnScreenDebugMessage( int32 Key, float TimeToDisplay, // 消息在屏幕上显示的时间 FColor DisplayColor, // 文字的颜色 const FString & DebugMessage, // 显示内容 bool bNewrOnTop, const FVector2D & TextScale)
官方文档的例子在这里:
void AHelloWorldPrinter::Tick(float DeltaTime) { Super::Tick(DeltaTime); //Call parent class Tick static const FString ScrollingMessage(TEXT("Hello World: ")); if (GEngine) { const int32 AlwaysAddKey = -1; // Passing -1 means that we will not try and overwrite an // existing message, just add a new one GEngine->AddOnScreenDebugMessage(AlwaysAddKey, 0.5f, FColor::Yellow, ScrollingMessage + FString::FromInt(MyNumber)); const int32 MyNumberKey = 0; // Not passing -1 so each time through we will update the existing message instead // of making a new one GEngine->AddOnScreenDebugMessage(MyNumberKey, 5.f, FColor::Yellow, FString::FromInt(MyNumber)); ++MyNumber; // Increase MyNumber so we can see it change on screen } }
- 贴出一个Demo:
// Called every framevoid AFloatingActor::Tick(float DeltaTime){ Super::Tick(DeltaTime); FVector NewLocation = GetActorLocation(); if (GEngine) { GEngine->AddOnScreenDebugMessage(-1, 8.f, FColor::Blue, TEXT("Hello World !")); GEngine->AddOnScreenDebugMessage(0, 3.f, FColor::Red, *NewLocation.ToString()); }}
代码说明:
- Tick 在类创建的时候由编辑器自动创建
- GetActorLocation() 用来获取 Actor 当前的 Location,返回的是一个 FVector 结构体类型
- 使用
FVector::ToString()
将 NewLocation 由 FVector 转为 FString
笔者的代码执行结果如下:
- 补充:
- FString 的
FString::SanitizeFloat(double Infloat)
将 double 类型转为 FString 类型,FString::SanitizeFloat()
- FString 的
阅读全文
1 0
- UE4材质初探
- UE4材质初探
- UE4材质初探
- UE4 C++初探
- ue4局域网初探
- UE4材质初探(转载)
- UE4之SlateUI系统初探
- UE4初探及问题总结
- UE4学习之材质系统初探
- 【UE4/C++】切换镜头
- 【UE4/C++】宏的使用
- 【UE4/C++】绑定输入响应
- UE4(C++) 初学备忘录
- ue4-HUD绘制UI(C++)
- UE4 新手常用C++API
- UE4 代理事件(C++)
- UE4 代理事件(C++)
- UE4高级功能--初探超大无缝地图的实现LevelStream
- 单点登录的实现方式
- STM32的CAN总线的接收双FIFO使用方法
- matlab绘图使用
- “#if 0/#if 1 ... #endif”的作用
- centos6版本django部署
- UE4 C++初探
- C#之入门总结_文件_1_13
- android Notification简单用法
- R语言-日期/时间
- Bug2
- leetcode--Populating Next Right Pointers in Each Node
- 如何用JS求DOM树的最大深度?
- 哈密尔顿环
- 链表+启发式合并(bzoj 1483: [HNOI2009]梦幻布丁)