Exemplo n.º 1
0
        private PacketSerializer SetupPacketSerializer()
        {
            var packetSerializer     = new PacketSerializer();
            var movePacketSerializer = new MovePacketSerializer(new GuidSerializer(), new Vector3Serializer(),
                                                                new QuaternionSerializer());
            var spawnPacketSerializer = new SpawnPacketSerializer(new GuidSerializer(), new Vector3Serializer(),
                                                                  new QuaternionSerializer());
            var destroyPacketSerializer = new DestroyPacketSerializer();

            packetSerializer.Serializers.Add(typeof(MovePacket), packet => movePacketSerializer.Serialize((MovePacket)packet));
            packetSerializer.Serializers.Add(typeof(SpawnPacket), packet => spawnPacketSerializer.Serialize((SpawnPacket)packet));
            packetSerializer.Serializers.Add(typeof(DestroyPacket), packet => destroyPacketSerializer.Serialize(((DestroyPacket)packet).Id));
            return(packetSerializer);
        }
Exemplo n.º 2
0
        private PacketSerializer GetPacketSerializer()
        {
            var serializer     = new PacketSerializer();
            var spawnConverter = new SpawnPacketSerializer(
                new GuidSerializer(),
                new Vector3Serializer(),
                new QuaternionSerializer());
            var moveConverter = new MovePacketSerializer(
                new GuidSerializer(),
                new Vector3Serializer(),
                new QuaternionSerializer());
            IPacketConverter <DestroyPacket> destroyConverter = new DestroyPacketSerializer();

            serializer.Deserializers.Add(typeof(SpawnPacket), s => spawnConverter.Deserialize(s));
            serializer.Deserializers.Add(typeof(MovePacket), s => moveConverter.Deserialize(s));
            serializer.Deserializers.Add(typeof(DestroyPacket), s => destroyConverter.Deserialize(s));

            serializer.Serializers.Add(typeof(SpawnPacket), packet => spawnConverter.Serialize((SpawnPacket)packet));
            serializer.Serializers.Add(typeof(MovePacket), packet => moveConverter.Serialize((MovePacket)packet));
            serializer.Serializers.Add(typeof(DestroyPacket), packet => destroyConverter.Serialize((DestroyPacket)packet));

            return(serializer);
        }