Пример #1
0
        public void TestCustomRW()
        {
            QuestMessage message = new QuestMessage
            {
                quest = new MockQuest(100)
            };

            byte[]       data     = MessagePackingTest.PackToByteArray(message);
            QuestMessage unpacked = MessagePackingTest.UnpackFromByteArray <QuestMessage>(data);

            Assert.That(unpacked.quest.Id, Is.EqualTo(100));
        }
        public void TestWriteScriptableObject()
        {
            ScriptableObjectMessage message = new ScriptableObjectMessage
            {
                scriptableObject = ScriptableObject.CreateInstance <MyScriptableObject>()
            };

            message.scriptableObject.someData = 10;

            byte[] data = MessagePackingTest.PackToByteArray(message);

            ScriptableObjectMessage unpacked = MessagePackingTest.UnpackFromByteArray <ScriptableObjectMessage>(data);

            Assert.That(unpacked.scriptableObject, Is.Not.Null);
            Assert.That(unpacked.scriptableObject.someData, Is.EqualTo(10));
        }
Пример #3
0
        public void OnDataReceivedInvalidConnectionId()
        {
            // register a message handler
            int called = 0;

            NetworkServer.RegisterHandler <TestMessage1>((conn, msg) => ++ called, false);

            // listen
            NetworkServer.Listen(1);

            // serialize a test message into an arraysegment
            byte[] message = MessagePackingTest.PackToByteArray(new TestMessage1());

            // call transport.OnDataReceived with an invalid connectionId
            // an error log is expected.
            LogAssert.ignoreFailingMessages = true;
            transport.OnServerDataReceived.Invoke(42, new ArraySegment <byte>(message), 0);
            LogAssert.ignoreFailingMessages = false;

            // message handler should never be called
            Assert.That(called, Is.EqualTo(0));
        }