mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
NetworkServerTest: HideForConnection
This commit is contained in:
parent
9bdfb676e3
commit
038e3c1969
@ -899,6 +899,50 @@ public void ShowForConnection()
|
|||||||
GameObject.DestroyImmediate(identity.gameObject);
|
GameObject.DestroyImmediate(identity.gameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void HideForConnection()
|
||||||
|
{
|
||||||
|
// message handlers
|
||||||
|
NetworkServer.RegisterHandler<ConnectMessage>((conn, msg) => {}, false);
|
||||||
|
NetworkServer.RegisterHandler<DisconnectMessage>((conn, msg) => {}, false);
|
||||||
|
NetworkServer.RegisterHandler<ErrorMessage>((conn, msg) => {}, false);
|
||||||
|
|
||||||
|
// listen
|
||||||
|
NetworkServer.Listen(1);
|
||||||
|
Assert.That(NetworkServer.connections.Count, Is.EqualTo(0));
|
||||||
|
|
||||||
|
// add connection
|
||||||
|
ULocalConnectionToClient connection = new ULocalConnectionToClient();
|
||||||
|
connection.isReady = true; // required for ShowForConnection
|
||||||
|
connection.connectionToServer = new ULocalConnectionToServer();
|
||||||
|
// set a client handler
|
||||||
|
int called = 0;
|
||||||
|
connection.connectionToServer.SetHandlers(new Dictionary<int,NetworkMessageDelegate>()
|
||||||
|
{
|
||||||
|
{ MessagePacker.GetId<ObjectHideMessage>(), (msg => ++called) }
|
||||||
|
});
|
||||||
|
NetworkServer.AddConnection(connection);
|
||||||
|
|
||||||
|
// create a gameobject and networkidentity and some unique values
|
||||||
|
NetworkIdentity identity = new GameObject().AddComponent<NetworkIdentity>();
|
||||||
|
identity.connectionToClient = connection;
|
||||||
|
|
||||||
|
// call HideForConnection
|
||||||
|
NetworkServer.HideForConnection(identity, connection);
|
||||||
|
|
||||||
|
// update local connection once so that the incoming queue is processed
|
||||||
|
connection.connectionToServer.Update();
|
||||||
|
|
||||||
|
// was it sent to and handled by the connection?
|
||||||
|
Assert.That(called, Is.EqualTo(1));
|
||||||
|
|
||||||
|
// clean up
|
||||||
|
NetworkServer.Shutdown();
|
||||||
|
// destroy GO after shutdown, otherwise isServer is true in OnDestroy and it tries to call
|
||||||
|
// GameObject.Destroy (but we need DestroyImmediate in Editor)
|
||||||
|
GameObject.DestroyImmediate(identity.gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void ShutdownCleanupTest()
|
public void ShutdownCleanupTest()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user