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;
            }
        }
        private async void SendWorldMapAsync()
        {
            ARWorldMap worldMap = await GetARWorldMapAsync();

            PackableARWorldMap   packableARWorldMap   = (PackableARWorldMap)worldMap;
            NetworkMessageStruct networkMessageStruct = new NetworkMessageStruct
            {
                Type    = MessageType.WorldMap,
                Message = packableARWorldMap.ARWorldMapData
            };

            SendMessage(networkMessageStruct);
        }
        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)));
        }
        public override void SendAnchor(ARPlane plane)
        {
            // todo: all byte to "stream" conversion should be made more effecient through less copying
            byte[] planeTrackableId1 = BitConverter.GetBytes(plane.trackableId.subId1);
            byte[] planeTrackableId2 = BitConverter.GetBytes(plane.trackableId.subId2);
            byte[] messagePacket     = new byte[planeTrackableId1.Length + planeTrackableId2.Length];
            planeTrackableId1.CopyTo(messagePacket, 0);
            planeTrackableId2.CopyTo(messagePacket, planeTrackableId1.Length);
            NetworkMessageStruct networkMessageStruct = new NetworkMessageStruct
            {
                Type    = MessageType.Anchor,
                Message = messagePacket
            };

            SendMessage(networkMessageStruct);
        }
 protected virtual void SendMessage(NetworkMessageStruct message)
 {
     throw new NotImplementedException();
 }
 protected override void SendMessage(NetworkMessageStruct message)
 {
     Debug.Log("Send message to all friends");
     UnityMCSessionNativeInterface.GetMcSessionNativeInterface().SendToAllPeers(message.Serialize());
 }
 public override void SendMessage(NetworkMessageStruct message)
 {
     _wifiDirectImpl.sendMessage(message);
 }