12,判断isDead从蓝图转到C++
·
isDead在蓝图中是网络复制,并通知客户端,目前这个是单机游戏,但是为了扩展,还是保留相关属性,在这个通知函数加上一个蓝图和C++都可以调用的函数,暂时在蓝图实现
//是否死亡
// ReplicatedUsing 指定值变化时触发的回调函数
UPROPERTY(ReplicatedUsing = OnRep_IsDead)
bool IsDead = false;
//===== 死亡状态接口 =====
UFUNCTION(BlueprintCallable, Category = "Combat")
void SetIsDead(bool bNewState);
UFUNCTION(BlueprintPure, Category = "Combat")
bool GetIsDead() const;
// Rep 回调函数声明(引擎固定格式 UFUNCTION())
UFUNCTION()
void OnRep_IsDead();
// 网络复制注册函数声明
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Combat|Death")
void OnIsDeadChanged();
virtual void OnIsDeadChanged_Implementation() {}
void AMyPaperZDCharacter::SetIsDead(bool bNewState)
{
// 可选:相同状态跳过,避免重复赋值
if (IsDead == bNewState)
return;
IsDead = bNewState;
}
bool AMyPaperZDCharacter::GetIsDead() const
{
return IsDead;
}
void AMyPaperZDCharacter::OnRep_IsDead()
{
OnIsDeadChanged();
}
void AMyPaperZDCharacter::GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
// 注册 IsDead 为网络同步变量
DOREPLIFETIME(AMyPaperZDCharacter, IsDead);
}
替换过程












引用为0,去掉蓝图中的isDead成员变量
更多推荐


所有评论(0)