- Client to Server
UFUNCTION(reliable, server, WithValidation) ServerFun(); void ClientToServer() { if(Role<Role_Authotity) { ServerFun(); } //DoSomething } void ServerFun_Impletation() { ClientToServer(); } void ServerFun_Validate() { return true; }
- Server to client
UPROPERTY(Transient, ReplicatedUsing=OnRep_State) bool State:1; /** [client] state change */ UFUNCTION() void OnRep_State(); void Main() { if (Role == ROLE_Authority) { //ServerToClient在server中执行 ServerToClient(); } } void ServerToClient() { //Dosomething //state 改变 state = !state; } void OnRep_State() { //ServerToClient在client中执行
//这里可能会计算一些东西,因为这个流程是从server端开始的,后续的执行可能需要一些数据是server端有而client端并没有的,所有在这里会根据现有条件重新计算需要的数据 ServerToClient(); }
- 通过上边两种方式,可以实现client到server和server到client的沟通
- 方法在server端执行或者在client端执行
// play FX locally if (GetNetMode() != NM_DedicatedServer) { //dosomething }
- 属性复制可以设置条件复制,只同步到romote client ,DOREPLIFETIME_CONDITION( AShooterWeapon_Instant, HitNotify, COND_SkipOwner );