lua ue_Bluelua支持在lua中重写UE4网络事件

06d64bcdb2a83646f41c94092b31dab3.png

最近抽空把 Bluelua 计划的最后一部分功能内容做完了,就是在 lua 中重载 UE4 中的网络事件,这样就可以直接在 lua 中重写网络相关的逻辑了。还有就是将之前重载纯蓝图函数和事件几个崩溃修复了。网络相关的重写示例在 BlueluaDemo 的 NetTest 文件夹中

UE4 中网络事件分两种,一种是 C++ 中的网络事件,就是在 UFUNCTION 中带上 Server/NetMulticast/Client 关键字,另一种是在蓝图中,创建一个 Custom Event,然后在这个事件的复制属性中选择 Run On Server/Multicast/Run on owning Client,如图

f11d97f65e05e20b9173f3f64802ff95.png

这两种是互相独立的,也就是 C++ 中的 Server/NetMulticast/Client 函数是无法在蓝图中进行重写,所以如果有这样的需求就需要在 C++ 的 Server/NetMulticast/Client 函数中去调用其它 BlueprintNativeEvent/BlueprintImplementable 函数,将这个事件抛到蓝图中,略显麻烦。Bluelua 中就不用这么麻烦了,现在可以直接在 lua 中分别重写这两类网络事件

重写 C++ 网络事件

首先在 ANetCharacter 的 C++ 类中定义三个函数,一个可复制属性和属性的修改通知函数

UFUNCTION(Unreliable, Server, WithValidation)
void TestNativeServerFunction();

UFUNCTION(Unreliable, NetMulticast)
void TestNativeNetMulticastFunction();

UFUNCTION(Unreliable, Client)
void TestNativeClientFunction();

UPROPERTY(ReplicatedUsing=OnRep_Counter)
int32 Counter;

UFUNCTION(BlueprintNativeEvent)
void OnRep_Counter();

实现这几个函数

void ANetCharacter::TestNativeClientFunction_Implementation()
{
    
    UE_LOG(LogTemp, Display, TEXT("%sTestNativeClientFunction get called"), *GetPrefix(this));
}

void ANetCharacter::TestNativeNetMulticastFunction_Implementation()
{
    
    UE_LOG(LogTemp, Display, TEXT("%sTestNativeNetMulticastFunction get called"), *GetPrefix(this));
}

void ANetCharacter::TestNativeServerFunction_Implementation()
{
    
    UE_LOG(LogTemp, Display, TEXT("%sTestNativeServerFunction get called"), *GetPrefix(this));

    TestNativeNetMulticastFunction(); // will run on local and remote
    TestNativeClientFunction(); // will run on remote
}

bool ANetCharacter::TestNativeServerFunction_Validate()
{
    
    return true;
}

void ANetCharacter::OnRep_Counter_Implementation()
{
    
    UE_LOG(LogTemp, Displ
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值