void DrawRemotingOnGUI()
        {
            EditorGUILayout.HelpBox(s_RemotingSettingsReminder);
            EditorGUILayout.HelpBox(s_RemotingConnectionHelp);

            EditorGUI.BeginDisabledGroup(WindowsMRRemoting.isConnected);
            s_RemoteSettings.m_RemoteMachineName = EditorGUILayout.TextField(s_RemoteMachineText, s_RemoteSettings.m_RemoteMachineName);
            s_RemoteSettings.m_EnableAudio       = EditorGUILayout.Toggle(s_EnableVideoText, s_RemoteSettings.m_EnableAudio);
            s_RemoteSettings.m_EnableVideo       = EditorGUILayout.Toggle(s_EnableAudioText, s_RemoteSettings.m_EnableVideo);
            s_RemoteSettings.m_MaxBitRateKbps    = EditorGUILayout.IntSlider(s_MaxBitrateText, s_RemoteSettings.m_MaxBitRateKbps, 1024, s_RemoteSettings.m_MaxBitRateKbps);
            EditorGUI.EndDisabledGroup();

            GUIContent      labelContent;
            GUIContent      buttonContent;
            ConnectionState connectionState;

            if (!WindowsMRRemoting.TryGetConnectionState(out connectionState))
            {
                Debug.Log("Failed to get connection state! Exiting remoting-window drawing.");
                return;
            }

            if (previousConnectionState == ConnectionState.Connecting && connectionState == ConnectionState.Disconnected)
            {
                ConnectionFailureReason failureReason;
                WindowsMRRemoting.TryGetConnectionFailureReason(out failureReason);

                Debug.Log("Connection Failure Reason: " + failureReason);
            }

            previousConnectionState = connectionState;

            switch (connectionState)
            {
            case ConnectionState.Disconnected:
            default:
                labelContent  = s_ConnectionStateDisconnectedText;
                buttonContent = s_ConnectionButtonConnectText;
                break;

            case ConnectionState.Connecting:
                labelContent  = s_ConnectionStateConnectingText;
                buttonContent = s_ConnectionButtonDisconnectText;
                break;

            case ConnectionState.Connected:
                labelContent  = s_ConnectionStateConnectedText;
                buttonContent = s_ConnectionButtonDisconnectText;
                break;
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(s_ConnectionStatusText, "Button");
            float iconSize = EditorGUIUtility.singleLineHeight;
            Rect  iconRect = GUILayoutUtility.GetRect(iconSize, iconSize, GUILayout.ExpandWidth(false));

            EditorGUILayout.LabelField(labelContent);
            EditorGUILayout.EndHorizontal();
        }
    IEnumerator TryConnect()
    {
        // Setup the connection state information required to make a connection
        // to the remote device.
        WindowsMRRemoting.isAudioEnabled    = enableAudio;
        WindowsMRRemoting.isVideoEnabled    = enableVideo;
        WindowsMRRemoting.maxBitRateKbps    = maxBitRate;
        WindowsMRRemoting.remoteMachineName = machineName;

        WindowsMREmulation.mode = WindowsMREmulationMode.Remoting;

        Debug.Log($"Connecting to {machineName}...");

        WindowsMRRemoting.Connect();

        yield return(new WaitForEndOfFrame());

        ConnectionState connectionState = ConnectionState.Disconnected;

        int connectionTryCount = 0;

        // If connection fails, we'll try again, up to the number of times specified
        while (WindowsMRRemoting.TryGetConnectionState(out connectionState) && connectionTryCount < connectionRetryCount)
        {
            connectionTryCount++;
            if (connectionState == ConnectionState.Connecting)
            {
                Debug.Log($"Still connecting to {machineName}...");
                yield return(new WaitForSeconds(1));

                continue;
            }
            break;
        }

        switch (connectionState)
        {
        case ConnectionState.Connected:
            Debug.Log($"Successfully connected to {machineName} after {connectionTryCount} seconds.");

            // We've connected, so now we need to spin up XR SDK.
            yield return(XRGeneralSettings.Instance.Manager.InitializeLoader());

            if (XRGeneralSettings.Instance.Manager.activeLoader != null)
            {
                XRGeneralSettings.Instance.Manager.activeLoader.Start();
            }
            break;

        case ConnectionState.Disconnected:
            Debug.LogError($"Unable to connect to {machineName} after {connectionTryCount} seconds");
            ConnectionFailureReason failureReason = ConnectionFailureReason.None;
            WindowsMRRemoting.TryGetConnectionFailureReason(out failureReason);
            Debug.LogError($"Connection Failure Reason {failureReason}");
            break;
        }
    }
        void UpdateConnectionStatus()
        {
            if (!WindowsMRRemoting.TryGetConnectionState(out connectionState))
            {
                Debug.Log("Failed to get connection state! Exiting remoting-window drawing.");
                return;
            }

            if (previousConnectionState == ConnectionState.Connecting && connectionState == ConnectionState.Disconnected)
            {
                ConnectionFailureReason failureReason;
                WindowsMRRemoting.TryGetConnectionFailureReason(out failureReason);

                Debug.Log("Connection Failure Reason: " + failureReason);
            }

            if (previousConnectionState != connectionState)
            {
                previousConnectionState = connectionState;
                Repaint();
            }

            switch (connectionState)
            {
            case ConnectionState.Disconnected:
            default:
                labelContent  = s_ConnectionStateDisconnectedText;
                buttonContent = s_ConnectionButtonConnectText;
                break;

            case ConnectionState.Connecting:
                labelContent  = s_ConnectionStateConnectingText;
                buttonContent = s_ConnectionButtonDisconnectText;
                Repaint();
                break;

            case ConnectionState.Connected:
                labelContent  = s_ConnectionStateConnectedText;
                buttonContent = s_ConnectionButtonDisconnectText;
                break;
            }
        }
        void DrawRemotingOnGUI()
        {
            EditorGUI.BeginDisabledGroup(WindowsMRRemoting.isConnected);
            m_RemoteMachineName = EditorGUILayout.TextField(s_RemoteMachineText, m_RemoteMachineName);
            WindowsMRRemoting.remoteMachineName = m_RemoteMachineName;
            WindowsMRRemoting.isVideoEnabled    = EditorGUILayout.Toggle(s_EnableVideoText, WindowsMRRemoting.isVideoEnabled);
            WindowsMRRemoting.isAudioEnabled    = EditorGUILayout.Toggle(s_EnableAudioText, WindowsMRRemoting.isAudioEnabled);
            WindowsMRRemoting.maxBitRateKbps    = EditorGUILayout.IntSlider(s_MaxBitrateText, WindowsMRRemoting.maxBitRateKbps, 1024, 99999);
            EditorGUI.EndDisabledGroup();

            GUIContent      labelContent;
            GUIContent      buttonContent;
            ConnectionState connectionState;

            if (!WindowsMRRemoting.TryGetConnectionState(out connectionState))
            {
                Debug.Log("Failed to get connection state! Exiting remoting-window drawing.");
                return;
            }

            if (previousConnectionState == ConnectionState.Connecting && connectionState == ConnectionState.Disconnected)
            {
                ConnectionFailureReason failureReason;
                WindowsMRRemoting.TryGetConnectionFailureReason(out failureReason);

                Debug.Log("Connection Failure Reason: " + failureReason);
            }

            previousConnectionState = connectionState;

            switch (connectionState)
            {
            case ConnectionState.Disconnected:
            default:
                labelContent  = s_ConnectionStateDisconnectedText;
                buttonContent = s_ConnectionButtonConnectText;
                break;

            case ConnectionState.Connecting:
                labelContent  = s_ConnectionStateConnectingText;
                buttonContent = s_ConnectionButtonDisconnectText;
                break;

            case ConnectionState.Connected:
                labelContent  = s_ConnectionStateConnectedText;
                buttonContent = s_ConnectionButtonDisconnectText;
                break;
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(s_ConnectionStatusText, "Button");
            float iconSize = EditorGUIUtility.singleLineHeight;
            Rect  iconRect = GUILayoutUtility.GetRect(iconSize, iconSize, GUILayout.ExpandWidth(false));

            EditorGUILayout.LabelField(labelContent);
            EditorGUILayout.EndHorizontal();

            EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode);
            bool pressed = EditorGUILayout.DropdownButton(buttonContent, FocusType.Passive, EditorStyles.miniButton);

            EditorGUI.EndDisabledGroup();

            if (pressed)
            {
                if (EditorGUIUtility.editingTextField)
                {
                    EditorGUIUtility.editingTextField = false;
                    GUIUtility.keyboardControl        = 0;
                }

                HandleButtonPress();
            }
        }