示例#1
0
 /// <summary>
 /// 发送
 /// </summary>
 void SocketSend()
 {
     //清空发送缓存
     sendData = new byte[1024];
     //数据类型转换
     dpsend.set(transform);
     dpsend.HP = MPlayerInfo.getins().hp;
     sendData  = ConvertHelper.StructureToByte(dpsend);
     //发送给指定服务端
     sock.SendTo(sendData, clientEnd);
 }
示例#2
0
 /// <summary>
 /// 接收
 /// </summary>
 void SocketReceive()
 {
     //进入接收循环
     while (true)
     {
         //对data清零
         recvData = new byte[1024];
         //获取客户端,获取客户端数据,用引用给客户端赋值
         recvLen = socket.ReceiveFrom(recvData, ref ep);
         //接收到一个包
         dpget = ((DgramPlayer)ConvertHelper.ByteToStructure(recvData));
         if (dpget.IP == MyIP)
         {
             continue;
         }
         else if (PlayerList.ContainsKey(dpget.IP))
         {
             //伤害数据包
             if (dpget.damage != 0 && MyIP == dpget.damageIP)
             {
                 MPlayerInfo.getins().damage(dpget.damage);
             }
             else
             {
                 //解析
                 OtherPlayer temp = PlayerList[dpget.IP];
                 GameObject  p    = temp.gobj;
                 temp.pos   = dpget.getpos();
                 temp.rot   = dpget.getrot();
                 temp.speed = dpget.speed;
                 //hp
                 temp.UpdateHp(dpget.HP);
                 //gun
                 temp.GunManage(dpget.getgunrot(), dpget.shooting);
             }
         }
         else
         {
             //加入
             //由于主线程才能使用unity的api,把添加用户的逻辑交给update;
             lock (currentjoin)
             {
                 currentjoin.join = true;
                 currentjoin.IP   = dpget.IP;
             }
         }
     }
 }
示例#3
0
 public MPlayerInfo()
 {
     ins = this;
     //bloodpercent = new OneArg<float>(1f);
 }
示例#4
0
 // Use this for initialization
 void Start()
 {
     Info = MPlayerInfo.getins();
     MPlayerInfo.getins().Revive += revive;
 }