예제 #1
0
        public void Display(Rect displayRect)
        {
            if (null == NetworkManager.singleton)
            {
                return;
            }
            if (NetworkServer.active || NetworkClient.active)
            {
                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();
        }
        void OnGUI()
        {
            if (null == NetworkManager.singleton)
            {
                return;
            }
            if (NetworkServer.active || NetworkClient.active)
            {
                return;
            }
            if (!NetworkDiscovery.SupportedOnThisPlatform)
            {
                return;
            }

            if (null == m_centeredLabelStyle)
            {
                m_centeredLabelStyle           = new GUIStyle(GUI.skin.label);
                m_centeredLabelStyle.alignment = TextAnchor.MiddleCenter;
            }

            int elemWidth = width / m_headerNames.Length - 5;

            GUILayout.BeginArea(new Rect(offsetX, offsetY, width, height));

            if (IsRefreshing)
            {
                GUILayout.Button("Refreshing...", GUILayout.Height(25), GUILayout.ExpandWidth(false));
            }
            else
            {
                if (GUILayout.Button("Refresh LAN", GUILayout.Height(25), GUILayout.ExpandWidth(false)))
                {
                    Refresh();
                }
            }

            // 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));

            // header
            GUILayout.BeginHorizontal();
            foreach (string str in m_headerNames)
            {
                GUILayout.Button(str, GUILayout.Width(elemWidth));
            }
            GUILayout.EndHorizontal();

            // servers

            m_scrollViewPos = GUILayout.BeginScrollView(m_scrollViewPos);

            foreach (var info in m_discoveredServers)
            {
                GUILayout.BeginHorizontal();

                if (GUILayout.Button(info.EndPoint.Address.ToString(), GUILayout.Width(elemWidth)))
                {
                    Connect(info);
                }

                for (int i = 1; i < m_headerNames.Length; i++)
                {
                    if (info.KeyValuePairs.ContainsKey(m_headerNames[i]))
                    {
                        GUILayout.Label(info.KeyValuePairs[m_headerNames[i]], m_centeredLabelStyle, GUILayout.Width(elemWidth));
                    }
                    else
                    {
                        GUILayout.Label("", m_centeredLabelStyle, GUILayout.Width(elemWidth));
                    }
                }

                GUILayout.EndHorizontal();
            }

            GUILayout.EndScrollView();


            GUILayout.EndArea();
        }