-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: weaver now processes multiple SyncEvent per class (#2055)
* weaver test for mutlitple events * tests for multiple sync events in 1 class * removing break so that multiple events will be proccessed It seems like this break was here because unet used foreach CustomAttributes but mirror uses GetCustomAttribute
- Loading branch information
1 parent
c91308f
commit b316b35
Showing
6 changed files
with
137 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
using NUnit.Framework; | ||
using UnityEngine; | ||
|
||
namespace Mirror.Tests.RemoteAttrributeTest | ||
{ | ||
public delegate void MySyncEventDelegate(int someNumber); | ||
public delegate void MySyncEventDelegate2(int someNumber, Vector3 somePosition); | ||
|
||
class SyncEventBehaviour : NetworkBehaviour | ||
{ | ||
[SyncEvent] | ||
public event MySyncEventDelegate EventOnly; | ||
|
||
public void CallEvent(int i) | ||
{ | ||
EventOnly.Invoke(i); | ||
} | ||
} | ||
|
||
class MultipleSyncEventBehaviour : NetworkBehaviour | ||
{ | ||
[SyncEvent] | ||
public event MySyncEventDelegate EventFirst; | ||
|
||
[SyncEvent] | ||
public event MySyncEventDelegate2 EventSecond; | ||
|
||
public void CallEvent1(int i) | ||
{ | ||
EventFirst?.Invoke(i); | ||
} | ||
|
||
public void CallEvent2(int i, Vector3 v) | ||
{ | ||
EventSecond?.Invoke(i, v); | ||
} | ||
} | ||
|
||
public class SyncEventTest : RemoteTestBase | ||
{ | ||
[Test] | ||
public void FirstEventIsCalled() | ||
{ | ||
SyncEventBehaviour serverBehaviour = CreateHostObject<SyncEventBehaviour>(true); | ||
SyncEventBehaviour clientBehaviour = CreateHostObject<SyncEventBehaviour>(true); | ||
|
||
// set the clientBehaviour has the serverBehaviour's Id | ||
clientBehaviour.netIdentity.netId = serverBehaviour.netId; | ||
NetworkIdentity.spawned[serverBehaviour.netId] = clientBehaviour.netIdentity; | ||
|
||
const int someInt = 20; | ||
|
||
int callCount = 0; | ||
clientBehaviour.EventOnly += incomingInt => | ||
{ | ||
callCount++; | ||
Assert.That(incomingInt, Is.EqualTo(someInt)); | ||
}; | ||
serverBehaviour.CallEvent(someInt); | ||
ProcessMessages(); | ||
Assert.That(callCount, Is.EqualTo(1)); | ||
} | ||
|
||
[Test] | ||
public void SecondEventIsCalled() | ||
{ | ||
MultipleSyncEventBehaviour serverBehaviour = CreateHostObject<MultipleSyncEventBehaviour>(true); | ||
MultipleSyncEventBehaviour clientBehaviour = CreateHostObject<MultipleSyncEventBehaviour>(true); | ||
|
||
// set the clientBehaviour has the serverBehaviour's Id | ||
clientBehaviour.netIdentity.netId = serverBehaviour.netId; | ||
NetworkIdentity.spawned[serverBehaviour.netId] = clientBehaviour.netIdentity; | ||
|
||
const int someInt1 = 20; | ||
const int someInt2 = 25; | ||
Vector3 someVector = Vector3.left; | ||
|
||
int callCount1 = 0; | ||
int callCount2 = 0; | ||
clientBehaviour.EventFirst += incomingInt => | ||
{ | ||
callCount1++; | ||
Assert.That(incomingInt, Is.EqualTo(someInt1)); | ||
}; | ||
clientBehaviour.EventSecond += (incomingInt, incomingVector) => | ||
{ | ||
callCount2++; | ||
Assert.That(incomingInt, Is.EqualTo(someInt2)); | ||
Assert.That(incomingVector, Is.EqualTo(someVector)); | ||
}; | ||
|
||
serverBehaviour.CallEvent1(someInt1); | ||
ProcessMessages(); | ||
Assert.That(callCount1, Is.EqualTo(1)); | ||
Assert.That(callCount2, Is.EqualTo(0)); | ||
|
||
serverBehaviour.CallEvent2(someInt2, someVector); | ||
ProcessMessages(); | ||
Assert.That(callCount1, Is.EqualTo(1)); | ||
Assert.That(callCount2, Is.EqualTo(1)); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
Assets/Mirror/Tests/Editor/Weaver/WeaverSyncEventTests~/MultipleSyncEvent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Mirror; | ||
|
||
namespace WeaverSyncEventTests.MultipleSyncEvent | ||
{ | ||
class MultipleSyncEvent : NetworkBehaviour | ||
{ | ||
public delegate void MySyncEventDelegate(); | ||
public delegate void MySyncEventDelegate2(int someNumber); | ||
|
||
[SyncEvent] | ||
public event MySyncEventDelegate EventDoCoolThingsWithExcitingPeople; | ||
|
||
[SyncEvent] | ||
public event MySyncEventDelegate2 EventDoMoreCoolThingsWithExcitingPeople; | ||
} | ||
} |