SetMatchHost() public method

This sets the address of the MatchMaker service.

public SetMatchHost ( string newHost, int port, bool https ) : void
newHost string Hostname of MatchMaker service.
port int Port of MatchMaker service.
https bool Protocol used by MatchMaker service.
return void
    void Awake()
    {
        manager = GetComponent<NetworkManager>();
        manager.StartMatchMaker();
        manager.SetMatchHost("mm.unet.unity3d.com", 443, true);

        manager.matchMaker.ListMatches(0, 20, "", UpdateListing);
    }
Example #2
0
    void Awake()
    {
        Dropdown mapDropdown = Map.GetComponent<Dropdown>();
        mapDropdown.options.Add(new Dropdown.OptionData("scene1"));
        mapDropdown.options.Add(new Dropdown.OptionData("scene2"));
        mapDropdown.options.Add(new Dropdown.OptionData("scene3"));
        mapDropdown.options.Add(new Dropdown.OptionData("scene4"));
        mapDropdown.options.Add(new Dropdown.OptionData("scene5"));

        manager = GetComponent<NetworkManager>();
        manager.StartMatchMaker();
        manager.SetMatchHost("mm.unet.unity3d.com", 443, true);
    }
Example #3
0
        void OnGUI()
        {
            if (!showGUI)
            {
                return;
            }

            int       xpos    = 10 + offsetX;
            int       ypos    = 40 + offsetY;
            const int spacing = 24;

            GUI.skin.label.fontSize     = 12 * (int)scale;
            GUI.skin.button.fontSize    = 12 * (int)scale;
            GUI.skin.textField.fontSize = 12 * (int)scale;

            bool noConnection = (manager.client == null || manager.client.connection == null ||
                                 manager.client.connection.connectionId == -1);

            if (!manager.IsClientConnected() && !NetworkServer.active && manager.matchMaker == null)
            {
                if (noConnection)
                {
                    if (UnityEngine.Application.platform != RuntimePlatform.WebGLPlayer)
                    {
                        if (GUI.Button(ScaleRect(xpos, ypos, 200, 20), "LAN Host(H)"))
                        {
                            manager.StartHost();
                        }
                        ypos += spacing;
                    }

                    if (GUI.Button(ScaleRect(xpos, ypos, 105, 20), "LAN Client(C)"))
                    {
                        manager.StartClient();
                    }

                    manager.networkAddress = GUI.TextField(ScaleRect(xpos + 100, ypos, 95, 20), manager.networkAddress);
                    ypos += spacing;

                    if (UnityEngine.Application.platform == RuntimePlatform.WebGLPlayer)
                    {
                        // cant be a server in webgl build
                        GUI.Box(ScaleRect(xpos, ypos, 200, 25), "(  WebGL cannot be server  )");
                        ypos += spacing;
                    }
                    else
                    {
                        if (GUI.Button(ScaleRect(xpos, ypos, 200, 20), "LAN Server Only(S)"))
                        {
                            manager.StartServer();
                        }
                        ypos += spacing;
                    }
                }
                else
                {
                    GUI.Label(ScaleRect(xpos, ypos, 200, 20), "Connecting to " + manager.networkAddress + ":" + manager.networkPort + "..");
                    ypos += spacing;


                    if (GUI.Button(ScaleRect(xpos, ypos, 200, 20), "Cancel Connection Attempt"))
                    {
                        manager.StopClient();
                    }
                }
            }
            else
            {
                if (NetworkServer.active)
                {
                    string serverMsg = "Server: port=" + manager.networkPort;
                    if (manager.useWebSockets)
                    {
                        serverMsg += " (Using WebSockets)";
                    }
                    GUI.Label(ScaleRect(xpos, ypos, 300, 20), serverMsg);
                    ypos += spacing;
                }
                if (manager.IsClientConnected())
                {
                    GUI.Label(ScaleRect(xpos, ypos, 300, 20), "Client: address=" + manager.networkAddress + " port=" + manager.networkPort);
                    ypos += spacing;
                }
            }

            if (manager.IsClientConnected() && !ClientScene.ready)
            {
                if (GUI.Button(ScaleRect(xpos, ypos, 200, 20), "Client Ready"))
                {
                    ClientScene.Ready(manager.client.connection);

                    if (ClientScene.localPlayers.Count == 0)
                    {
                        ClientScene.AddPlayer(0);
                    }
                }
                ypos += spacing;
            }

            if (NetworkServer.active || manager.IsClientConnected())
            {
                if (GUI.Button(ScaleRect(xpos, ypos, 200, 20), "Stop (X)"))
                {
                    manager.StopHost();
                }
                ypos += spacing;
            }

            if (!NetworkServer.active && !manager.IsClientConnected() && noConnection)
            {
                ypos += 10;

                if (UnityEngine.Application.platform == RuntimePlatform.WebGLPlayer)
                {
                    GUI.Box(ScaleRect(xpos - 5, ypos, 220, 25), "(WebGL cannot use Match Maker)");
                    return;
                }

                if (manager.matchMaker == null)
                {
                    if (GUI.Button(ScaleRect(xpos, ypos, 200, 20), "Enable Match Maker (M)"))
                    {
                        manager.StartMatchMaker();
                    }
                    ypos += spacing;
                }
                else
                {
                    if (manager.matchInfo == null)
                    {
                        if (manager.matches == null)
                        {
                            if (GUI.Button(ScaleRect(xpos, ypos, 200, 20), "Create Internet Match"))
                            {
                                manager.matchMaker.CreateMatch(manager.matchName, manager.matchSize, true, "", "", "", 0, 0, manager.OnMatchCreate);
                            }
                            ypos += spacing;

                            GUI.Label(ScaleRect(xpos, ypos, 100, 20), "Room Name:");
                            manager.matchName = GUI.TextField(ScaleRect(xpos + 100, ypos, 100, 20), manager.matchName);
                            ypos += spacing;

                            ypos += 10;

                            if (GUI.Button(ScaleRect(xpos, ypos, 200, 20), "Find Internet Match"))
                            {
                                manager.matchMaker.ListMatches(0, 20, "", false, 0, 0, manager.OnMatchList);
                            }
                            ypos += spacing;
                        }
                        else
                        {
                            for (int i = 0; i < manager.matches.Count; i++)
                            {
                                var match = manager.matches[i];
                                if (GUI.Button(ScaleRect(xpos, ypos, 200, 20), "Join Match:" + match.name))
                                {
                                    manager.matchName = match.name;
                                    manager.matchMaker.JoinMatch(match.networkId, "", "", "", 0, 0, manager.OnMatchJoined);
                                }
                                ypos += spacing;
                            }

                            if (GUI.Button(ScaleRect(xpos, ypos, 200, 20), "Back to Match Menu"))
                            {
                                manager.matches = null;
                            }
                            ypos += spacing;
                        }
                    }

                    if (GUI.Button(ScaleRect(xpos, ypos, 200, 20), "Change MM server"))
                    {
                        m_ShowServer = !m_ShowServer;
                    }
                    if (m_ShowServer)
                    {
                        ypos += spacing;
                        if (GUI.Button(ScaleRect(xpos, ypos, 100, 20), "Local"))
                        {
                            manager.SetMatchHost("localhost", 1337, false);
                            m_ShowServer = false;
                        }
                        ypos += spacing;
                        if (GUI.Button(ScaleRect(xpos, ypos, 100, 20), "Internet"))
                        {
                            manager.SetMatchHost("mm.unet.unity3d.com", 443, true);
                            m_ShowServer = false;
                        }
                        ypos += spacing;
                        if (GUI.Button(ScaleRect(xpos, ypos, 100, 20), "Staging"))
                        {
                            manager.SetMatchHost("staging-mm.unet.unity3d.com", 443, true);
                            m_ShowServer = false;
                        }
                    }

                    ypos += spacing;

                    GUI.Label(ScaleRect(xpos, ypos, 300, 20), "MM Uri: " + manager.matchMaker.baseUri);
                    ypos += spacing;

                    if (GUI.Button(ScaleRect(xpos, ypos, 200, 20), "Disable Match Maker"))
                    {
                        manager.StopMatchMaker();
                    }
                    ypos += spacing;
                }
            }
        }
Example #4
0
        void OnGUI()
        {
            if (isPaused)
            {
                // Si le bouton est présser alors isPaused devient faux donc le jeu reprend.
                if (GUI.Button(new Rect(Screen.width / 2 - 40, Screen.height / 2 - 20, 80, 40), "Continuer"))
                {
                    isPaused = false;
                }

                // Si le bouton est présser alors on ferme completement le jeu ou charge la scene "Menu Principal
                // Dans le cas du bouton quitter il faut augmenter sa postion Y pour qu'il soit plus bas
                if (GUI.Button(new Rect(Screen.width / 2 - 40, Screen.height / 2 + 40, 80, 40), "Quitter"))
                {
                    // Application.Quit();
                    manager.StopHost();
                    Application.LoadLevel("Menu");
                }
            }

            if (!showGUI)
            {
                return;
            }

            int       xpos    = 10 + offsetX;
            int       ypos    = 40 + offsetY;
            const int spacing = 24;

            bool noConnection = (manager.client == null || manager.client.connection == null ||
                                 manager.client.connection.connectionId == -1);

            if (!manager.IsClientConnected() && !NetworkServer.active && manager.matchMaker == null)
            {
                if (noConnection)
                {
                    if (UnityEngine.Application.platform != RuntimePlatform.WebGLPlayer)
                    {
                        if (GUI.Button(new Rect(xpos, ypos, 200, 20), "LAN Host(H)"))
                        {
                            manager.StartHost();
                        }
                        ypos += spacing;
                    }

                    if (GUI.Button(new Rect(xpos, ypos, 105, 20), "LAN Client(C)"))
                    {
                        manager.StartClient();
                    }

                    manager.networkAddress = GUI.TextField(new Rect(xpos + 100, ypos, 95, 20), manager.networkAddress);
                    ypos += spacing;

                    if (UnityEngine.Application.platform == RuntimePlatform.WebGLPlayer)
                    {
                        // cant be a server in webgl build
                        GUI.Box(new Rect(xpos, ypos, 200, 25), "(  WebGL cannot be server  )");
                        ypos += spacing;
                    }
                    else
                    {
                        if (GUI.Button(new Rect(xpos, ypos, 200, 20), "LAN Server Only(S)"))
                        {
                            manager.StartServer();
                        }
                        ypos += spacing;
                    }
                }
                else
                {
                    GUI.Label(new Rect(xpos, ypos, 200, 20), "Connecting to " + manager.networkAddress + ":" + manager.networkPort + "..");
                    ypos += spacing;


                    if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Cancel Connection Attempt"))
                    {
                        manager.StopClient();
                    }
                }
            }
            else
            {
                if (NetworkServer.active)
                {
                    string serverMsg = "Server: port=" + manager.networkPort;
                    if (manager.useWebSockets)
                    {
                        serverMsg += " (Using WebSockets)";
                    }
                    GUI.Label(new Rect(xpos, ypos, 300, 20), serverMsg);
                    ypos += spacing;
                }
                if (manager.IsClientConnected())
                {
                    GUI.Label(new Rect(xpos, ypos, 300, 20), "Client: address=" + manager.networkAddress + " port=" + manager.networkPort);
                    ypos += spacing;
                }
            }

            if (manager.IsClientConnected() && !ClientScene.ready)
            {
                if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Client Ready"))
                {
                    ClientScene.Ready(manager.client.connection);

                    if (ClientScene.localPlayers.Count == 0)
                    {
                        ClientScene.AddPlayer(0);
                    }
                }
                ypos += spacing;
            }

            if (NetworkServer.active || manager.IsClientConnected())
            {
                if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Stop (X)"))
                {
                    manager.StopHost();
                }
                ypos += spacing;
            }

            if (!NetworkServer.active && !manager.IsClientConnected() && noConnection)
            {
                ypos += 10;

                if (UnityEngine.Application.platform == RuntimePlatform.WebGLPlayer)
                {
                    GUI.Box(new Rect(xpos - 5, ypos, 220, 25), "(WebGL cannot use Match Maker)");
                    return;
                }

                if (manager.matchMaker == null)
                {
                    if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Enable Match Maker (M)"))
                    {
                        manager.StartMatchMaker();
                    }
                    ypos += spacing;
                }
                else
                {
                    if (manager.matchInfo == null)
                    {
                        if (manager.matches == null)
                        {
                            if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Create Internet Match"))
                            {
                                manager.matchMaker.CreateMatch(manager.matchName, manager.matchSize, true, "", "", "", 0, 0, manager.OnMatchCreate);
                            }
                            ypos += spacing;

                            GUI.Label(new Rect(xpos, ypos, 100, 20), "Room Name:");
                            manager.matchName = GUI.TextField(new Rect(xpos + 100, ypos, 100, 20), manager.matchName);
                            ypos += spacing;

                            ypos += 10;

                            if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Find Internet Match"))
                            {
                                manager.matchMaker.ListMatches(0, 20, "", false, 0, 0, manager.OnMatchList);
                            }
                            ypos += spacing;
                        }
                        else
                        {
                            for (int i = 0; i < manager.matches.Count; i++)
                            {
                                var match = manager.matches[i];
                                if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Join Match:" + match.name))
                                {
                                    manager.matchName = match.name;
                                    manager.matchMaker.JoinMatch(match.networkId, "", "", "", 0, 0, manager.OnMatchJoined);
                                }
                                ypos += spacing;
                            }

                            if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Back to Match Menu"))
                            {
                                manager.matches = null;
                            }
                            ypos += spacing;
                        }
                    }

                    if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Change MM server"))
                    {
                        m_ShowServer = !m_ShowServer;
                    }
                    if (m_ShowServer)
                    {
                        ypos += spacing;
                        if (GUI.Button(new Rect(xpos, ypos, 100, 20), "Local"))
                        {
                            manager.SetMatchHost("localhost", 1337, false);
                            m_ShowServer = false;
                        }
                        ypos += spacing;
                        if (GUI.Button(new Rect(xpos, ypos, 100, 20), "Internet"))
                        {
                            manager.SetMatchHost("mm.unet.unity3d.com", 443, true);
                            m_ShowServer = false;
                        }
                        ypos += spacing;
                        if (GUI.Button(new Rect(xpos, ypos, 100, 20), "Staging"))
                        {
                            manager.SetMatchHost("staging-mm.unet.unity3d.com", 443, true);
                            m_ShowServer = false;
                        }
                    }

                    ypos += spacing;

                    GUI.Label(new Rect(xpos, ypos, 300, 20), "MM Uri: " + manager.matchMaker.baseUri);
                    ypos += spacing;

                    if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Disable Match Maker"))
                    {
                        manager.StopMatchMaker();
                    }
                    ypos += spacing;
                }
            }
        }
Example #5
0
        private void OnGUI()
        {
            if (!showGUI)
            {
                return;
            }
            int num  = 10 + offsetX;
            int num2 = 40 + offsetY;

            if (!manager.IsClientConnected() && !NetworkServer.active && manager.matchMaker == null)
            {
                if (GUI.Button(new Rect(num, num2, 200f, 20f), "LAN Host(H)"))
                {
                    manager.StartHost();
                }
                num2 += 24;
                if (GUI.Button(new Rect(num, num2, 105f, 20f), "LAN Client(C)"))
                {
                    manager.StartClient();
                }
                manager.networkAddress = GUI.TextField(new Rect(num + 100, num2, 95f, 20f), manager.networkAddress);
                num2 += 24;
                if (GUI.Button(new Rect(num, num2, 200f, 20f), "LAN Server Only(S)"))
                {
                    manager.StartServer();
                }
                num2 += 24;
            }
            else
            {
                if (NetworkServer.active)
                {
                    GUI.Label(new Rect(num, num2, 300f, 20f), "Server: port=" + manager.networkPort);
                    num2 += 24;
                }
                if (manager.IsClientConnected())
                {
                    GUI.Label(new Rect(num, num2, 300f, 20f), "Client: address=" + manager.networkAddress + " port=" + manager.networkPort);
                    num2 += 24;
                }
            }
            if (manager.IsClientConnected() && !ClientScene.ready)
            {
                if (GUI.Button(new Rect(num, num2, 200f, 20f), "Client Ready"))
                {
                    ClientScene.Ready(manager.client.connection);
                    if (ClientScene.localPlayers.Count == 0)
                    {
                        ClientScene.AddPlayer(0);
                    }
                }
                num2 += 24;
            }
            if (NetworkServer.active || manager.IsClientConnected())
            {
                if (GUI.Button(new Rect(num, num2, 200f, 20f), "Stop (X)"))
                {
                    manager.StopHost();
                }
                num2 += 24;
            }
            if (NetworkServer.active || manager.IsClientConnected())
            {
                return;
            }
            num2 += 10;
            if (manager.matchMaker == null)
            {
                if (GUI.Button(new Rect(num, num2, 200f, 20f), "Enable Match Maker (M)"))
                {
                    manager.StartMatchMaker();
                }
                return;
            }
            if (manager.matchInfo == null)
            {
                if (manager.matches == null)
                {
                    if (GUI.Button(new Rect(num, num2, 200f, 20f), "Create Internet Match"))
                    {
                        NetworkMatch   matchMaker     = manager.matchMaker;
                        string         matchName      = manager.matchName;
                        uint           matchSize      = manager.matchSize;
                        string         empty          = string.Empty;
                        NetworkManager networkManager = manager;
                        matchMaker.CreateMatch(matchName, matchSize, matchAdvertise: true, empty, networkManager.OnMatchCreate);
                    }
                    num2 += 24;
                    GUI.Label(new Rect(num, num2, 100f, 20f), "Room Name:");
                    manager.matchName = GUI.TextField(new Rect(num + 100, num2, 100f, 20f), manager.matchName);
                    num2 += 24;
                    num2 += 10;
                    if (GUI.Button(new Rect(num, num2, 200f, 20f), "Find Internet Match"))
                    {
                        NetworkMatch   matchMaker2     = manager.matchMaker;
                        string         empty2          = string.Empty;
                        NetworkManager networkManager2 = manager;
                        matchMaker2.ListMatches(0, 20, empty2, networkManager2.OnMatchList);
                    }
                    num2 += 24;
                }
                else
                {
                    foreach (MatchDesc match in manager.matches)
                    {
                        if (GUI.Button(new Rect(num, num2, 200f, 20f), "Join Match:" + match.name))
                        {
                            manager.matchName = match.name;
                            manager.matchSize = (uint)match.currentSize;
                            manager.matchMaker.JoinMatch(match.networkId, string.Empty, manager.OnMatchJoined);
                        }
                        num2 += 24;
                    }
                }
            }
            if (GUI.Button(new Rect(num, num2, 200f, 20f), "Change MM server"))
            {
                m_ShowServer = !m_ShowServer;
            }
            if (m_ShowServer)
            {
                num2 += 24;
                if (GUI.Button(new Rect(num, num2, 100f, 20f), "Local"))
                {
                    manager.SetMatchHost("localhost", 1337, https: false);
                    m_ShowServer = false;
                }
                num2 += 24;
                if (GUI.Button(new Rect(num, num2, 100f, 20f), "Internet"))
                {
                    manager.SetMatchHost("mm.unet.unity3d.com", 443, https: true);
                    m_ShowServer = false;
                }
                num2 += 24;
                if (GUI.Button(new Rect(num, num2, 100f, 20f), "Staging"))
                {
                    manager.SetMatchHost("staging-mm.unet.unity3d.com", 443, https: true);
                    m_ShowServer = false;
                }
            }
            num2 += 24;
            GUI.Label(new Rect(num, num2, 300f, 20f), "MM Uri: " + manager.matchMaker.baseUri);
            num2 += 24;
            if (GUI.Button(new Rect(num, num2, 200f, 20f), "Disable Match Maker"))
            {
                manager.StopMatchMaker();
            }
        }
        void OnGUI()
        {
            if (!showGUI)
            {
                return;
            }

            int xpos    = 10 + offsetX;
            int ypos    = 40 + offsetY;
            int spacing = 24;

            int multVal = 5;

            if (!NetworkClient.active && !NetworkServer.active && manager.matchMaker == null)
            {
                if (GUI.Button(new Rect(xpos * multVal, ypos * multVal, 1600, 160), "LAN Host(H)"))
                {
                    manager.StartHost();
                }
                ypos += spacing;

                if (GUI.Button(new Rect(xpos * multVal, ypos * multVal, 105 * multVal, 20 * multVal), "LAN Client(C)"))
                {
                    manager.StartClient();
                }
                manager.networkAddress = GUI.TextField(new Rect((xpos + 100) * multVal, ypos * multVal, 95 * multVal, 20 * multVal), manager.networkAddress);
                ypos += spacing;

                if (GUI.Button(new Rect(xpos * multVal, ypos * multVal, 200 * multVal, 20 * multVal), "LAN Server Only(S)"))
                {
                    manager.StartServer();
                }
                ypos += spacing;
            }
            else
            {
                if (NetworkServer.active)
                {
                    GUI.Label(new Rect(xpos, ypos, 300, 20), "Server: port=" + manager.networkPort);
                    ypos += spacing;
                }
                if (NetworkClient.active)
                {
                    GUI.Label(new Rect(xpos, ypos, 300, 20), "Client: address=" + manager.networkAddress + " port=" + manager.networkPort);
                    ypos += spacing;
                }
            }

            if (NetworkClient.active && !ClientScene.ready)
            {
                if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Client Ready"))
                {
                    ClientScene.Ready(manager.client.connection);

                    if (ClientScene.localPlayers.Count == 0)
                    {
                        ClientScene.AddPlayer(0);
                    }
                }
                ypos += spacing;
            }

            if (NetworkServer.active || NetworkClient.active)
            {
                if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Stop (X)"))
                {
                    manager.StopHost();
                }
                ypos += spacing;
            }

            if (!NetworkServer.active && !NetworkClient.active)
            {
                ypos += 10;

                if (manager.matchMaker == null)
                {
                    if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Enable Match Maker (M)"))
                    {
                        manager.StartMatchMaker();
                    }
                    ypos += spacing;
                }
                else
                {
                    if (manager.matchInfo == null)
                    {
                        if (manager.matches == null)
                        {
                            if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Create Internet Match"))
                            {
                                //    manager.matchMaker.CreateMatch(manager.matchName, manager.matchSize, true, "", manager.OnMatchCreate);
                            }
                            ypos += spacing;

                            GUI.Label(new Rect(xpos, ypos, 100, 20), "Room Name:");
                            manager.matchName = GUI.TextField(new Rect(xpos + 100, ypos, 100, 20), manager.matchName);
                            ypos += spacing;

                            ypos += 10;

                            if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Find Internet Match"))
                            {
                                //     manager.matchMaker.ListMatches(0, 20, "", manager.OnMatchList);
                            }
                            ypos += spacing;
                        }
                        else
                        {
                            foreach (var match in manager.matches)
                            {
                                if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Join Match:" + match.name))
                                {
                                    manager.matchName = match.name;
                                    manager.matchSize = (uint)match.currentSize;
                                    //manager.matchMaker.JoinMatch(match.networkId, "", manager.OnMatchJoined);
                                }
                                ypos += spacing;
                            }
                        }
                    }

                    if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Change MM server"))
                    {
                        showServer = !showServer;
                    }
                    if (showServer)
                    {
                        ypos += spacing;
                        if (GUI.Button(new Rect(xpos, ypos, 100, 20), "Local"))
                        {
                            manager.SetMatchHost("localhost", 1337, false);
                            showServer = false;
                        }
                        ypos += spacing;
                        if (GUI.Button(new Rect(xpos, ypos, 100, 20), "Internet"))
                        {
                            manager.SetMatchHost("mm.unet.unity3d.com", 443, true);
                            showServer = false;
                        }
                        ypos += spacing;
                        if (GUI.Button(new Rect(xpos, ypos, 100, 20), "Staging"))
                        {
                            manager.SetMatchHost("staging-mm.unet.unity3d.com", 443, true);
                            showServer = false;
                        }
                    }

                    ypos += spacing;

                    GUI.Label(new Rect(xpos, ypos, 300, 20), "MM Uri: " + manager.matchMaker.baseUri);
                    ypos += spacing;

                    if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Disable Match Maker"))
                    {
                        manager.StopMatchMaker();
                    }
                    ypos += spacing;
                }
            }
        }
Example #7
0
        void OnGUI()
        {
            int        numPlayers     = lobby.GetComponent <Lobby> ().activePlayers;
            int        maxPlayers     = GetComponent <ControllerNet> ().maxPlayers;
            GameObject waitingPlayers = GameObject.Find("WaitingPlayers");

            if (waitingPlayers != null)
            {
                //Client ready but not the scene
                if (numPlayers < maxPlayers || maxPlayers == -1)
                {
                    if (NetworkClient.active || NetworkServer.active)
                    {
                        string strNumPlayers = "";

                        if (numPlayers == 0)
                        {
                            numPlayers = 1;
                        }

                        strNumPlayers = "Currently " + numPlayers;

                        if (maxPlayers != -1)
                        {
                            strNumPlayers += " of " + maxPlayers;
                        }

                        waitingPlayers.GetComponent <Text> ().text = "Waiting for other players\n" + strNumPlayers;
                    }
                }
                else
                {
                    if (waitingPlayers != null)
                    {
                        alphaBGWaitingPlayers -= Time.deltaTime;

                        if (alphaBGWaitingPlayers <= 0f)
                        {
                            alphaBGWaitingPlayers = 0f;
                            GameObject.Find("BGWaitingPlayers").SetActive(false);
                        }
                        else
                        {
                            //
                            Color alphaColor = new Color(1f, 1f, 1f, alphaBGWaitingPlayers);
                            GameObject.Find("BGWaitingPlayers").GetComponent <Image> ().color = alphaColor;
                            waitingPlayers.GetComponent <Text> ().color = alphaColor;
                            GameObject.Find("BGWaitingPlayers").transform.FindChild("Logo").GetComponent <Image> ().color = alphaColor;
                        }
                    }
                }
            }

            if (!showGUI)
            {
                return;
            }

            int xpos    = 10 + offsetX;
            int ypos    = 40 + offsetY;
            int spacing = 24;

            if (!NetworkClient.active && !NetworkServer.active && manager.matchMaker == null)
            {
                if (GUI.Button(new Rect(xpos, ypos, 100, 20), "Drifter"))
                {
                    classType = 0;
                }

                if (GUI.Button(new Rect(xpos + 100, ypos, 100, 20), "Miner"))
                {
                    classType = 1;
                }

                if (GUI.Button(new Rect(xpos + 200, ypos, 100, 20), "Camper"))
                {
                    classType = 2;
                }

                ypos += spacing;

                if (GUI.Button(new Rect(xpos, ypos, 100, 20), "Blue Team"))
                {
                    team = 0;
                }

                if (GUI.Button(new Rect(xpos + 100, ypos, 100, 20), "Red Team"))
                {
                    team = 1;
                }

                ypos += spacing;

                player = GUI.TextField(new Rect(xpos, ypos, 200, 20), player);
                ypos  += spacing;

                if (GUI.Button(new Rect(xpos, ypos, 200, 20), "LAN Host(H)"))
                {
                    manager.StartHost();

                    //LoaderClass loaderScript = manager.playerPrefab.gameObject.GetComponent<LoaderClass> ();
                    //loaderScript.typeClass = classType;
                }
                ypos += spacing;

                if (GUI.Button(new Rect(xpos, ypos, 105, 20), "LAN Client(C)"))
                {
                    manager.StartClient();

                    //LoaderClass loaderScript = manager.playerPrefab.gameObject.GetComponent<LoaderClass> ();
                    //loaderScript.typeClass = classType;
                }
                manager.networkAddress = GUI.TextField(new Rect(xpos + 100, ypos, 95, 20), manager.networkAddress);
                ypos += spacing;

                if (GUI.Button(new Rect(xpos, ypos, 200, 20), "LAN Server Only(S)"))
                {
                    manager.StartServer();
                }
                ypos += spacing;
            }
            else
            {
                if (NetworkServer.active)
                {
                    //GUI.Label(new Rect(xpos, ypos, 300, 20), "Server: port=" + manager.networkPort);
                    //ypos += spacing;
                }
                if (NetworkClient.active)
                {
                    //GUI.Label(new Rect(xpos, ypos, 300, 20), "Client: address=" + manager.networkAddress + " port=" + manager.networkPort);
                    //ypos += spacing;
                }
            }

            if (NetworkClient.active && !ClientScene.ready)
            {
                if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Client Ready"))
                {
                    ClientScene.Ready(manager.client.connection);

                    if (ClientScene.localPlayers.Count == 0)
                    {
                        ClientScene.AddPlayer(0);
                    }
                }
                ypos += spacing;
            }

            if (NetworkServer.active || NetworkClient.active)
            {
                //if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Stop (X)"))
                //{
                //	manager.StopHost();
                //}
                //ypos += spacing;
            }
            if (!NetworkServer.active && !NetworkClient.active)
            {
                ypos += 10;

                if (manager.matchMaker == null)
                {
                    if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Enable Match Maker (M)"))
                    {
                        manager.StartMatchMaker();
                    }
                    ypos += spacing;
                }
                else
                {
                    if (manager.matchInfo == null)
                    {
                        if (manager.matches == null)
                        {
                            if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Create Internet Match"))
                            {
                                manager.matchMaker.CreateMatch(manager.matchName, manager.matchSize, true, "", manager.OnMatchCreate);
                            }
                            ypos += spacing;

                            GUI.Label(new Rect(xpos, ypos, 100, 20), "Room Name:");
                            manager.matchName = GUI.TextField(new Rect(xpos + 100, ypos, 100, 20), manager.matchName);
                            ypos += spacing;

                            ypos += 10;

                            if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Find Internet Match"))
                            {
                                manager.matchMaker.ListMatches(0, 20, "", manager.OnMatchList);
                            }
                            ypos += spacing;
                        }
                        else
                        {
                            foreach (var match in manager.matches)
                            {
                                if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Join Match:" + match.name))
                                {
                                    manager.matchName = match.name;
                                    manager.matchSize = (uint)match.currentSize;
                                    manager.matchMaker.JoinMatch(match.networkId, "", manager.OnMatchJoined);
                                }
                                ypos += spacing;
                            }
                        }
                    }

                    if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Change MM server"))
                    {
                        showServer = !showServer;
                    }
                    if (showServer)
                    {
                        ypos += spacing;
                        if (GUI.Button(new Rect(xpos, ypos, 100, 20), "Local"))
                        {
                            manager.SetMatchHost("localhost", 1337, false);
                            showServer = false;
                        }
                        ypos += spacing;
                        if (GUI.Button(new Rect(xpos, ypos, 100, 20), "Internet"))
                        {
                            manager.SetMatchHost("mm.unet.unity3d.com", 443, true);
                            showServer = false;
                        }
                        ypos += spacing;
                        if (GUI.Button(new Rect(xpos, ypos, 100, 20), "Staging"))
                        {
                            manager.SetMatchHost("staging-mm.unet.unity3d.com", 443, true);
                            showServer = false;
                        }
                    }

                    ypos += spacing;

                    GUI.Label(new Rect(xpos, ypos, 300, 20), "MM Uri: " + manager.matchMaker.baseUri);
                    ypos += spacing;

                    if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Disable Match Maker"))
                    {
                        manager.StopMatchMaker();
                    }
                    ypos += spacing;
                }
            }
        }
Example #8
0
        public void OnGUI()
        {
            if (!showGUI)
            {
                return;
            }

            int xpos    = 10 + offsetX;
            int ypos    = 40 + offsetY;
            int spacing = 24;

            if (!NetworkClient.active && !NetworkServer.active && manager.matchMaker == null)
            {
                if (GUI.Button(new Rect(xpos, ypos, 200, 20), "LAN Host(H)"))
                {
                    this.showGUI = false;
                    Debug.Log("Starting host.");
                    manager.StartHost();
                }
                ypos += spacing;

                if (GUI.Button(new Rect(xpos, ypos, 105, 20), "LAN Client(C)"))
                {
                    Debug.Log("Starting client.");
                    manager.StartClient();
                }
                manager.networkAddress = GUI.TextField(new Rect(xpos + 100, ypos, 95, 20), manager.networkAddress);
                ypos += spacing;

                if (GUI.Button(new Rect(xpos, ypos, 200, 20), "LAN Server Only(S)"))
                {
                    this.showGUI = false;
                    Debug.Log("Starting server.");
                    manager.StartServer();
                }
                ypos += spacing;
            }
            else
            {
                if (NetworkServer.active)
                {
                    GUI.Label(new Rect(xpos, ypos, 300, 20), "Server: address=" + manager.networkAddress + " port=" + manager.networkPort, this.style);
                    ypos += spacing;
                }
                else if (NetworkClient.active)
                {
                    GUI.Label(new Rect(xpos, ypos, 300, 20), "Client: address=" + manager.networkAddress + " port=" + manager.networkPort, this.style);
                    ypos += spacing;
                }
            }

            if (NetworkClient.active && !ClientScene.ready)
            {
                if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Client Ready"))
                {
                    ClientScene.Ready(manager.client.connection);
                    this.showGUI = false;
                    if (ClientScene.localPlayers.Count == 0)
                    {
                        ClientScene.AddPlayer(0);
                    }
                }
                ypos += spacing;
            }


            if (NetworkServer.active || NetworkClient.active)
            {
                if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Stop (K)"))
                {
                    Debug.Log("Stopping host.");
                    manager.StopHost();
                    if (NetworkClient.active)
                    {
                        Debug.Log("Also stopping client.");
                        manager.StopClient();
                    }
                    this.showGUI = true;
                }
                ypos += spacing;
            }

            if (!NetworkServer.active && !NetworkClient.active)
            {
                ypos += 10;

                if (manager.matchMaker == null)
                {
                    if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Enable Match Maker (M)"))
                    {
                        Debug.Log("Starting match maker.");
                        manager.StartMatchMaker();
                    }
                    ypos += spacing;
                }
                else
                {
                    if (manager.matchInfo == null)
                    {
                        if (manager.matches == null)
                        {
                            if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Create Internet Match"))
                            {
                                manager.matchMaker.CreateMatch(manager.matchName, manager.matchSize, true, "", manager.OnMatchCreate);
                            }
                            ypos += spacing;

                            GUI.Label(new Rect(xpos, ypos, 100, 20), "Room Name:");
                            manager.matchName = GUI.TextField(new Rect(xpos + 100, ypos, 100, 20), manager.matchName);
                            ypos += spacing;

                            ypos += 10;

                            if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Find Internet Match"))
                            {
                                manager.matchMaker.ListMatches(0, 20, "", manager.OnMatchList);
                            }
                            ypos += spacing;
                        }
                        else
                        {
                            foreach (var match in manager.matches)
                            {
                                if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Join Match:" + match.name))
                                {
                                    manager.matchName = match.name;
                                    manager.matchSize = (uint)match.currentSize;
                                    manager.matchMaker.JoinMatch(match.networkId, "", manager.OnMatchJoined);
                                }
                                ypos += spacing;
                            }
                        }
                    }

                    if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Change MM server"))
                    {
                        showServer = !showServer;
                    }
                    if (showServer)
                    {
                        ypos += spacing;
                        if (GUI.Button(new Rect(xpos, ypos, 100, 20), "Local"))
                        {
                            manager.SetMatchHost("localhost", 1337, false);
                            showServer = false;
                        }
                        ypos += spacing;
                        if (GUI.Button(new Rect(xpos, ypos, 100, 20), "Internet"))
                        {
                            manager.SetMatchHost("mm.unet.unity3d.com", 443, true);
                            showServer = false;
                        }
                        ypos += spacing;
                        if (GUI.Button(new Rect(xpos, ypos, 100, 20), "Staging"))
                        {
                            manager.SetMatchHost("staging-mm.unet.unity3d.com", 443, true);
                            showServer = false;
                        }
                    }

                    ypos += spacing;

                    GUI.Label(new Rect(xpos, ypos, 300, 20), "MM Uri: " + manager.matchMaker.baseUri);
                    ypos += spacing;

                    if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Disable Match Maker"))
                    {
                        Debug.Log("Stopping match maker.");
                        manager.StopMatchMaker();
                    }
                    ypos += spacing;
                }
            }

            if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Return to Main Menu"))
            {
                if (NetworkServer.active || NetworkClient.active)
                {
                    Debug.Log("Stopping host.");
                    manager.StopHost();
                    this.showGUI = false;
                }


#if (UNITY_5_2_3 || UNITY_5_2_4)
                Application.LoadLevel("menu");
#else
                SceneManager.LoadScene("menu");
#endif
            }
            ypos += spacing;
        }
Example #9
0
        private void OnGUI()
        {
            if (!showGUI)
            {
                return;
            }
            int  num  = 10 + offsetX;
            int  num2 = 40 + offsetY;
            bool flag = manager.client == null || manager.client.connection == null || manager.client.connection.connectionId == -1;

            if (!manager.IsClientConnected() && !NetworkServer.active && manager.matchMaker == null)
            {
                if (flag)
                {
                    if (Application.platform != RuntimePlatform.WebGLPlayer)
                    {
                        if (GUI.Button(new Rect(num, num2, 200f, 20f), "LAN Host(H)"))
                        {
                            manager.StartHost();
                        }
                        num2 += 24;
                    }
                    if (GUI.Button(new Rect(num, num2, 105f, 20f), "LAN Client(C)"))
                    {
                        manager.StartClient();
                    }
                    manager.networkAddress = GUI.TextField(new Rect(num + 100, num2, 95f, 20f), manager.networkAddress);
                    num2 += 24;
                    if (Application.platform == RuntimePlatform.WebGLPlayer)
                    {
                        GUI.Box(new Rect(num, num2, 200f, 25f), "(  WebGL cannot be server  )");
                        num2 += 24;
                    }
                    else
                    {
                        if (GUI.Button(new Rect(num, num2, 200f, 20f), "LAN Server Only(S)"))
                        {
                            manager.StartServer();
                        }
                        num2 += 24;
                    }
                }
                else
                {
                    GUI.Label(new Rect(num, num2, 200f, 20f), "Connecting to " + manager.networkAddress + ":" + manager.networkPort + "..");
                    num2 += 24;
                    if (GUI.Button(new Rect(num, num2, 200f, 20f), "Cancel Connection Attempt"))
                    {
                        manager.StopClient();
                    }
                }
            }
            else
            {
                if (NetworkServer.active)
                {
                    string text = "Server: port=" + manager.networkPort;
                    if (manager.useWebSockets)
                    {
                        text += " (Using WebSockets)";
                    }
                    GUI.Label(new Rect(num, num2, 300f, 20f), text);
                    num2 += 24;
                }
                if (manager.IsClientConnected())
                {
                    GUI.Label(new Rect(num, num2, 300f, 20f), "Client: address=" + manager.networkAddress + " port=" + manager.networkPort);
                    num2 += 24;
                }
            }
            if (manager.IsClientConnected() && !ClientScene.ready)
            {
                if (GUI.Button(new Rect(num, num2, 200f, 20f), "Client Ready"))
                {
                    ClientScene.Ready(manager.client.connection);
                    if (ClientScene.localPlayers.Count == 0)
                    {
                        ClientScene.AddPlayer(0);
                    }
                }
                num2 += 24;
            }
            if (NetworkServer.active || manager.IsClientConnected())
            {
                if (GUI.Button(new Rect(num, num2, 200f, 20f), "Stop (X)"))
                {
                    manager.StopHost();
                }
                num2 += 24;
            }
            if (NetworkServer.active || manager.IsClientConnected() || !flag)
            {
                return;
            }
            num2 += 10;
            if (Application.platform == RuntimePlatform.WebGLPlayer)
            {
                GUI.Box(new Rect(num - 5, num2, 220f, 25f), "(WebGL cannot use Match Maker)");
                return;
            }
            if (manager.matchMaker == null)
            {
                if (GUI.Button(new Rect(num, num2, 200f, 20f), "Enable Match Maker (M)"))
                {
                    manager.StartMatchMaker();
                }
                num2 += 24;
                return;
            }
            if (manager.matchInfo == null)
            {
                if (manager.matches == null)
                {
                    if (GUI.Button(new Rect(num, num2, 200f, 20f), "Create Internet Match"))
                    {
                        NetworkMatch   matchMaker     = manager.matchMaker;
                        string         matchName      = manager.matchName;
                        uint           matchSize      = manager.matchSize;
                        NetworkManager networkManager = manager;
                        matchMaker.CreateMatch(matchName, matchSize, matchAdvertise: true, "", "", "", 0, 0, networkManager.OnMatchCreate);
                    }
                    num2 += 24;
                    GUI.Label(new Rect(num, num2, 100f, 20f), "Room Name:");
                    manager.matchName = GUI.TextField(new Rect(num + 100, num2, 100f, 20f), manager.matchName);
                    num2 += 24;
                    num2 += 10;
                    if (GUI.Button(new Rect(num, num2, 200f, 20f), "Find Internet Match"))
                    {
                        NetworkMatch   matchMaker2     = manager.matchMaker;
                        NetworkManager networkManager2 = manager;
                        matchMaker2.ListMatches(0, 20, "", filterOutPrivateMatchesFromResults: false, 0, 0, networkManager2.OnMatchList);
                    }
                    num2 += 24;
                }
                else
                {
                    for (int i = 0; i < manager.matches.Count; i++)
                    {
                        MatchInfoSnapshot matchInfoSnapshot = manager.matches[i];
                        if (GUI.Button(new Rect(num, num2, 200f, 20f), "Join Match:" + matchInfoSnapshot.name))
                        {
                            manager.matchName = matchInfoSnapshot.name;
                            NetworkMatch   matchMaker3     = manager.matchMaker;
                            NetworkID      networkId       = matchInfoSnapshot.networkId;
                            NetworkManager networkManager3 = manager;
                            matchMaker3.JoinMatch(networkId, "", "", "", 0, 0, networkManager3.OnMatchJoined);
                        }
                        num2 += 24;
                    }
                    if (GUI.Button(new Rect(num, num2, 200f, 20f), "Back to Match Menu"))
                    {
                        manager.matches = null;
                    }
                    num2 += 24;
                }
            }
            if (GUI.Button(new Rect(num, num2, 200f, 20f), "Change MM server"))
            {
                m_ShowServer = !m_ShowServer;
            }
            if (m_ShowServer)
            {
                num2 += 24;
                if (GUI.Button(new Rect(num, num2, 100f, 20f), "Local"))
                {
                    manager.SetMatchHost("localhost", 1337, https: false);
                    m_ShowServer = false;
                }
                num2 += 24;
                if (GUI.Button(new Rect(num, num2, 100f, 20f), "Internet"))
                {
                    manager.SetMatchHost("mm.unet.unity3d.com", 443, https: true);
                    m_ShowServer = false;
                }
                num2 += 24;
                if (GUI.Button(new Rect(num, num2, 100f, 20f), "Staging"))
                {
                    manager.SetMatchHost("staging-mm.unet.unity3d.com", 443, https: true);
                    m_ShowServer = false;
                }
            }
            num2 += 24;
            GUI.Label(new Rect(num, num2, 300f, 20f), "MM Uri: " + manager.matchMaker.baseUri);
            num2 += 24;
            if (GUI.Button(new Rect(num, num2, 200f, 20f), "Disable Match Maker"))
            {
                manager.StopMatchMaker();
            }
            num2 += 24;
        }
Example #10
0
 public void Local()
 {
     manager.SetMatchHost("localhost", 1337, false);
     m_ShowServer = false;
 }