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!"); } }
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(); } } }