コード例 #1
0
    public void Display(Rect displayRect)
    {
        if (null == NetworkManager.Singleton)
        {
            return;
        }
        if (NetworkManager.Singleton.IsServer || NetworkManager.Singleton.IsConnectedClient)
        {
            return;
        }
        if (!NetworkDiscovery.SupportedOnThisPlatform)
        {
            return;
        }

        GUILayout.BeginArea(displayRect);

        this.DisplayRefreshButton();

        // lookup a server

        GUILayout.Label("Lookup server: ");
        GUILayout.BeginHorizontal();
        GUILayout.Label("IP:");
        m_lookupServerIP = GUILayout.TextField(m_lookupServerIP, GUILayout.Width(120));
        GUILayout.Space(10);
        GUILayout.Label("Port:");
        m_lookupServerPort = GUILayout.TextField(m_lookupServerPort, GUILayout.Width(60));
        GUILayout.Space(10);
        if (IsLookingUpAnyServer)
        {
            GUILayout.Button("Lookup...", GUILayout.Height(25), GUILayout.MinWidth(80));
        }
        else
        {
            if (GUILayout.Button("Lookup", GUILayout.Height(25), GUILayout.MinWidth(80)))
            {
                LookupServer();
            }
        }
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        m_displayBroadcastAddresses = GUILayout.Toggle(m_displayBroadcastAddresses, "Display broadcast addresses", GUILayout.ExpandWidth(false));
        if (m_displayBroadcastAddresses)
        {
            GUILayout.Space(10);
            GUILayout.Label(string.Join(", ", NetworkDiscovery.GetBroadcastAdresses().Select(ip => ip.ToString())));
        }
        GUILayout.EndHorizontal();

        GUILayout.Label(string.Format("Servers [{0}]:", m_discoveredServers.Count));

        this.DisplayServers();

        GUILayout.EndArea();
    }