/// <summary> /// 向玩家发送单个玩家更新状态 /// </summary> /// <param name="ip"></param> /// <param name="info"></param> public void SendUpdatePlayrInfo(string ip, RoomPlayerInfoMessage info) { byte[] bytes = RoomPlayerInfoMessage.GetBytes(info); NetworkMessage sendM = new NetworkMessage(10, NetworkTools.GetLocalIP(), bytes); SendMsg(ip, NetworkConstent.UDPClientPort, NetworkMessage.GetBytes(sendM)); }
/// <summary> /// 向玩家发送房间内所有玩家信息 /// </summary> /// <param name="ip"></param> public void SendPlayerInfosToClient(string ip) { foreach (var item in playerData.GetPlayersInfo().Keys) { byte[] bytes = RoomPlayerInfoMessage.GetBytes(playerData.GetPlayersInfo()[item]); NetworkMessage sendM = new NetworkMessage(15, NetworkTools.GetLocalIP(), bytes); SendMsg(ip, NetworkConstent.UDPClientPort, NetworkMessage.GetBytes(sendM)); } }
/// <summary> /// 想要加入的房间 /// </summary> /// <param name="ip"></param> public void SendAddRoom(string ip) { try { IPAddress.Parse(ip); Debug.Log("请求加入: " + ip); } catch (System.Exception) { Debug.LogError("请输入有效IP"); return; } byte[] info = RoomPlayerInfoMessage.GetBytes(new RoomPlayerInfoMessage("", false, NetworkTools.GetLocalIP())); SendMsg(ip, NetworkConstent.UDPServerPort, NetworkMessage.GetBytes(new NetworkMessage(7, NetworkTools.GetLocalIP(), info))); }