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); }
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); }