Пример #1
0
    /// <summary>
    /// 玩家登录后触发事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void LoggedEvent(object sender, ProtocalData e)
    {
        playerInitHandler = syncPlayerInfo.AddComponent <PlayerInitHandler>();
        playerInitHandler.InitPlayerListEvent += InitPlayerListEvent;
        playerInitHandler.Send(new ProtocalData(ActionCode.MsgInitPlay, new PlayInfoData()));

        LocalPlayer = ProtoBufSerializable.Decode <UserLoginData>(e.Bytes);
    }
Пример #2
0
    public override void OnResponse(ProtocalData msg)
    {
        base.OnResponse(msg);
        RoomData room = ProtoBufSerializable.Decode <RoomData>(msg.Bytes);

        if (CreateRoomCallback != null)
        {
            CreateRoomCallback(room);
        }
    }
 public override void OnResponse(ProtocalData msg)
 {
     base.OnResponse(msg);
     if (RoomListCallback != null)
     {
         List <RoomData> rooms = ProtoBufSerializable.Decode <List <RoomData> >(msg.Bytes);
         RoomListCallback(rooms);
         OnRoomListEvent(rooms);
     }
 }
    public override void OnResponse(ProtocalData msg)
    {
        base.OnResponse(msg);
        UserLoginData data = ProtoBufSerializable.Decode <UserLoginData>(msg.Bytes);

        if (LoggedEvent != null)
        {
            LoggedEvent(this, msg);
        }
    }
Пример #5
0
    /// <summary>
    /// 玩家退出事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void PlayerLogOutEvent(object sender, ProtocalData e)
    {
        PlayInfoData playInfo = ProtoBufSerializable.Decode <PlayInfoData>(e.Bytes);
        GameObject   tank;

        if (PlayerList.TryGetValue(playInfo.UserId, out tank))
        {
            RemovePlayer(playInfo.UserId);
            gameManager.RemoveTank(playInfo.UserId);
            gameManager.m_PlayerList.RemoveItem(tank.name);
            UnityEngine.Object.DestroyObject(tank);
        }
    }
Пример #6
0
 /// <summary>
 /// 解码并执行命令回调
 /// </summary>
 /// <param name="dataLenght">数据流长度</param>
 /// <param name="actionCallback">回调函数</param>
 public void DecodeMessage(int dataLenght, Action <ProtocalData> actionCallback)
 {
     startIndex += dataLenght;
     while (true)
     {
         if (startIndex <= headLength)
         {
             return;
         }
         int bodyLength = NettyBitConverter.ToInt(data);
         if ((startIndex - headLength) >= bodyLength)
         {
             ProtocalData data = ProtoBufSerializable.Decode <ProtocalData>(Data, headLength, bodyLength);
             actionCallback(data);
             Array.Copy(Data, headLength + bodyLength, Data, 0, startIndex - headLength - bodyLength);
             startIndex -= (headLength + bodyLength);
         }
         else
         {
             break;
         }
     }
 }
Пример #7
0
    public override void OnResponse(ProtocalData msg)
    {
        PlayInfoData playInfo = ProtoBufSerializable.Decode <PlayInfoData>(msg.Bytes);

        if (PlayerManager.Instance.LocalPlayer.UserId == playInfo.UserId)
        {
            return;
        }
        GameObject tank;

        if (PlayerManager.Instance.PlayerList.TryGetValue(playInfo.UserId, out tank))
        {
            tank.GetComponent <Complete.TankMovement>().RemoteTransform(playInfo.GetPosition(), playInfo.GetRotation());
            if (playInfo.Shoot)
            {
                tank.GetComponent <Complete.TankShooting>().Fire(playInfo.Force);
            }
            tank.GetComponent <Complete.TankHealth>().SyncHealth(playInfo.ServerHealth);
        }
        else
        {
            PlayerManager.Instance.AddPlayer(playInfo);
        }
    }
Пример #8
0
    /// <summary>
    /// 初始化玩家列表事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void InitPlayerListEvent(object sender, ProtocalData e)
    {
        tankBehavior = syncPlayerInfo.AddComponent <TankBehaviorHanlder>();
        List <PlayInfoData> datas = ProtoBufSerializable.Decode <List <PlayInfoData> >(e.Bytes);

        for (int i = 0; i < datas.Count; i++)
        {
            GameObject tank;
            var        item  = datas[i];
            Color      color = tankColors[item.PlayerNumber];
            if (item.UserId == LocalPlayer.UserId)
            {
                tank = gameManager.AddTank(item.PlayerNumber, color, LocalPlayer.UserName, LocalPlayer.UserId, true);
                tankBehavior.SetLocalPlayer(tank, tank.transform);
            }
            else
            {
                tank = gameManager.AddTank(item.PlayerNumber, color, item.PlayName, item.UserId, item.GetPosition(), item.GetRotation());
            }

            PlayerList.Add(item.UserId, tank);
            gameManager.m_PlayerList.AddItem(tank.name, color);
        }
    }
Пример #9
0
    private void JoinRoomHandler_JoinRoomEvent(object sender, ProtocalData msg)
    {
        RoomData room = ProtoBufSerializable.Decode <RoomData>(msg.Bytes);

        RefreshPlayerItem(room);
    }
Пример #10
0
 public ProtocalData(string protocolName, string protocolDesc, object @object)
 {
     ProtocolName = protocolName;
     ProtocolDesc = protocolDesc;
     Bytes        = ProtoBufSerializable.Encode(@object);
 }
Пример #11
0
 public virtual byte[] Encode()
 {
     return(ProtoBufSerializable.Encode(this));
 }