Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.89 KB | None | 0 0
  1. private void NetworkTask(object obj)
  2.     {
  3.         while (true)
  4.         {
  5.             try
  6.             {
  7.                 Debug.LogError("Да");
  8.                 string line = reader.ReadLine();
  9.                 if (line != null)
  10.                 {
  11.                     string[] command = line.Split(':');
  12.                     string cmd = command[0].ToUpperInvariant();
  13.                     switch (cmd)
  14.                     {
  15.                         case "GOTOME":
  16.                             onServer = true;
  17.                             id = command[1];
  18.                             break;
  19.                         case "NEWPLAYERSPAWN":
  20.                             ClientConnection newPlayer = new ClientConnection
  21.                             {
  22.                                 id = int.Parse(command[1]),
  23.                                 spawned = true
  24.                             };
  25.                             clientList.Add(newPlayer);
  26.                             break;
  27.                         case "EXISTSPLAYER":
  28.                             ClientConnection existsPlayer = new ClientConnection
  29.                             {
  30.                                 id = int.Parse(command[1]),
  31.                                 spawned = true
  32.                             };
  33.                             clientList.Add(existsPlayer);
  34.                             break;
  35.                         case "POS":
  36.                             ClientConnection cl = clientList.Find(c => c.id == int.Parse(command[1]));
  37.                             cl.position = new Vector3(float.Parse(command[2]), float.Parse(command[3]), float.Parse(command[4]));
  38.                             break;
  39.                         case "ROT":
  40.                             ClientConnection clRot = clientList.Find(c => c.id == int.Parse(command[1]));
  41.                             clRot.rotation = new Quaternion(float.Parse(command[2]), float.Parse(command[3]), float.Parse(command[4]), 0f);
  42.                             break;
  43.                         default:
  44.                             Debug.LogErrorFormat("Client Get Wrong Command: {0}", cmd);
  45.                             break;
  46.                     }
  47.                 }
  48.                 if (client.Connected && myVehicle != null)
  49.                 {
  50.                     string posLine = string.Format("MYPOS:{0}:{1}:{2}:{3}", id, myPosition.x, myPosition.y, myPosition.z);
  51.                     string rotLine = string.Format("MYROT:{0}:{1}:{2}:{3}", id, myRotation.x, myRotation.y, myRotation.z);
  52.                     writer.WriteLine(posLine);
  53.                     writer.WriteLine(rotLine);
  54.                     Debug.LogFormat("My position: {0}", myPosition.ToString());
  55.                 }
  56.             }
  57.             catch (Exception e)
  58.             {
  59.                 Debug.LogErrorFormat("Client exception: {0}", e.ToString());
  60.             }
  61.         }
  62.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement