Ejemplo n.º 1
0
    // Send a list of all the player names and ready-state to the player.
    private void sendLobbyPlayersMessage(int id)
    {
        LobbyPlayerMessage message = new LobbyPlayerMessage();
        List <Player>      players = new List <Player>();

        // Update the ready-state for each connected lobby player.
        foreach (var conn in NetworkServer.connections)
        {
            NetworkLobbyPlayer lobbyPlayer = null;

            if ((conn != null) && (conn.playerControllers.Count > 0) && (conn.playerControllers[0].gameObject != null))
            {
                lobbyPlayer = conn.playerControllers[0].gameObject.GetComponent <NetworkLobbyPlayer>();
            }

            if (lobbyPlayer != null)
            {
                this._players[conn.connectionId].readyLobby = lobbyPlayer.readyToBegin;
                players.Add(this._players[conn.connectionId]);
            }
        }

        message.players = new LobbyPlayer[players.Count];

        for (int i = 0; i < players.Count; i++)
        {
            message.players[i]        = new LobbyPlayer();
            message.players[i].name   = players[i].name;
            message.players[i].animal = players[i].animal;
            message.players[i].ready  = players[i].readyLobby;
        }

        NetworkServer.SendToClient(id, (short)NetworkMessageType.MSG_LOBBY_PLAYERS, message);
    }
Ejemplo n.º 2
0
        public override void Execute()
        {
            var message = new LobbyPlayerMessage
            {
                Id   = MyNetworkPlayer.Id,
                Name = MyNetworkPlayer.Name
            };

            // Send lobby player to client
            GameServerService.Send(GameServerService.ActiveConnections, MsgStruct.SendLobbyPlayer, message);
        }
Ejemplo n.º 3
0
    // Update the list of names and ready-state of lobby players.
    private void updateRoom(LobbyPlayerMessage message)
    {
        if (!this._inRoom || (this._lobbyPanel == null))
        {
            return;
        }

        string        matchName;
        RectTransform rt;
        GameObject    title    = this._lobbyPanel.transform.GetChild(0).GetChild(0).gameObject;
        GameObject    template = this._lobbyPanel.transform.GetChild(0).GetChild(1).gameObject;

        if (title != null)
        {
            matchName = (this._matchName != "" ? this._matchName : "default");
            //matchName = (matchName.Length < 11 ? matchName : matchName.Substring(0, 10) + "...");

            title.GetComponent <Text>().text = string.Format("Match: {0}", matchName);
        }

        for (int i = 2; i < this._lobbyPanel.transform.GetChild(0).childCount; i++)
        {
            this._lobbyPanel.transform.GetChild(0).GetChild(i).gameObject.SetActive(false);
            Destroy(this._lobbyPanel.transform.GetChild(0).GetChild(i).gameObject);
        }

        for (int i = 0; i < message.players.Length; i++)
        {
            GameObject listing = Instantiate(template);
            listing.transform.SetParent(template.transform.parent);
            listing.SetActive(true);

            rt           = listing.GetComponent <RectTransform>();
            rt.offsetMax = new Vector2(192, (i + 1) * -45 - 20);
            rt.offsetMin = new Vector2(0, (i + 2) * -45 - 20);

            listing.transform.GetChild(0).GetComponent <Text>().text = message.players[i].name;
            listing.transform.GetChild(1).GetComponent <Text>().text = (message.players[i].ready ? "Ready" : "Not ready");
            listing.transform.GetChild(2).GetComponent <Text>().text = new string[] { "Bunny", "Fox", "Bird", "Moose" }[message.players[i].animal];
        }
    }