Beispiel #1
0
 protected override void NetworkCallback(object message)
 {
     if (message.GetType().ToString().Equals("Network.NetworkMessage"))
     {
         Debug.Log("客户端接收");
         NetworkMessage nm = (NetworkMessage)message;
         if (nm.type == 13)
         {
             PlayerInfoMessage info = PlayerInfoMessage.GetMessage(nm.message);
             RoomSingle.AddPlayer(info);
             //Debug.Log("开始游戏");
             UIManager._Instance.CloseWindow(WindowName.WaitStartRoom);
             LoadSceneManager._Instance.LoadScene(SceneName.Mission1, StartGameCallBack);
             //NetworkManager._Instance.RemoveCallBack(13, GetNetworkMsgCallBack);
         }
         else if (nm.type == 10)
         {
             RoomPlayerInfoMessage info = RoomPlayerInfoMessage.GetMessage(nm.message);
             playerData.SetPlayerCanStart(info.playerIP, info.canStart);
             wait.UpdatePanel(playerData);
         }
         else if (nm.type == 15)
         {
             RoomPlayerInfoMessage info = RoomPlayerInfoMessage.GetMessage(nm.message);
             playerData.AddPlayerInfo(info.playerIP, info);
             wait.UpdatePanel(playerData);
         }
         else if (nm.type == 16)
         {
             RoomPlayerInfoMessage info = RoomPlayerInfoMessage.GetMessage(nm.message);
             playerData.RemovePlayerInfo(info.playerIP);
             RoomSingle.RemovePlayer(info.playerIP);
             wait.UpdatePanel(playerData);
         }
         else if (nm.type == 17)
         {
             PlayerInfoMessage info = PlayerInfoMessage.GetMessage(nm.message);
             RoomSingle.AddPlayer(info);
             playerData.SetPlayerCanStart(info.playerIP, true);
             wait.UpdatePanel(playerData);
         }
     }
 }
Beispiel #2
0
 /// <summary>
 /// 向客户端发送可以加入信息
 /// </summary>
 /// <param name="obj_arr"></param>
 void AddRoomMsgCallBack(params object[] obj_arr)
 {
     //房间最多4个人
     if (playerData.GetPlayersInfo().Count < 4)
     {
         NetworkMessage        m    = (NetworkMessage)obj_arr[0];
         RoomPlayerInfoMessage info = RoomPlayerInfoMessage.GetMessage(m.message);
         playerData.AddPlayerInfo(m.ip, info);
         NetworkManager._Instance.AddMessage(102, playerData);
         Debug.Log("房间加入玩家" + m.ip + " --- " + playerData.GetPlayersInfo().Count);
         byte[] bytes = NetworkMessage.GetBytes(new NetworkMessage(8, NetworkTools.GetLocalIP(), new byte[0]));
         SendMsg(m.ip, NetworkConstent.UDPClientPort, bytes);
         //向所有玩家发送加入信息
         foreach (var item in playerData.GetPlayersInfo().Keys)
         {
             if (!item.Equals(NetworkTools.GetLocalIP()))
             {
                 SendPlayerInfosToClient(item);
             }
         }
     }
 }