コード例 #1
0
 public override void OnResponse(ProtocalData msg)
 {
     if (PlayerLogOutEvent != null)
     {
         PlayerLogOutEvent(this, msg);
     }
 }
コード例 #2
0
 private void ActionCallback(ProtocalData data)
 {
     if (ReceiveEvent != null)
     {
         ReceiveEvent(this, data);
     }
 }
コード例 #3
0
 public void Send(ProtocalData msg)
 {
     if (SendEvent != null)
     {
         SendEvent(this, msg);
     }
 }
コード例 #4
0
 internal void Send(ProtocalData e)
 {
     if (clientScoket != null && clientScoket.Connected)
     {
         clientScoket.Send(Message.EncodeMessage(e));
     }
 }
コード例 #5
0
    public void SendHealth(float health)
    {
        PlayInfoData playInfo = new PlayInfoData(user.UserId, user.UserName, localTransform, false, (int)health, 15f);
        ProtocalData data     = new ProtocalData(ActionCode.MsgPlayInfoData, playInfo);

        Send(data);
    }
コード例 #6
0
 public override void OnResponse(ProtocalData msg)
 {
     base.OnResponse(msg);
     if (ExitRoomEvent != null)
     {
         ExitRoomEvent(this, msg);
     }
 }
コード例 #7
0
 public override void OnResponse(ProtocalData msg)
 {
     base.OnResponse(msg);
     if (InitPlayerListEvent != null)
     {
         InitPlayerListEvent(this, msg);
     }
 }
コード例 #8
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);
    }
コード例 #9
0
    public void SendFire(float force)
    {
        Complete.TankHealth th = this.player.GetComponent <Complete.TankHealth>();
        var          health    = th.GetCurrentHealth();
        PlayInfoData playInfo  = new PlayInfoData(user.UserId, user.UserName, localTransform, true, (int)health, force);
        ProtocalData data      = new ProtocalData(ActionCode.MsgPlayInfoData, playInfo);

        Send(data);
    }
コード例 #10
0
    private void SendLocalPlayer()
    {
        Complete.TankHealth th = this.player.GetComponent <Complete.TankHealth>();
        var          health    = th.GetCurrentHealth();
        PlayInfoData playInfo  = new PlayInfoData(user.UserId, user.UserName, player.transform, false, (int)health, 15f);
        ProtocalData data      = new ProtocalData(ActionCode.MsgPlayInfoData, playInfo);

        Send(data);
    }
コード例 #11
0
    public override void OnResponse(ProtocalData msg)
    {
        base.OnResponse(msg);
        RoomData room = ProtoBufSerializable.Decode <RoomData>(msg.Bytes);

        if (CreateRoomCallback != null)
        {
            CreateRoomCallback(room);
        }
    }
コード例 #12
0
 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);
     }
 }
コード例 #13
0
    public override void OnResponse(ProtocalData msg)
    {
        base.OnResponse(msg);
        UserLoginData data = ProtoBufSerializable.Decode <UserLoginData>(msg.Bytes);

        if (LoggedEvent != null)
        {
            LoggedEvent(this, msg);
        }
    }
コード例 #14
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);
        }
    }
コード例 #15
0
    /// <summary>
    /// 消息处理
    /// </summary>
    /// <param name="msg">消息</param>
    public void MessageHandler(ProtocalData msg)
    {
        if (msg == null)
        {
            return;
        }
        ActionCode  code = msg.GetName().ToEnum <ActionCode>();
        BaseHandler baseHandler;

        if (msgDict.TryGetValue(code, out baseHandler))
        {
            baseHandler.OnResponse(msg);
        }
        else
        {
            Debug.LogWarning("没有对应的处理类: " + msg.GetName());
        }
    }
コード例 #16
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;
         }
     }
 }
コード例 #17
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);
        }
    }
コード例 #18
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);
        }
    }
コード例 #19
0
 /// <summary>
 /// 接收消息事件处理方法
 /// </summary>
 /// <param name="sender">触发事件对象</param>
 /// <param name="e">参数</param>
 private void ReceiveEvent(object sender, ProtocalData e)
 {
     msgManager.Add(e);
 }
コード例 #20
0
 private void SendMessage(object sender, ProtocalData e)
 {
     clientManager.Send(e);
 }
コード例 #21
0
 public void Add(ProtocalData msg)
 {
     MessageList.Add(msg);
 }
コード例 #22
0
 public void JoinRoom(string roomId)
 {
     ProtocalData data = new ProtocalData(actionCode, new RoomData() { Id = roomId });
     Send(data);
 }
コード例 #23
0
 public virtual void Send(ProtocalData msg)
 {
     MessageManager.Send(msg);
 }
コード例 #24
0
 public virtual void OnResponse(ProtocalData msg)
 {
 }
コード例 #25
0
 /// <summary>
 /// 编码消息
 /// </summary>
 /// <param name="data">消息对象</param>
 /// <returns>序列化结果</returns>
 public static byte[] EncodeMessage(ProtocalData data)
 {
     byte[] body = data.Encode();
     byte[] head = NettyBitConverter.ToBytes(body.Length);
     return(head.Concat(body).ToArray());
 }
コード例 #26
0
    private void JoinRoomHandler_JoinRoomEvent(object sender, ProtocalData msg)
    {
        RoomData room = ProtoBufSerializable.Decode <RoomData>(msg.Bytes);

        RefreshPlayerItem(room);
    }
コード例 #27
0
 public override void OnResponse(ProtocalData msg)
 {
     base.OnResponse(msg);
 }