private void HandleButtonPress()
        {
            if (EditorApplication.isPlayingOrWillChangePlaymode)
            {
                Debug.LogError("Unable to connect / disconnect remoting while playing.");
                return;
            }

            ConnectionState connectionState;

            if (!WindowsMRRemoting.TryGetConnectionState(out connectionState))
            {
                Debug.LogError("Failed to get connection state - exiting button-press response!");
                return;
            }

            if (connectionState == ConnectionState.Connecting ||
                connectionState == ConnectionState.Connected)
            {
                WindowsMRRemoting.Disconnect();
            }
            else if (!string.IsNullOrEmpty(WindowsMRRemoting.remoteMachineName))
            {
                WindowsMRRemoting.Connect();
            }
            else
            {
                Debug.LogError("Cannot connect without a remote machine name!");
            }
        }
        void HandleManualConnect()
        {
            if (!s_RemoteSettings.autoConnectOnPlay)
            {
                if (connectionState != ConnectionState.Connected)
                {
                    bool shouldDisableButton = string.IsNullOrEmpty(s_RemoteSettings.m_RemoteMachineName) ||
                                               EditorApplication.isPlayingOrWillChangePlaymode ||
                                               connectionState != ConnectionState.Disconnected;

                    EditorGUILayout.Space();
                    EditorGUI.BeginDisabledGroup(shouldDisableButton);
                    if (GUILayout.Button(s_ConnectionButtonConnectText))
                    {
                        var connector = GetConnector();
                        if (connector)
                        {
                            Debug.Log("Attempting to start remoting...");
                            if (!WindowsMRRemoting.TryGetConnectionState(out connectionState))
                            {
                                Debug.LogError("Failed to get connection state! Connection attempt terminated");
                                return;
                            }

                            WindowsMRRemoting.remoteMachineName = s_RemoteSettings.m_RemoteMachineName;
                            WindowsMRRemoting.isAudioEnabled    = s_RemoteSettings.m_EnableAudio;
                            WindowsMRRemoting.isVideoEnabled    = s_RemoteSettings.m_EnableVideo;
                            WindowsMRRemoting.maxBitRateKbps    = s_RemoteSettings.m_MaxBitRateKbps;
                            WindowsMRRemoting.Connect();
                            Repaint();
                        }
                    }
                    EditorGUI.EndDisabledGroup();
                }
                else
                {
                    EditorGUILayout.Space();
                    EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode || connectionState != ConnectionState.Connected);
                    if (GUILayout.Button(s_ConnectionButtonDisconnectText))
                    {
                        var connector = GetConnector();
                        if (connector)
                        {
                            Debug.Log("Attempting to stop remoting...");
                            WindowsMRRemoting.Disconnect();
                            Repaint();
                        }
                    }
                    EditorGUI.EndDisabledGroup();
                }
            }
        }
        void DrawEmulationModeOnGUI()
        {
            EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode);
            EditorGUI.BeginChangeCheck();
            WindowsMREmulationMode previousMode = WindowsMREmulation.mode;
            WindowsMREmulationMode currentMode  = (WindowsMREmulationMode)EditorGUILayout.Popup(s_EmulationModeText, (int)previousMode, s_ModeStrings);

            if (EditorGUI.EndChangeCheck())
            {
                if (previousMode == WindowsMREmulationMode.Remoting)
                {
                    WindowsMRRemoting.Disconnect();
                }
                WindowsMREmulation.mode = currentMode;
            }
            EditorGUI.EndDisabledGroup();
        }
 static void Disconnect()
 {
     if (WindowsMREmulation.mode == WindowsMREmulationMode.Remoting && WindowsMRRemoting.isConnected)
     {
         var connector = GetConnector();
         if (EditorApplication.isPlaying && s_RemoteSettings.autoConnectOnPlay && connector)
         {
             connector.StopRemotingConnection();
             GameObject.Destroy(s_Connector);
             s_Connector = null;
         }
         else
         {
             WindowsMRRemoting.Disconnect();
         }
     }
 }
    IEnumerator TryDisconnect()
    {
        ConnectionState connectionState = ConnectionState.Disconnected;

        if (WindowsMRRemoting.TryGetConnectionState(out connectionState) && connectionState == ConnectionState.Connected)
        {
            // If we have a live XR SDK session, we need to shut that before we can disconnect the remote session.
            if (XRGeneralSettings.Instance.Manager.activeLoader != null)
            {
                XRGeneralSettings.Instance.Manager.activeLoader.Stop();
                XRGeneralSettings.Instance.Manager.DeinitializeLoader();
            }

            WindowsMRRemoting.Disconnect();
            yield return(new WaitForEndOfFrame());
        }

        yield return(null);
    }