Beispiel #1
0
 public static byte[] GetBytes(BulletMessage t)
 {
     byte[] bx    = BitConverter.GetBytes(t.x);
     byte[] by    = BitConverter.GetBytes(t.y);
     byte[] bz    = BitConverter.GetBytes(t.z);
     byte[] bax   = BitConverter.GetBytes(t.angleX);
     byte[] bay   = BitConverter.GetBytes(t.angleY);
     byte[] baz   = BitConverter.GetBytes(t.angleZ);
     byte[] btype = BitConverter.GetBytes(t.bulletType);
     byte[] bnum  = BitConverter.GetBytes(t.num);
     byte[] bytes = new byte[bx.Length + by.Length +
                             bz.Length + bax.Length + bay.Length + baz.Length + btype.Length + bnum.Length];
     bx.CopyTo(bytes, 0);
     by.CopyTo(bytes, 4);
     bz.CopyTo(bytes, 8);
     bax.CopyTo(bytes, 12);
     bay.CopyTo(bytes, 16);
     baz.CopyTo(bytes, 20);
     btype.CopyTo(bytes, 24);
     bnum.CopyTo(bytes, 28);
     return(bytes);
 }
Beispiel #2
0
        protected override void GetNetworkMsgCallBack(params object[] obj_arr)
        {
            NetworkMessage message = (NetworkMessage)obj_arr[0];

            if (message.type == 50 && !message.ip.Equals(NetworkTools.GetLocalIP()))//位置同步
            {
                BulletMessage bullet = BulletMessage.GetMessage(message.message);
                if ((bullet.bulletType == (int)BulletType.boosMissile || bullet.bulletType == (int)BulletType.bossBullet) && NetworkTools.GetLocalIP().Equals(RoomSingle.roomIP))
                {
                    return;
                }
                if (bullets.ContainsKey(message.ip + bullet.num) && bullet.bulletType != (int)BulletType.bossBullet)//有这颗子弹
                {
                    if (bullet.bulletType == (int)BulletType.bossBullet)
                    {
                        return;
                    }
                    bullets[message.ip + bullet.num].SetTarget(bullet);
                }
                else//没有这个子弹, 根据子弹的类型生成子弹
                {
                    AddMessage(message);
                }
            }
            else if (message.type == 51 && !message.ip.Equals(NetworkTools.GetLocalIP()))//位置同步
            {
                BulletMessage bullet = BulletMessage.GetMessage(message.message);
                if (bullet.bulletType == (int)BulletType.bossBullet)
                {
                    return;
                }
                if (bullets.ContainsKey(message.ip + bullet.num))//有这颗子弹
                {
                    //爆炸
                    AddMessage(message);
                }
            }
        }
Beispiel #3
0
 protected override void NetworkCallback(NetworkMessage message)
 {
     if (message.type == 50 && !message.ip.Equals(NetworkTools.GetLocalIP()))//位置同步
     {
         BulletMessage bullet = BulletMessage.GetMessage(message.message);
         if ((bullet.bulletType == (int)BulletType.boosMissile || bullet.bulletType == (int)BulletType.bossBullet) && NetworkTools.GetLocalIP().Equals(RoomSingle.roomIP))
         {
             return;
         }
         if (!bullets.ContainsKey(message.ip + bullet.num))//有这颗子弹
         {
             GameObject prefab = Resources.Load <GameObject>("Prefab/Bullet/Net_" + ((BulletType)bullet.bulletType).ToString());
             GameObject obj    = Instantiate <GameObject>(prefab,
                                                          new Vector3(bullet.x, bullet.y, bullet.z),
                                                          Quaternion.Euler(bullet.angleX, bullet.angleY, bullet.angleZ));
             obj.GetComponent <NetworkBullet>().SetTarget(bullet);
             if (bullet.bulletType != (int)BulletType.bossBullet)
             {
                 bullets.Add(message.ip + bullet.num, obj.GetComponent <NetworkBullet>());
             }
         }
     }
     else if (message.type == 51 && !message.ip.Equals(NetworkTools.GetLocalIP()))//包扎同步
     {
         BulletMessage bullet = BulletMessage.GetMessage(message.message);
         if (bullet.bulletType == (int)BulletType.bossBullet)
         {
             return;
         }
         if (bullets.ContainsKey(message.ip + bullet.num))//有这颗子弹
         {
             bullets[message.ip + bullet.num].Explosion();
             bullets.Remove(message.ip + bullet.num);
         }
     }
 }
Beispiel #4
0
 /// <summary>
 /// 子弹爆炸
 /// </summary>
 /// <param name="p"></param>
 /// <param name="r"></param>
 /// <param name="type"></param>
 /// <param name="num"></param>
 public void SendExplosion(Vector3 p, Vector3 r, int type, int num)
 {
     byte[] b = BulletMessage.GetBytes(new BulletMessage(p, r, type, num));
     byte[] m = NetworkMessage.GetBytes(new NetworkMessage(51, NetworkTools.GetLocalIP(), b));
     SendMsg(RoomSingle.roomIP, NetworkConstent.UDPServerPort, m);
 }