コード例 #1
0
        public Task <bool> RunRemoteLocalizationAsync(INetworkConnection connection, Guid spatialLocalizerID, ISpatialLocalizationSettings settings)
        {
            DebugLog($"Initiating remote localization: {connection.ToString()}, {spatialLocalizerID.ToString()}");
            if (remoteLocalizationSessions.TryGetValue(connection, out var currentCompletionSource))
            {
                DebugLog($"Canceling existing remote localization session: {connection.ToString()}");
                currentCompletionSource.TrySetCanceled();
                remoteLocalizationSessions.Remove(connection);
            }

            TaskCompletionSource <bool> taskCompletionSource = new TaskCompletionSource <bool>();

            remoteLocalizationSessions.Add(connection, taskCompletionSource);

            using (MemoryStream stream = new MemoryStream())
                using (BinaryWriter message = new BinaryWriter(stream))
                {
                    message.Write(LocalizeCommand);
                    message.Write(spatialLocalizerID);
                    settings.Serialize(message);

                    byte[] data = stream.ToArray();
                    connection.Send(ref data);
                }

            return(taskCompletionSource.Task);
        }
コード例 #2
0
        private void OnLocalizationCompleteMessageReceived(INetworkConnection connection, string command, BinaryReader reader, int remainingDataSize)
        {
            bool localizationSuccessful = reader.ReadBoolean();

            if (!remoteLocalizationSessions.TryGetValue(connection, out TaskCompletionSource <bool> taskSource))
            {
                DebugLog($"Remote session from connection {connection.ToString()} completed but we were no longer tracking that session");
                return;
            }

            DebugLog($"Localization completed message received: {connection.ToString()}");
            remoteLocalizationSessions.Remove(connection);
            taskSource.TrySetResult(localizationSuccessful);
        }
コード例 #3
0
        protected override void OnConnected(INetworkConnection connection)
        {
            base.OnConnected(connection);

            DebugLog($"Observer Connected to connection: {connection.ToString()}");

            if (StateSynchronizationSceneManager.IsInitialized)
            {
                StateSynchronizationSceneManager.Instance.MarkSceneDirty();
            }

            hologramSynchronizer.Reset(connection);
        }
コード例 #4
0
        private void OnParticipantDataReceived(INetworkConnection connection, string command, BinaryReader reader, int remainingDataSize)
        {
            if (!TryGetSpatialCoordinateSystemParticipant(connection, out SpatialCoordinateSystemParticipant participant))
            {
                Debug.LogError($"Received participant localization data for a missing participant: {connection.ToString()}");
                return;
            }

            if (participant.CurrentLocalizationSession == null)
            {
                Debug.LogError($"Received participant localization data for a participant that is not currently running a localization session: {connection.ToString()}");
                return;
            }

            DebugLog($"Data received for participant: {connection.ToString()}, {command}");
            participant.CurrentLocalizationSession.OnDataReceived(reader);
        }
コード例 #5
0
 private void OnNetDisconnected(INetworkConnection obj)
 {
     Debug.Log($"INetworkConnectionManager Disconnected:{obj.ToString()}");
 }
 protected override void OnDisconnected(INetworkConnection connection)
 {
     DebugLog($"Broadcaster received disconnect from {connection.ToString()}");;
     base.OnDisconnected(connection);
 }
コード例 #7
0
        private async void OnLocalizeMessageReceived(INetworkConnection connection, string command, BinaryReader reader, int remainingDataSize)
        {
            DebugLog("LocalizeMessageReceived");
            if (!participants.TryGetValue(connection, out SpatialCoordinateSystemParticipant participant))
            {
                Debug.LogError($"Could not find a SpatialCoordinateSystemParticipant for INetworkConnection {connection.ToString()}");
                SendLocalizationCompleteCommand(connection, localizationSuccessful: false);
                return;
            }

            Guid spatialLocalizerID = reader.ReadGuid();

            if (!localizers.TryGetValue(spatialLocalizerID, out ISpatialLocalizer localizer))
            {
                Debug.LogError($"Request to begin localization with localizer {spatialLocalizerID} but no localizer with that ID was registered");
                SendLocalizationCompleteCommand(connection, localizationSuccessful: false);
                return;
            }

            if (!localizer.TryDeserializeSettings(reader, out ISpatialLocalizationSettings settings))
            {
                Debug.LogError($"Failed to deserialize settings for localizer {spatialLocalizerID}");
                SendLocalizationCompleteCommand(connection, localizationSuccessful: false);
                return;
            }

            bool localizationSuccessful = await RunLocalizationSessionAsync(localizer, settings, participant);

            // Ensure that the participant's fully-localized state is sent before sending the LocalizationComplete command (versus waiting
            // for the next Update). This way the remote peer receives the located state of the participant before they receive the notification
            // that this localization session completed.
            participant.EnsureStateChangesAreBroadcast();

            SendLocalizationCompleteCommand(connection, localizationSuccessful);
        }
コード例 #8
0
        private void OnConnected(INetworkConnection connection)
        {
            if (participants.TryGetValue(connection, out var existingParticipant))
            {
                Debug.LogWarning("SpatialCoordinateSystemParticipant connected that already existed.");
                return;
            }

            DebugLog($"Creating new SpatialCoordinateSystemParticipant, NetworkConnection: {connection.ToString()}, DebugLogging: {debugLogging}");

            SpatialCoordinateSystemParticipant participant = new SpatialCoordinateSystemParticipant(connection, debugVisual, debugVisualScale);

            participants[connection]     = participant;
            participant.ShowDebugVisuals = showDebugVisuals;
            participant.SendSupportedLocalizersMessage(connection, localizers.Keys);

            if (ParticipantConnected == null)
            {
                DebugLog($"No ParticipantConnected event handlers exist");
            }
            else
            {
                DebugLog($"Invoking ParticipantConnected event");
                ParticipantConnected.Invoke(participant);
            }
        }
コード例 #9
0
        public Task <bool> LocalizeAsync(INetworkConnection connection, Guid spatialLocalizerID, ISpatialLocalizationSettings settings)
        {
            DebugLog("LocalizeAsync");
            if (!participants.TryGetValue(connection, out SpatialCoordinateSystemParticipant participant))
            {
                Debug.LogError($"Could not find a SpatialCoordinateSystemParticipant for INetworkConnection {connection.ToString()}");
                return(Task.FromResult(false));
            }

            if (!localizers.TryGetValue(spatialLocalizerID, out ISpatialLocalizer localizer))
            {
                Debug.LogError($"Could not find a ISpatialLocalizer for spatialLocalizerID {spatialLocalizerID}");
                return(Task.FromResult(false));
            }

            DebugLog("Returning a localization session.");
            return(RunLocalizationSessionAsync(localizer, settings, participant));
        }