예제 #1
0
 public static byte[] GetBytes(PlayerStateMessage p)
 {
     byte[] newBytes = new byte[8];
     BitConverter.GetBytes((int)p.state).CopyTo(newBytes, 0);
     BitConverter.GetBytes((int)p.atkState).CopyTo(newBytes, 4);
     return(newBytes);
 }
예제 #2
0
 /// <summary>
 /// 同步状态的方法
 /// </summary>
 /// <param name="state"></param>
 public void SendPlayerStateToServer(PlayerState playerState, AtkState atkState)
 {
     try
     {
         NetworkMessage message = new NetworkMessage(5, NetworkTools.GetLocalIP(),
                                                     PlayerStateMessage.GetBytes(new PlayerStateMessage(playerState,
                                                                                                        atkState)));
         byte[] bytes = NetworkMessage.GetBytes(message);
         //Debug.Log("发送位置数据");
         //测试
         SendMsg(RoomSingle.roomIP, NetworkConstent.UDPServerPort, bytes);
     }
     catch (Exception e)
     {
         Debug.LogError(e.ToString());
     }
 }
예제 #3
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();
     }
 }