# ConnectionTargetSelectionDropdown(Rect, IConnectionState, GUIStyle)

> Display a drop-down button and menu for the user to choose and establish a connection to a Player.

## Definition

* **Type:** Method
* **Namespace:** [UnityEditor.Networking.PlayerConnection](/engine/6000.6/script-reference/unityeditor/networking/playerconnection.md)
* **Assembly:** UnityEditor.CoreModule

```csharp
public static void ConnectionTargetSelectionDropdown(Rect rect, IConnectionState state, GUIStyle style = null)
```

### Parameters

**** (\[Rect]\(/engine/6000.6/script-reference/unityengine/rect)): Where to draw the drop-down button.**** (\[IConnectionState]\(/engine/6000.6/script-reference/unityengine/networking/playerconnection/iconnectionstate)): The state for the connection that is used in the [EditorWindow](/engine/6000.6/script-reference/unityeditor/editorwindow.md) displaying this drop-down. Use [PlayerConnectionGUIUtility.GetConnectionState](/engine/6000.6/script-reference/unityeditor/networking/playerconnection/playerconnectionguiutility/getconnectionstate.md) to get a state in OnEnable and remember to dispose of that state in OnDisable.**** (\[GUIStyle]\(/engine/6000.6/script-reference/unityengine/guistyle)): Define the [GUIStyle](/engine/6000.6/script-reference/unityengine/guistyle.md) the drop-down button should be drawn in. A default drop-down button will be drawn if no style is specified.

### Remarks

This is the same control that is used in the toolbars of the [Profiler Window](/engine/6000.6/manual/analysis/profiler/window.md), [Frame Debugger](/engine/6000.6/manual/analysis/graphics-performance-profiling/profile-rendering/frame-debugger/frame-debugger.md) or [Console Window](/engine/6000.6/manual/unity-editor/editor-windows-views-reference/console.md). The drop-down will list all available Players and Editors that your Editor can connect to and that are discoverable. It also offers an entry to directly connect to an IP address. You will need to provide the state of the connection used for your [EditorWindow](/engine/6000.6/script-reference/unityeditor/editorwindow.md). To get one, use [PlayerConnectionGUIUtility.GetConnectionState](/engine/6000.6/script-reference/unityeditor/networking/playerconnection/playerconnectionguiutility/getconnectionstate.md) in OnEnable and remember to dispose of the state in OnDisable of the [EditorWindow](/engine/6000.6/script-reference/unityeditor/editorwindow.md) you're using it in.

This class currently only works for the connection that the Profiling tools and the Console use. In a future release this will work with [PlayerConnection](/engine/6000.6/script-reference/unityengine/networking/playerconnection/playerconnection.md).

```csharp
using UnityEngine;
using UnityEngine.Profiling;
using UnityEditor;
using UnityEngine.Networking.PlayerConnection;
using UnityEditor.Networking.PlayerConnection;

public class MyWindow : EditorWindow
{
    // The state can survive for the life time of the EditorWindow so it's best to store it here and just renew/dispose of it in OnEnable and OnDisable, rather than fetching repeatedly it in OnGUI.
    IConnectionState attachProfilerState;

    [MenuItem("Window/My Window")]
    static void Init()
    {
        MyWindow window = (MyWindow)GetWindow(typeof(MyWindow));
        window.Show();
    }

    private void OnEnable()
    {
        // The state of the connection is not getting serialized and needs to be disposed
        // Therefore, it's recommended to fetch it in OnEnable and call Dispose() on it in OnDisable
        attachProfilerState = PlayerConnectionGUIUtility.GetConnectionState(this, OnConnected);
    }

    private void OnConnected(string player)
    {
        Debug.Log(string.Format("MyWindow connected to {0}", player));
    }

    private void OnGUI()
    {
        // Draw a toolbar across the top of the window and draw the drop-down in the toolbar drop-down style too
        EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
        var rect = GUILayoutUtility.GetRect(100, EditorGUIUtility.singleLineHeight, EditorStyles.toolbarDropDown);
        PlayerConnectionGUI.ConnectionTargetSelectionDropdown(rect, attachProfilerState, EditorStyles.toolbarDropDown);

        switch (attachProfilerState.connectedToTarget)
        {
            case ConnectionTarget.None:
                //This case can never happen within the Editor, since the Editor will always fall back onto a connection to itself.
                break;
            case ConnectionTarget.Player:
                Profiler.enabled = GUILayout.Toggle(Profiler.enabled, string.Format("Profile the attached Player ({0})", attachProfilerState.connectionName), EditorStyles.toolbarButton);
                break;
            case ConnectionTarget.Editor:
                // The name of the Editor or the PlayMode Player would be "Editor" so adding the connectionName here would not add anything.
                Profiler.enabled = GUILayout.Toggle(Profiler.enabled, "Profile the Player in the Editor", EditorStyles.toolbarButton);
                break;
            default:
                break;
        }
        EditorGUILayout.EndHorizontal();
    }

    private void OnDisable()
    {
        // Remember to always dispose of the state!
        attachProfilerState.Dispose();
    }
}
```

Also see [PlayerConnectionGUI.ConnectionTargetSelectionDropdown](/engine/6000.6/script-reference/unityeditor/networking/playerconnection/playerconnectiongui/connectiontargetselectiondropdown.md) for automatic layouts as well as [PlayerConnectionGUIUtility.GetConnectionState](/engine/6000.6/script-reference/unityeditor/networking/playerconnection/playerconnectionguiutility/getconnectionstate.md) and [IConnectionState](/engine/6000.6/script-reference/unityengine/networking/playerconnection/iconnectionstate.md) for details of the state handling for this UI control.
