private void OnDataReceivedEvent(byte[] obj) { NetworkMessageStruct networkMessage = NetworkMessageStruct.Deserialize(obj); switch (networkMessage.Type) { case MessageType.ColorChange: DeserializeColorAndSendEvent(networkMessage.Message); break; case MessageType.WorldMap: Debug.Log("recieved world map"); ARWorldMap arWorldMap = (ARWorldMap) new PackableARWorldMap(networkMessage.Message); RestartSessionWithWorldMap(arWorldMap); break; case MessageType.Anchor: Debug.Log("recieved anchor"); ulong trackableId1 = BitConverter.ToUInt64(networkMessage.Message, 0); ulong trackableId2 = BitConverter.ToUInt64(networkMessage.Message, sizeof(ulong)); TrackableId trackableId = new TrackableId(trackableId1, trackableId2); AnchorRecieved?.Invoke(trackableId); break; case MessageType.SpawnedObject: DeserializeObjectSpawnAndSendEvent(networkMessage.Message); break; } }
public bool TestNetworkPacketSerialization() { Color sourceColor = new Color(.1f, .2f, .3f); NetworkMessageStruct networkMessageStruct = new NetworkMessageStruct { Type = MessageType.ColorChange, Message = SerializeColor(sourceColor) }; byte[] serializeMessage = networkMessageStruct.Serialize(); NetworkMessageStruct deserializedStruct = NetworkMessageStruct.Deserialize(serializeMessage); return(networkMessageStruct.Type == deserializedStruct.Type && VerifyColor(sourceColor, DeserializeColor(deserializedStruct.Message))); }