NetworkServerTest: HideForConnection

This commit is contained in:
vis2k 2020-02-26 10:14:42 +01:00
parent 9bdfb676e3
commit 038e3c1969

View File

@ -899,6 +899,50 @@ public void ShowForConnection()
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]
public void ShutdownCleanupTest()
{