123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
-
- public class ClientSend : MonoBehaviour
- {
- private static void SendTCPData(Packet _packet)
- {
- _packet.WriteLength();
- Client.instance.tcp.SendData(_packet);
- }
-
- private static void SendUDPData(Packet _packet)
- {
- _packet.WriteLength();
- Client.instance.udp.SendData(_packet);
- }
-
- #region packets
- public static void WelcomeReceived()
- {
- using (Packet _packet = new Packet((int)ClientPackets.welcomeReceived))
- {
- _packet.Write(Client.instance.myId);
- _packet.Write(UIManager.instance.usernameField.text);
-
- SendTCPData(_packet);
- }
- }
-
- public static void PlayerMovement(bool[] _inputs)
- {
- using (Packet _packet = new Packet((int)ClientPackets.playerMovement))
- {
- _packet.Write(_inputs.Length);
- foreach (bool _input in _inputs)
- {
- _packet.Write(_input);
- }
- _packet.Write(GameManager.players[Client.instance.myId].transform.rotation);
- SendUDPData(_packet);
- }
- }
-
- public static void PlayerShoot(Vector3 _facing)
- {
- using (Packet _packet = new Packet((int)ClientPackets.playerShoot))
- {
- _packet.Write(_facing);
- SendTCPData(_packet);
- }
- }
- #endregion
- }
|