Exemple #1
0
 /// <summary>
 /// 同步状态的方法
 /// </summary>
 /// <param name="state"></param>
 public void SendPlayerHurtToServer(float hurt)
 {
     try
     {
         NetworkMessage message = new NetworkMessage(6, NetworkTools.GetLocalIP(),
                                                     PlayerHurtMessage.GetBytes(new PlayerHurtMessage(hurt)));
         byte[] bytes = NetworkMessage.GetBytes(message);
         SendMsg(RoomSingle.roomIP, NetworkConstent.UDPServerPort, bytes);
     }
     catch (Exception e)
     {
         Debug.LogError(e.ToString());
     }
 }
Exemple #2
0
 protected override void NetworkCallback(NetworkMessage message)
 {
     if (message.type == 5 && message.ip == IP)
     {
         PlayerStateMessage m = PlayerStateMessage.GetMessage(message.message);
         player.SetState(m.state, m.atkState);
     }
     else if (message.type == 6 && message.ip == IP)
     {
         PlayerHurtMessage m = PlayerHurtMessage.GetMessage(message.message);
         player.ReduceHP(m.hurt);
     }
     else if (message.type == 18 && message.ip == IP)
     {
         player.Shoot();
     }
 }
Exemple #3
0
 public static byte[] GetBytes(PlayerHurtMessage message)
 {
     byte[] newBytes = BitConverter.GetBytes(message.hurt);
     return(newBytes);
 }