Skip to content

Commit

Permalink
feat: TargetRpc no longer need Target prefix (#2085)
Browse files Browse the repository at this point in the history
Instead of doing
```cs
[TargetRpc]
public void TargetPepe() {}
```

You can now do
```cs
[TargetRpc]
public void Pepe() {}
```

We actually tried to remove them a while ago. The way the weaver worked
back then caused an infinite recursion.

Since the Command rewrite that allows virtuals, this is no longer
a problem.  So we can drop this requirement.

Co-authored-by: Paul Pacheco <paul.pacheco@aa.com>
  • Loading branch information
paulpach and paulpach committed Jul 12, 2020
1 parent b6d1d09 commit d89ac9f
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 25 deletions.
6 changes: 0 additions & 6 deletions Assets/Mirror/Editor/Weaver/Processors/TargetRpcProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,6 @@ public static MethodDefinition ProcessTargetRpcCall(TypeDefinition td, MethodDef

public static bool ProcessMethodsValidateTargetRpc(MethodDefinition md)
{
if (!md.Name.StartsWith("Target"))
{
Weaver.Error($"{md.Name} must start with Target. Consider renaming it to Target{md.Name}", md);
return false;
}

if (md.IsStatic)
{
Weaver.Error($"{md.Name} must not be static", md);
Expand Down
4 changes: 2 additions & 2 deletions Assets/Mirror/Tests/Editor/TargetRpcTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class TargetRpcBehaviour : NetworkBehaviour
public event Action<int> onSendInt;

[TargetRpc]
public void TargetSendInt(int someInt)
public void SendInt(int someInt)
{
onSendInt?.Invoke(someInt);
}
Expand All @@ -29,7 +29,7 @@ public void RpcIsCalled()
callCount++;
Assert.That(incomingInt, Is.EqualTo(someInt));
};
hostBehaviour.TargetSendInt(someInt);
hostBehaviour.SendInt(someInt);
ProcessMessages();
Assert.That(callCount, Is.EqualTo(1));
}
Expand Down
7 changes: 0 additions & 7 deletions Assets/Mirror/Tests/Editor/Weaver/WeaverTargetRpcTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ public void TargetRpcValid()
Assert.That(weaverErrors, Is.Empty);
}

[Test]
public void ErrorWhenMethodDoesNotStartWithTarget()
{
Assert.That(weaverErrors, Contains.Item("DoesntStartWithTarget must start with Target. Consider renaming it to TargetDoesntStartWithTarget " +
"(at System.Void WeaverTargetRpcTests.ErrorWhenMethodDoesNotStartWithTarget.ErrorWhenMethodDoesNotStartWithTarget::DoesntStartWithTarget(Mirror.NetworkConnection))"));
}

[Test]
public void ErrorWhenTargetRpcIsStatic()
{
Expand Down

This file was deleted.

0 comments on commit d89ac9f

Please sign in to comment.