mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
feature: remote call overloads are now allowed for [TargetRpc] too. they are possible now due to 0cdeccbe71
using .FullName instead of .Name
This commit is contained in:
parent
b6f4c641de
commit
30a7e1d576
@ -1161,12 +1161,6 @@ void ProcessTargetRpc(HashSet<string> names, MethodDefinition md, CustomAttribut
|
||||
if (!ValidateRemoteCallAndParameters(md, RemoteCallType.TargetRpc, ref WeavingFailed))
|
||||
return;
|
||||
|
||||
if (names.Contains(md.Name))
|
||||
{
|
||||
Log.Error($"Duplicate Target Rpc name {md.Name}", md);
|
||||
WeavingFailed = true;
|
||||
return;
|
||||
}
|
||||
names.Add(md.Name);
|
||||
targetRpcs.Add(md);
|
||||
|
||||
|
@ -22,6 +22,18 @@ public void SendIntWithTarget(NetworkConnection target, int someInt)
|
||||
}
|
||||
}
|
||||
|
||||
class TargetRpcOverloads : NetworkBehaviour
|
||||
{
|
||||
public int firstCalled = 0;
|
||||
public int secondCalled = 0;
|
||||
|
||||
[TargetRpc]
|
||||
public void TargetRpcTest(int _) => ++firstCalled;
|
||||
|
||||
[TargetRpc]
|
||||
public void TargetRpcTest(string _) => ++secondCalled;
|
||||
}
|
||||
|
||||
public class TargetRpcTest : RemoteTestBase
|
||||
{
|
||||
[Test]
|
||||
@ -149,5 +161,21 @@ public void ErrorForTargetRpcWhenObjectNotSpawned()
|
||||
LogAssert.Expect(LogType.Warning, $"TargetRpc System.Void Mirror.Tests.RemoteAttrributeTest.TargetRpcBehaviour::SendInt(System.Int32) called on {hostBehaviour.name} but that object has not been spawned or has been unspawned");
|
||||
hostBehaviour.SendInt(someInt);
|
||||
}
|
||||
|
||||
// RemoteCalls uses md.FullName which gives us the full command/rpc name
|
||||
// like "System.Void Mirror.Tests.RemoteAttrributeTest.AuthorityBehaviour::SendInt(System.Int32)"
|
||||
// which means overloads with same name but different types should work.
|
||||
[Test]
|
||||
public void TargetRpcOverload()
|
||||
{
|
||||
// spawn with owner
|
||||
CreateNetworkedAndSpawn(out GameObject _, out NetworkIdentity _, out TargetRpcOverloads hostBehaviour, NetworkServer.localConnection);
|
||||
|
||||
hostBehaviour.TargetRpcTest(42);
|
||||
hostBehaviour.TargetRpcTest("A");
|
||||
ProcessMessages();
|
||||
Assert.That(hostBehaviour.firstCalled, Is.EqualTo(1));
|
||||
Assert.That(hostBehaviour.secondCalled, Is.EqualTo(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -124,8 +124,7 @@ public void NetworkBehaviourTargetRpcParamNetworkConnection()
|
||||
[Test]
|
||||
public void NetworkBehaviourTargetRpcDuplicateName()
|
||||
{
|
||||
HasError("Duplicate Target Rpc name TargetRpcCantHaveSameName",
|
||||
"System.Void WeaverNetworkBehaviourTests.NetworkBehaviourTargetRpcDuplicateName.NetworkBehaviourTargetRpcDuplicateName::TargetRpcCantHaveSameName(Mirror.NetworkConnection,System.Int32,System.Int32)");
|
||||
IsSuccess();
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -4,10 +4,11 @@ namespace WeaverNetworkBehaviourTests.NetworkBehaviourTargetRpcDuplicateName
|
||||
{
|
||||
class NetworkBehaviourTargetRpcDuplicateName : NetworkBehaviour
|
||||
{
|
||||
// remote call overloads are now supported
|
||||
[TargetRpc]
|
||||
public void TargetRpcCantHaveSameName(NetworkConnection monkeyCon, int abc) { }
|
||||
public void TargetRpcWithSameName(NetworkConnection monkeyCon, int abc) { }
|
||||
|
||||
[TargetRpc]
|
||||
public void TargetRpcCantHaveSameName(NetworkConnection monkeyCon, int abc, int def) { }
|
||||
public void TargetRpcWithSameName(NetworkConnection monkeyCon, int abc, int def) { }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user