예제 #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.Deserializers.Add(typeof(MovePacket), packet => movePacketSerializer.Deserialize(packet));
            packetSerializer.Deserializers.Add(typeof(SpawnPacket), packet => spawnPacketSerializer.Deserialize(packet));
            packetSerializer.Deserializers.Add(typeof(DestroyPacket), packet => new DestroyPacket(destroyPacketSerializer.Deserialize(packet)));
            return(packetSerializer);
        }
예제 #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);
        }