private void SendCoordinateAssigned(string coordinateId) { DebugLog($"Sending coordinate assignment: {coordinateId}"); peerConnection.SendData(writer => { writer.Write(MarkerVisualLocalizationSettings.CoordinateAssignedHeader); writer.Write(coordinateId); }); }
/// <inheritdoc/> public override async Task <ISpatialCoordinate> LocalizeAsync(CancellationToken cancellationToken) { ISpatialCoordinate coordinateToReturn = null; using (var cancellableCTS = CancellationTokenSource.CreateLinkedTokenSource(defaultCancellationToken, cancellationToken)) { if (configuration.IsCoordinateCreator) { localizer.DebugLog("User getting initialized coordinate"); coordinateToReturn = await coordinateService.TryCreateCoordinateAsync(localizer.anchorPosition, Quaternion.Euler(localizer.anchorRotation), cancellableCTS.Token); if (coordinateToReturn != null) { localizer.DebugLog($"Sending coordinate id: {coordinateToReturn.Id}"); peerConnection.SendData(writer => writer.Write(coordinateToReturn.Id)); localizer.DebugLog("Message sent."); } else { Debug.LogError("Coordinate discovery returned null coordinate"); return(null); } } else { localizer.DebugLog("Non-host waiting for coord id to be sent over"); string coordinateIdentifier = await coordinateIdentifierTaskSource.Task.Unless(cancellableCTS.Token); if (!cancellableCTS.Token.IsCancellationRequested) { localizer.DebugLog($"Coordinate id: {coordinateIdentifier}, starting discovery."); if (await coordinateService.TryDiscoverCoordinatesAsync(cancellableCTS.Token, coordinateIdentifier)) { localizer.DebugLog("Discovery complete, retrieving reference to ISpatialCoordinate"); if (!coordinateService.TryGetKnownCoordinate(coordinateIdentifier, out coordinateToReturn)) { Debug.LogError("We discovered, but for some reason failed to get coordinate from service."); } } else { Debug.LogError("Failed to discover spatial coordinate."); } } } } return(coordinateToReturn); }
private bool TrySendMarkerVisualDiscoveryMessage() { if (localizer.markerVisual.TryGetMaxSupportedMarkerId(out var maxId)) { DebugLog($"Sending maximum id for discovery: {maxId}"); peerConnection?.SendData(writer => { writer.Write(MarkerVisualLocalizationSettings.DiscoveryHeader); writer.Write(maxId); }); return(true); } DebugLog("Unable to obtain max id from marker visual"); return(false); }