前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >UE4学习笔记: Functions

UE4学习笔记: Functions

作者头像
逍遥剑客
发布2018-05-21 11:33:18
2.5K0
发布2018-05-21 11:33:18
举报

函数声明

UE4中有两种函数, 一种是传统的C++函数, 一种是UFunction. UFunction通过加入一些描述符来支持一些特殊功能

代码语言:javascript
复制
UFUNCTION([specifier, specifier, ...], [meta(key=value, key=value, ...)])
ReturnType FunctionName([Parameter, Parameter, ...])

主要有几种应用:

  1. 在Blueprint中调用
  2. 做为delegate, 如与按键消息进行绑定
  3. 网络回调和数据同步
  4. 做为命令行的指令执行, 同UE3的exec关键字

函数说明符

  • Blueprint相关
    • BlueprintAuthorithOnly: 没有网格授权的话不会在blueprint中执行
    • BlueprintCallable: 可以在blueprint中执行
    • BlueprintCosmetic: 表现函数, 不会在服务器执行
    • BlueprintImplementableEvent: 可以在blueprint中重写
    • BlueprintNativeEvent: 设计为被blueprint重写, 但是仍然包含native的实现
    • BlueprintPure: 不会影响自身对象
  • Network相关
    • Client: 只在客户端执行
    • Server: 只在服务端执行
    • NetMulticast: 会在服务器和所有客户端执行
    • Reliable: 函数执行通过网络进行复制, 并且是可靠的
    • Unreliable: 函数在复制执行时可能失败
  • Editor相关
    • Category
  • 其它
    • CustomThunk: 提供自定义的execFoo, 而不是生成的
    • Exec: 可以在命令行中被执行

元数据说明符

  • BlueprintInternalUseOnly
  • BlueprintProtected: 只在blueprint中调用
  • DeprecatedFunction
  • DeprecationMessage
  • UnsafeDuringActorConstruction

函数参数说明符

  • Out: 传引用
  • Optional: 可选, 取默认值

委托(Delegate)

代码语言:javascript
复制
DECLARE_DELEGATE_OneParam( FStringDelegate, FString );
代码语言:javascript
复制
FSharedRef< FLogWriter > LogWriter( new FLogWriter() );

WriteToLogDelegate.BindSP( LogWriter, &FLogWriter::WriteToLog );
代码语言:javascript
复制
WriteToLogDelegate.Execute( TEXT( "Delegates are spiffy!" ) );

建议Delegate传递时使用引用, 避免传值引起内存分配

multi-cast与event的区别只有声明event的类本身可以调用event的Broadcast, IsBound, Clear函数

dynamic delegate是用函数名进行绑定, 所以可以进行序列化, 但速度相对较慢

定时器(Timer)

代码语言:javascript
复制
GetWorldTimerManager().SetTimer(this, &AMatineeActor::CheckPriorityRefresh, 1.0f, true);
代码语言:javascript
复制
GetWorldTimerManager().ClearTimer(this, &AMatineeActor::CheckPriorityRefresh);
代码语言:javascript
复制
GetWorldTimerManager().IsTimerActive(this, &APlayerController::DelayedPrepareMapChange)

Timer不是线程安全的, 只能在游戏线程使用

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2015年02月15日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档