コード例 #1
0
    /// <summary>
    /// Called when we need to read the players info from the server.
    /// </summary>
    private void ProcessPlayersInfo()
    {
        int playersCount             = m_Buffer.ReadInt();
        List <NetPlayer> playersInfo = new List <NetPlayer>(playersCount);

        for (int i = 0; i < playersCount; ++i)
        {
            playersInfo.Add(new NetPlayer(m_Buffer.ReadString(), m_Buffer.ReadInt()));
        }

        NetPlayersSystem.Instance().ReceiveNetPlayersList(playersInfo);
    }
コード例 #2
0
    public override void Update()
    {
        base.Update();

        List <NetPlayer> NetPlayers = NetPlayersSystem.Instance().GetAllPlayers();

        // Look for players which have been lost.
        for (int i = NetPlayers.Count - 1; i >= 0; --i)
        {
            int  currentPlayerID = NetPlayers[i].PlayerID;
            bool bRemove         = true;
            for (int j = 0; j < m_NewPlayers.Count; ++j)
            {
                if (m_NewPlayers[j].PlayerID == currentPlayerID)
                {
                    bRemove = false;
                    break;
                }
            }

            if (bRemove)
            {
                NetPlayers.RemoveAt(i);
            }
        }


        // See if there are any new players here.
        for (int j = 0; j < m_NewPlayers.Count; ++j)
        {
            bool bAdd            = true;
            int  currentPlayerID = m_NewPlayers[j].PlayerID;
            for (int i = 0; i < NetPlayers.Count; ++i)
            {
                if (NetPlayers[i].PlayerID == currentPlayerID)
                {
                    // Not new don't add.
                    bAdd = false;
                    break;
                }
            }

            if (bAdd)
            {
                NetPlayersSystem.Instance().AddPlayer(NetPlayers[j]);
            }
        }

        // Can't really fail this task.
        SetComplete(true);
    }