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!");
            }
        }
Ejemplo n.º 2
0
        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 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();
                }
            }
        }
    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);
    }
        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();
            }
        }