Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void NetworkTask(object obj)
- {
- while (true)
- {
- try
- {
- Debug.LogError("Да");
- string line = reader.ReadLine();
- if (line != null)
- {
- string[] command = line.Split(':');
- string cmd = command[0].ToUpperInvariant();
- switch (cmd)
- {
- case "GOTOME":
- onServer = true;
- id = command[1];
- break;
- case "NEWPLAYERSPAWN":
- ClientConnection newPlayer = new ClientConnection
- {
- id = int.Parse(command[1]),
- spawned = true
- };
- clientList.Add(newPlayer);
- break;
- case "EXISTSPLAYER":
- ClientConnection existsPlayer = new ClientConnection
- {
- id = int.Parse(command[1]),
- spawned = true
- };
- clientList.Add(existsPlayer);
- break;
- case "POS":
- ClientConnection cl = clientList.Find(c => c.id == int.Parse(command[1]));
- cl.position = new Vector3(float.Parse(command[2]), float.Parse(command[3]), float.Parse(command[4]));
- break;
- case "ROT":
- ClientConnection clRot = clientList.Find(c => c.id == int.Parse(command[1]));
- clRot.rotation = new Quaternion(float.Parse(command[2]), float.Parse(command[3]), float.Parse(command[4]), 0f);
- break;
- default:
- Debug.LogErrorFormat("Client Get Wrong Command: {0}", cmd);
- break;
- }
- }
- if (client.Connected && myVehicle != null)
- {
- string posLine = string.Format("MYPOS:{0}:{1}:{2}:{3}", id, myPosition.x, myPosition.y, myPosition.z);
- string rotLine = string.Format("MYROT:{0}:{1}:{2}:{3}", id, myRotation.x, myRotation.y, myRotation.z);
- writer.WriteLine(posLine);
- writer.WriteLine(rotLine);
- Debug.LogFormat("My position: {0}", myPosition.ToString());
- }
- }
- catch (Exception e)
- {
- Debug.LogErrorFormat("Client exception: {0}", e.ToString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement