Test de communication de paquets entre un client et un serveur
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class ClientSend : MonoBehaviour
  5. {
  6. private static void SendTCPData(Packet _packet)
  7. {
  8. _packet.WriteLength();
  9. Client.instance.tcp.SendData(_packet);
  10. }
  11. private static void SendUDPData(Packet _packet)
  12. {
  13. _packet.WriteLength();
  14. Client.instance.udp.SendData(_packet);
  15. }
  16. #region packets
  17. public static void WelcomeReceived()
  18. {
  19. using (Packet _packet = new Packet((int)ClientPackets.welcomeReceived))
  20. {
  21. _packet.Write(Client.instance.myId);
  22. _packet.Write(UIManager.instance.usernameField.text);
  23. SendTCPData(_packet);
  24. }
  25. }
  26. public static void PlayerMovement(bool[] _inputs)
  27. {
  28. using (Packet _packet = new Packet((int)ClientPackets.playerMovement))
  29. {
  30. _packet.Write(_inputs.Length);
  31. foreach (bool _input in _inputs)
  32. {
  33. _packet.Write(_input);
  34. }
  35. _packet.Write(GameManager.players[Client.instance.myId].transform.rotation);
  36. SendUDPData(_packet);
  37. }
  38. }
  39. public static void PlayerShoot(Vector3 _facing)
  40. {
  41. using (Packet _packet = new Packet((int)ClientPackets.playerShoot))
  42. {
  43. _packet.Write(_facing);
  44. SendTCPData(_packet);
  45. }
  46. }
  47. #endregion
  48. }