/// <summary>
        /// 发送Boss的位置信息
        /// </summary>
        /// <param name="t"></param>
        /// <param name="id"></param>
        /// <param name="listNum"></param>
        public void SendBossTransformMsg(Transform t, int id)
        {
            byte[] by = EnemyInfoMessage.GetBytes(
                new EnemyInfoMessage(t.position, t.rotation.eulerAngles, id, 0));
            NetworkMessage message = new NetworkMessage(70, NetworkTools.GetLocalIP(), by);

            byte[] bytes = NetworkMessage.GetBytes(message);
            SendMsg(RoomSingle.roomIP, NetworkConstent.UDPServerPort, bytes);
        }
 protected override void NetworkCallback(NetworkMessage message)
 {
     if (message.type == 60)
     {
         EnemyInfoMessage info = EnemyInfoMessage.GetMessage(message.message);
         string           key  = info.enemyType.ToString() + info.num.ToString();
         if (!enemyDic.ContainsKey(key))
         {
             GameObject prefab = Resources.Load <GameObject>("Prefab/Enemy/Enemy_AI_" + info.enemyType);
             GameObject obj    = Instantiate <GameObject>(prefab,
                                                          new Vector3(info.x, info.y, info.z), Quaternion.Euler(info.angleX, info.angleY, info.angleZ), transform);
             NetEnemyBase net = obj.GetComponent <NetEnemyBase>();
             net.SetIDandListNum(info.enemyType, info.num);
             net.SetTarget(info);
             enemyDic.Add(key, net);
         }
     }
     else if (message.type == 61)
     {
         //Debug.Log("同步小怪状态");
         EnemyStateMessage info = EnemyStateMessage.GetMessage(message.message);
         string            key  = info.enemyType.ToString() + info.num.ToString();
         if (enemyDic.ContainsKey(key))
         {
             enemyDic[key].SwitchEnemyState((EnemyState)info.state);
             if (info.state == (int)(EnemyState.Death))
             {
                 enemyDic.Remove(key);
             }
         }
     }
     else if (message.type == 62 && !NetworkTools.GetLocalIP().Equals(message.ip))
     {
         EnemyHurtMessge info = EnemyHurtMessge.GetMessage(message.message);
         string          key  = info.enemyType.ToString() + info.num.ToString();
         if (enemyDic.ContainsKey(key))
         {
             enemyDic[key].ReduceHP(info.hurt);
         }
     }
 }
Beispiel #3
0
 public static byte[] GetBytes(EnemyInfoMessage 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.enemyType);
     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);
 }
        protected override void GetNetworkMsgCallBack(params object[] obj_arr)
        {
            NetworkMessage message = (NetworkMessage)obj_arr[0];

            if (message.type == 60)//位置同步
            {
                //Debug.Log("同步小怪位置");
                EnemyInfoMessage info = EnemyInfoMessage.GetMessage(message.message);
                string           key  = info.enemyType.ToString() + info.num.ToString();
                if (enemyDic.ContainsKey(key))
                {
                    enemyDic[key].SetTarget(info);
                }
                else
                {
                    AddMessage(message);
                }
            }
            else if (message.type == 61 || message.type == 62)
            {
                AddMessage(message);
            }
        }