void Update() { var subsystem = GetSubsystem(); if (subsystem == null) { return; } // Check for new collaboration data while (subsystem.collaborationDataCount > 0) { using (var collaborationData = subsystem.DequeueCollaborationData()) { CollaborationNetworkingIndicator.NotifyHasCollaborationData(); if (m_MCSession.ConnectedPeerCount == 0) { continue; } using (var serializedData = collaborationData.ToSerialized()) using (var data = NSData.CreateWithBytesNoCopy(serializedData.bytes)) { m_MCSession.SendToAllPeers(data, collaborationData.priority == ARCollaborationDataPriority.Critical ? MCSessionSendDataMode.Reliable : MCSessionSendDataMode.Unreliable); CollaborationNetworkingIndicator.NotifyOutgoingDataSent(); } } } // Check for incoming data while (m_MCSession.ReceivedDataQueueSize > 0) { CollaborationNetworkingIndicator.NotifyIncomingDataReceived(); using (var data = m_MCSession.DequeueReceivedData()) using (var collaborationData = new ARCollaborationData(data.Bytes)) { if (collaborationData.valid) { subsystem.UpdateWithCollaborationData(collaborationData); } } } }
void Update() { var subsystem = GetSubsystem(); if (subsystem == null) { return; } // Check for new collaboration data while (subsystem.collaborationDataCount > 0) { using (var collaborationData = subsystem.DequeueCollaborationData()) { CollaborationNetworkingIndicator.NotifyHasCollaborationData(); if (m_MCSession.ConnectedPeerCount == 0) { continue; } using (var serializedData = collaborationData.ToSerialized()) using (var data = NSData.CreateWithBytesNoCopy(serializedData.bytes)) { m_MCSession.SendToAllPeers(data, collaborationData.priority == ARCollaborationDataPriority.Critical ? MCSessionSendDataMode.Reliable : MCSessionSendDataMode.Unreliable); CollaborationNetworkingIndicator.NotifyOutgoingDataSent(); // Only log 'critical' data as 'optional' data tends to come every frame if (collaborationData.priority == ARCollaborationDataPriority.Critical) { Logger.Log($"Sent {data.Length} bytes of collaboration data."); } } } } // Check for incoming data while (m_MCSession.ReceivedDataQueueSize > 0) { CollaborationNetworkingIndicator.NotifyIncomingDataReceived(); using (var data = m_MCSession.DequeueReceivedData()) using (var collaborationData = new ARCollaborationData(data.Bytes)) { if (collaborationData.valid) { subsystem.UpdateWithCollaborationData(collaborationData); if (collaborationData.priority == ARCollaborationDataPriority.Critical) { Logger.Log($"Received {data.Bytes.Length} bytes of collaboration data."); } } else { Logger.Log($"Received {data.Bytes.Length} bytes from remote, but the collaboration data was not valid."); } } } }
public static unsafe NSData AsNSData(this NativeSlice <byte> bytes) => NSData.CreateWithBytesNoCopy(bytes.GetUnsafeReadOnlyPtr(), bytes.Length, false);