AddPlayer() public static method

This adds a player GameObject for this client. This causes an AddPlayer message to be sent to the server, and NetworkManager.OnServerAddPlayer is called. If an extra message was passed to AddPlayer, then OnServerAddPlayer will be called with a NetworkReader that contains the contents of the message.

public static AddPlayer ( NetworkConnection readyConn, short playerControllerId ) : bool
readyConn NetworkConnection The connection to become ready for this client.
playerControllerId short The local player ID number.
return bool
Example #1
0
        void OnGUI()
        {
            if (!showGUI)
            {
                return;
            }

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

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

                if (GUI.Button(new Rect(xpos, ypos, 210, 40), "LAN Client(C)"))
                {
                    manager.StartClient();
                }
                manager.networkAddress = GUI.TextField(new Rect(xpos + 200, ypos, 190, 40), manager.networkAddress);
                ypos += spacing;

                if (GUI.Button(new Rect(xpos, ypos, 400, 40), "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, 400, 40), "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 += 20;

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

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

                            ypos += 20;

                            if (GUI.Button(new Rect(xpos, ypos, 400, 40), "Find Internet Match"))
                            {
                                manager.matchMaker.ListMatches(0, 40, "", manager.OnMatchList);
                            }
                            ypos += spacing;
                        }
                        else
                        {
                            foreach (var match in manager.matches)
                            {
                                if (GUI.Button(new Rect(xpos, ypos, 400, 40), "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, 400, 40), "Change MM server"))
                    {
                        showServer = !showServer;
                    }
                    if (showServer)
                    {
                        ypos += spacing;
                        if (GUI.Button(new Rect(xpos, ypos, 200, 40), "Local"))
                        {
                            manager.SetMatchHost("localhost", 1337, false);
                            showServer = false;
                        }
                        ypos += spacing;
                        if (GUI.Button(new Rect(xpos, ypos, 200, 40), "Internet"))
                        {
                            manager.SetMatchHost("mm.unet.unity3d.com", 443, true);
                            showServer = false;
                        }
                        ypos += spacing;
                        if (GUI.Button(new Rect(xpos, ypos, 200, 40), "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, 400, 40), "Disable Match Maker"))
                    {
                        manager.StopMatchMaker();
                    }
                    ypos += spacing;
                }
            }
        }
Example #2
0
        void OnGUI()
        {
            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 + 200, ypos, 200, 200), "LAN Host(H)"))
                        {
                            manager.StartHost();
                        }
                        ypos += spacing;
                    }

                    if (GUI.Button(new Rect(xpos + 100, ypos + 300, 305, 200), "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;
            }
        }
        private void OnGUI()
        {
            if (!this.showGUI)
            {
                return;
            }
            int num  = 10 + this.offsetX;
            int num2 = 40 + this.offsetY;

            if (!this.manager.IsClientConnected() && !NetworkServer.active && this.manager.matchMaker == null)
            {
                if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "LAN Host(H)"))
                {
                    this.manager.StartHost();
                }
                num2 += 24;
                if (GUI.Button(new Rect((float)num, (float)num2, 105f, 20f), "LAN Client(C)"))
                {
                    this.manager.StartClient();
                }
                this.manager.networkAddress = GUI.TextField(new Rect((float)(num + 100), (float)num2, 95f, 20f), this.manager.networkAddress);
                num2 += 24;
                if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "LAN Server Only(S)"))
                {
                    this.manager.StartServer();
                }
                num2 += 24;
            }
            else
            {
                if (NetworkServer.active)
                {
                    GUI.Label(new Rect((float)num, (float)num2, 300f, 20f), "Server: port=" + this.manager.networkPort);
                    num2 += 24;
                }
                if (this.manager.IsClientConnected())
                {
                    GUI.Label(new Rect((float)num, (float)num2, 300f, 20f), string.Concat(new object[]
                    {
                        "Client: address=",
                        this.manager.networkAddress,
                        " port=",
                        this.manager.networkPort
                    }));
                    num2 += 24;
                }
            }
            if (this.manager.IsClientConnected() && !ClientScene.ready)
            {
                if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Client Ready"))
                {
                    ClientScene.Ready(this.manager.client.connection);
                    if (ClientScene.localPlayers.Count == 0)
                    {
                        ClientScene.AddPlayer(0);
                    }
                }
                num2 += 24;
            }
            if (NetworkServer.active || this.manager.IsClientConnected())
            {
                if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Stop (X)"))
                {
                    this.manager.StopHost();
                }
                num2 += 24;
            }
            if (!NetworkServer.active && !this.manager.IsClientConnected())
            {
                num2 += 10;
                if (this.manager.matchMaker == null)
                {
                    if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Enable Match Maker (M)"))
                    {
                        this.manager.StartMatchMaker();
                    }
                    num2 += 24;
                }
                else
                {
                    if (this.manager.matchInfo == null)
                    {
                        if (this.manager.matches == null)
                        {
                            if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Create Internet Match"))
                            {
                                this.manager.matchMaker.CreateMatch(this.manager.matchName, this.manager.matchSize, true, string.Empty, new NetworkMatch.ResponseDelegate <CreateMatchResponse>(this.manager.OnMatchCreate));
                            }
                            num2 += 24;
                            GUI.Label(new Rect((float)num, (float)num2, 100f, 20f), "Room Name:");
                            this.manager.matchName = GUI.TextField(new Rect((float)(num + 100), (float)num2, 100f, 20f), this.manager.matchName);
                            num2 += 24;
                            num2 += 10;
                            if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Find Internet Match"))
                            {
                                this.manager.matchMaker.ListMatches(0, 20, string.Empty, new NetworkMatch.ResponseDelegate <ListMatchResponse>(this.manager.OnMatchList));
                            }
                            num2 += 24;
                        }
                        else
                        {
                            foreach (MatchDesc current in this.manager.matches)
                            {
                                if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Join Match:" + current.name))
                                {
                                    this.manager.matchName = current.name;
                                    this.manager.matchSize = (uint)current.currentSize;
                                    this.manager.matchMaker.JoinMatch(current.networkId, string.Empty, new NetworkMatch.ResponseDelegate <JoinMatchResponse>(this.manager.OnMatchJoined));
                                }
                                num2 += 24;
                            }
                        }
                    }
                    if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Change MM server"))
                    {
                        this.m_ShowServer = !this.m_ShowServer;
                    }
                    if (this.m_ShowServer)
                    {
                        num2 += 24;
                        if (GUI.Button(new Rect((float)num, (float)num2, 100f, 20f), "Local"))
                        {
                            this.manager.SetMatchHost("localhost", 1337, false);
                            this.m_ShowServer = false;
                        }
                        num2 += 24;
                        if (GUI.Button(new Rect((float)num, (float)num2, 100f, 20f), "Internet"))
                        {
                            this.manager.SetMatchHost("mm.unet.unity3d.com", 443, true);
                            this.m_ShowServer = false;
                        }
                        num2 += 24;
                        if (GUI.Button(new Rect((float)num, (float)num2, 100f, 20f), "Staging"))
                        {
                            this.manager.SetMatchHost("staging-mm.unet.unity3d.com", 443, true);
                            this.m_ShowServer = false;
                        }
                    }
                    num2 += 24;
                    GUI.Label(new Rect((float)num, (float)num2, 300f, 20f), "MM Uri: " + this.manager.matchMaker.baseUri);
                    num2 += 24;
                    if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Disable Match Maker"))
                    {
                        this.manager.StopMatchMaker();
                    }
                    num2 += 24;
                }
            }
        }
Example #4
0
        private void OnGUI()
        {
            if (!this.showGUI)
            {
                return;
            }
            int  num  = 10 + this.offsetX;
            int  num2 = 40 + this.offsetY;
            bool flag = this.manager.client == null || this.manager.client.connection == null || this.manager.client.connection.connectionId == -1;

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

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

            if (!manager.IsClientConnected() && !NetworkServer.active)
            {
                if (noConnection)
                {
                    if (GUI.Button(new Rect(xpos, ypos, buttonWidth, buttonHeight), "LAN Host(H)"))
                    {
                        manager.StartHost();
                    }
                    ypos += spacing;

                    if (GUI.Button(new Rect(xpos, ypos, buttonWidth / 2, buttonHeight), "LAN Client(C)"))
                    {
                        manager.StartClient();
                    }
                    manager.networkAddress = GUI.TextField(new Rect(xpos + buttonWidth / 2, ypos, buttonWidth / 2, buttonHeight), manager.networkAddress);
                    ypos += spacing;

                    if (GUI.Button(new Rect(xpos, ypos, buttonWidth, buttonHeight), "LAN Server Only(S)"))
                    {
                        manager.StartServer();
                    }
                    ypos += spacing;
                }
                else
                {
                    GUI.Label(new Rect(xpos, ypos, buttonWidth, buttonHeight), "Connecting to " + manager.networkAddress + ":" + manager.networkPort + "..");
                    ypos += spacing;


                    if (GUI.Button(new Rect(xpos, ypos, buttonWidth, buttonHeight), "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, buttonWidth, buttonHeight), serverMsg);
            //        ypos += spacing;
            //    }
            //    if (manager.IsClientConnected())
            //    {
            //        GUI.Label(new Rect(xpos, ypos, buttonWidth, buttonHeight), "Client: address=" + manager.networkAddress + " port=" + manager.networkPort);
            //        ypos += spacing;
            //    }
            //}

            if (manager.IsClientConnected() && !ClientScene.ready)
            {
                if (GUI.Button(new Rect(xpos, ypos, buttonWidth, buttonHeight), "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, buttonWidth, buttonHeight), "Quit"))
            //    {
            //        manager.StopHost();
            //    }
            //    ypos += spacing;
            //}
        }
Example #6
0
        void OnGUI()
        {
            if (!showGUI)
            {
                return;
            }

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

            GUILayout.BeginArea(new Rect(10 + offsetX, 40 + offsetY, 215, 9999));
            if (!manager.IsClientConnected() && !NetworkServer.active)
            {
                if (noConnection)
                {
                    // LAN Host
                    if (Application.platform != RuntimePlatform.WebGLPlayer)
                    {
                        if (GUILayout.Button("LAN Host"))
                        {
                            manager.StartHost();
                        }
                    }

                    // LAN Client + IP
                    GUILayout.BeginHorizontal();
                    if (GUILayout.Button("LAN Client"))
                    {
                        manager.StartClient();
                    }
                    manager.networkAddress = GUILayout.TextField(manager.networkAddress);
                    GUILayout.EndHorizontal();

                    // LAN Server Only
                    if (Application.platform == RuntimePlatform.WebGLPlayer)
                    {
                        // cant be a server in webgl build
                        GUILayout.Box("(  WebGL cannot be server  )");
                    }
                    else
                    {
                        if (GUILayout.Button("LAN Server Only"))
                        {
                            manager.StartServer();
                        }
                    }
                }
                else
                {
                    // Connecting
                    GUILayout.Label("Connecting to " + manager.networkAddress + ":" + manager.networkPort + "..");
                    if (GUILayout.Button("Cancel Connection Attempt"))
                    {
                        manager.StopClient();
                    }
                }
            }
            else
            {
                // server / client status message
                if (NetworkServer.active)
                {
                    string serverMsg = "Server: port=" + manager.networkPort;
                    if (manager.useWebSockets)
                    {
                        serverMsg += " (Using WebSockets)";
                    }

                    GUILayout.Label(serverMsg);
                }
                if (manager.IsClientConnected())
                {
                    GUILayout.Label("Client: address=" + manager.networkAddress + " port=" + manager.networkPort);
                }
            }

            // client ready
            if (manager.IsClientConnected() && !ClientScene.ready)
            {
                if (GUILayout.Button("Client Ready"))
                {
                    ClientScene.Ready(manager.client.connection);

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

            // stop
            if (NetworkServer.active || manager.IsClientConnected())
            {
                if (GUILayout.Button("Stop"))
                {
                    manager.StopHost();
                }
            }

            GUILayout.EndArea();
        }
Example #7
0
 /// <summary>
 ///   <para>This adds a player object for this client. This causes an AddPlayer message to be sent to the server, and NetworkManager.OnServerAddPlayer will be called. If an extra message was passed to AddPlayer, then OnServerAddPlayer will be called with a NetworkReader that contains the contents of the message.</para>
 /// </summary>
 /// <param name="readyConn">The connection to become ready for this client.</param>
 /// <param name="playerControllerId">The local player ID number.</param>
 /// <param name="extraMessage">An extra message object that can be passed to the server for this player.</param>
 /// <returns>
 ///   <para>True if player was added.</para>
 /// </returns>
 public static bool AddPlayer(NetworkConnection readyConn, short playerControllerId)
 {
     return(ClientScene.AddPlayer(readyConn, playerControllerId, (MessageBase)null));
 }
Example #8
0
 /// <summary>
 ///   <para>This adds a player object for this client. This causes an AddPlayer message to be sent to the server, and NetworkManager.OnServerAddPlayer will be called. If an extra message was passed to AddPlayer, then OnServerAddPlayer will be called with a NetworkReader that contains the contents of the message.</para>
 /// </summary>
 /// <param name="readyConn">The connection to become ready for this client.</param>
 /// <param name="playerControllerId">The local player ID number.</param>
 /// <param name="extraMessage">An extra message object that can be passed to the server for this player.</param>
 /// <returns>
 ///   <para>True if player was added.</para>
 /// </returns>
 public static bool AddPlayer(short playerControllerId)
 {
     return(ClientScene.AddPlayer((NetworkConnection)null, playerControllerId));
 }
Example #9
0
 public static bool AddPlayer(short playerControllerId)
 {
     return(ClientScene.AddPlayer(null, playerControllerId));
 }