123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using System.Collections;
- using System.Collections.Generic;
- using System.IO.Pipes;
- using System.Net;
- using UnityEngine;
-
- public class ClientHandle : MonoBehaviour
- {
- public static void Welcome(Packet _packet)
- {
- string _msg = _packet.ReadString();
- int _myId = _packet.ReadInt();
-
- Debug.Log($"Message from the server: {_msg}");
- Client.instance.myId = _myId;
- ClientSend.WelcomeReceived();
-
- Client.instance.udp.Connect(((IPEndPoint) Client.instance.tcp.socket.Client.LocalEndPoint).Port);
- }
-
- public static void SpawnPlayer(Packet _packet)
- {
- int _id = _packet.ReadInt();
- string _username = _packet.ReadString();
- Vector3 _position = _packet.ReadVector3();
- Quaternion _rotation = _packet.ReadQuaternion();
-
- GameManager.instance.SpawnPlayer(_id, _username, _position, _rotation);
- }
-
- public static void PlayerPosition(Packet _packet)
- {
- int _id = _packet.ReadInt();
- Vector3 _position = _packet.ReadVector3();
-
- GameManager.players[_id].transform.position = _position;
- }
-
- public static void PlayerRotation(Packet _packet)
- {
- int _id = _packet.ReadInt();
- Quaternion _rotation = _packet.ReadQuaternion();
-
- GameManager.players[_id].transform.rotation = _rotation;
- }
-
- public static void PlayerDisconnected(Packet _packet)
- {
- int _id = _packet.ReadInt();
-
- Destroy(GameManager.players[_id].gameObject);
- GameManager.players.Remove(_id);
- }
-
- public static void PlayerHealth(Packet _packet)
- {
- int _id = _packet.ReadInt();
- float _health = _packet.ReadFloat();
-
- GameManager.players[_id].SetHealth(_health);
- }
-
- public static void PlayerRespawned(Packet _packet)
- {
- int _id = _packet.ReadInt();
-
- GameManager.players[_id].Respawn();
- }
- }
|