Skip to content

Commit

Permalink
feat: adding excludeHost to ClientRpc
Browse files Browse the repository at this point in the history
can be used to avoid rpc being invoked locally on host
  • Loading branch information
James-Frowen committed Mar 12, 2024
1 parent 555ac70 commit a35ed9d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Assets/Mirage/Runtime/CustomAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public class ClientRpcAttribute : Attribute
public Channel channel = Channel.Reliable;
public RpcTarget target = RpcTarget.Observers;
public bool excludeOwner;
/// <summary>stops method being called on host/server</summary>
public bool excludeHost;
}

/// <summary>
Expand Down
4 changes: 3 additions & 1 deletion Assets/Mirage/Weaver/Processors/ClientRpcProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ private MethodDefinition GenerateStub(MethodDefinition md, CustomAttribute clien
var target = clientRpcAttr.GetField(nameof(ClientRpcAttribute.target), RpcTarget.Observers);
var channel = clientRpcAttr.GetField(nameof(ClientRpcAttribute.channel), 0);
var excludeOwner = clientRpcAttr.GetField(nameof(ClientRpcAttribute.excludeOwner), false);
var excludeHost = clientRpcAttr.GetField(nameof(ClientRpcAttribute.excludeHost), false);

var rpc = SubstituteMethod(md);

Expand All @@ -89,7 +90,8 @@ private MethodDefinition GenerateStub(MethodDefinition md, CustomAttribute clien
// {
// call the body
// }
CallBody(worker, rpc, target, excludeOwner);
if (!excludeHost)
CallBody(worker, rpc, target, excludeOwner);

// NetworkWriter writer = NetworkWriterPool.GetWriter()
var writer = md.AddLocal<PooledNetworkWriter>();
Expand Down

0 comments on commit a35ed9d

Please sign in to comment.