Beispiel #1
0
        /// <summary>
        /// 网络回调
        /// </summary>
        /// <param name="obj_arr"></param>
        protected override void GetNetworkMsgCallBack(params object[] obj_arr)
        {
            try
            {
                NetworkMessage message = (NetworkMessage)obj_arr[0];

                if (message.type == 4 && IP.Equals(message.ip))
                {
                    TransformMessage tr = TransformMessage.GetMessage(message.message);
                    //同步位置
                    player.SetTarget(tr);
                }
                else if (message.type == 5 && message.ip == IP)
                {
                    AddMessage(message);
                }
                else if (message.type == 6 && message.ip == IP)
                {
                    AddMessage(message);
                }
                else if (message.type == 18 && message.ip == IP)
                {
                    AddMessage(message);
                }
            }
            catch (System.Exception e)
            {
                Debug.LogError(e.ToString());
            }
        }
Beispiel #2
0
 public static byte[] GetBytes(TransformMessage t)
 {
     byte[] bx    = BitConverter.GetBytes(t.x);
     byte[] by    = BitConverter.GetBytes(t.y);
     byte[] bz    = BitConverter.GetBytes(t.z);
     byte[] ba    = BitConverter.GetBytes(t.angle);
     byte[] bg    = BitConverter.GetBytes(t.gunAngle);
     byte[] bytes = new byte[bx.Length + by.Length +
                             bz.Length + ba.Length + bg.Length];
     bx.CopyTo(bytes, 0);
     by.CopyTo(bytes, 4);
     bz.CopyTo(bytes, 8);
     ba.CopyTo(bytes, 12);
     bg.CopyTo(bytes, 16);
     return(bytes);
 }
Beispiel #3
0
 /// <summary>
 /// 同步位置方法
 /// </summary>
 /// <param name="trans"></param>
 public void SendTranfromToServer(Transform trans, float gunAngle)
 {
     try
     {
         NetworkMessage message = new NetworkMessage(4, NetworkTools.GetLocalIP(),
                                                     TransformMessage.GetBytes(new TransformMessage(
                                                                                   trans.position, trans.rotation.eulerAngles, gunAngle)));
         byte[] bytes = NetworkMessage.GetBytes(message);
         //Debug.Log("发送位置数据");
         //测试
         SendMsg(RoomSingle.roomIP, NetworkConstent.UDPServerPort, bytes);
     }
     catch (Exception e)
     {
         Debug.LogError(e.ToString());
     }
 }