/// <summary> /// 同步状态的方法 /// </summary> /// <param name="state"></param> public void SendPlayerHurtToServer(float hurt) { try { NetworkMessage message = new NetworkMessage(6, NetworkTools.GetLocalIP(), PlayerHurtMessage.GetBytes(new PlayerHurtMessage(hurt))); byte[] bytes = NetworkMessage.GetBytes(message); SendMsg(RoomSingle.roomIP, NetworkConstent.UDPServerPort, bytes); } catch (Exception e) { Debug.LogError(e.ToString()); } }
protected override void NetworkCallback(NetworkMessage message) { if (message.type == 5 && message.ip == IP) { PlayerStateMessage m = PlayerStateMessage.GetMessage(message.message); player.SetState(m.state, m.atkState); } else if (message.type == 6 && message.ip == IP) { PlayerHurtMessage m = PlayerHurtMessage.GetMessage(message.message); player.ReduceHP(m.hurt); } else if (message.type == 18 && message.ip == IP) { player.Shoot(); } }
public static byte[] GetBytes(PlayerHurtMessage message) { byte[] newBytes = BitConverter.GetBytes(message.hurt); return(newBytes); }