Beispiel #1
0
        private void UpdateClient()
        {
            var messages = _networking.GetOnlineMessages();

            foreach (var message in messages)
            {
                var packet = _serializer.Deserialize(message);
                if (packet is SpawnPacket)
                {
                    var spawnPacket = (SpawnPacket)packet;
                    CreatePrefab(spawnPacket.Id, spawnPacket.Position, spawnPacket.Rotation);
                }
            }
        }
 protected override MovePacket DeserializeFromFragments(string[] split)
 {
     return(new MovePacket(
                _guidSerializer.Deserialize(split[0]),
                _vectorSerializer.Deserialize(split[1]),
                _quaternionSerializer.Deserialize(split[2]),
                float.Parse(split[3], _floatFormat)));
 }
 protected override SpawnPacket DeserializeFromFragments(string[] split)
 {
     return(new SpawnPacket(
                _guidSerializer.Deserialize(split[0]),
                _vectorSerializer.Deserialize(split[1]),
                _quaternionSerializer.Deserialize(split[2]),
                split[3]));
 }
        public void CanDeserializeSpawnPacket()
        {
            _mockGuidSerializer.Deserialize("A").Returns(_packet.Id);
            _mockVectorSerializer.Deserialize("B").Returns(_packet.Position);
            _mockQuaternionSerializer.Deserialize("C").Returns(_packet.Rotation);

            Check.That(_serializer.Deserialize(string.Format("A{0}B{0}C{0}Cat", Environment.NewLine)))
            .IsEqualTo(_packet);
        }
Beispiel #5
0
 public void Setup()
 {
     _mockPacket             = new MockPacket();
     _packetHeader           = typeof(MockPacket).AssemblyQualifiedName;
     _serializatedMockPacket = "Dummy";
     _mockConverter          = Substitute.For <IPacketConverter <MockPacket> >();
     _mockConverter.Serialize(_mockPacket).Returns(_serializatedMockPacket);
     _mockConverter.Deserialize(_serializatedMockPacket).Returns(_mockPacket);
     _serializer = new PacketSerializer();
 }
Beispiel #6
0
        public void WhenTypeIsSupported_DeserializationIsSuccessful()
        {
            _serializer.Deserializers.Add(typeof(MockPacket), serializedPacket => _mockConverter.Deserialize(serializedPacket));

            Check.That(_serializer.Deserialize(_packetHeader + "|" + _serializatedMockPacket)).IsEqualTo(_mockPacket);
        }
 public void CanDeserializeMovePacket()
 {
     Check.That(_serializer.Deserialize(_packet.Id.ToString("N")))
     .IsEqualTo(_packet);
 }