示例#1
0
    private void Update()
    {
        IServerPacket packet = null;

        lock (mutex)
        {
            if (serverPackets.Count > 0)
            {
                packet = serverPackets.Dequeue();
            }
        }
        if (packet != null)
        {
            switch (packet.Id)
            {
            case PacketType.LobbyInfo:
                loginUI.OnLobbyInfo(packet as LobbyInfoPacket);
                break;

            case PacketType.StartGame:
                loginUI.OnStartGame(packet as StartGamePacket);
                break;

            case PacketType.LoadGame:
                var myId = (packet as LoadGamePacket).ClientId;
                var ack  = new LoadGameAckPacket();
                ack.ClientId = myId;
                client.Send(ack);
                loginUI.OnLoadGame();
                playerManager.OnLoadGame(packet as LoadGamePacket);
                break;

            case PacketType.Tick:
                playerManager.OnTick(packet as TickPacket);
                break;

            case PacketType.Death:
                playerManager.OnDeath(packet as DeathPacket);
                break;

            case PacketType.EndGame:
                loginUI.OnEndGame(packet as EndGamePacket);
                playerManager.OnEndGame(packet as EndGamePacket);
                break;

            default:
                Debug.Log(string.Format("Type: {0}, str: {1}", packet.Id, packet.ToString()));
                break;
            }
        }
    }