Location.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using UnityEngine;
  7. public class Location
  8. {
  9. public uint id { get; set; }
  10. public string name { get; set; }
  11. public List<Wall> walls { get; set; }
  12. public List<Beacon> beacons { get; set; }
  13. public GameObject plane { get; set; }
  14. public string texture_url { get; set; }
  15. public List<Zone> zones { get; set; }
  16. public GameObject location { get; set; }
  17. public void Save()
  18. {
  19. foreach (Wall wall in walls)
  20. {
  21. wall.Save();
  22. }
  23. foreach (var z in zones)
  24. {
  25. z.Save();
  26. }
  27. Beacon.Save(beacons);
  28. }
  29. public void Load()
  30. {
  31. Debug.Log("Location.Load");
  32. Zone.LoadByLocationId(id);
  33. Wall.LoadByLocationId(id);
  34. Beacon.Request(id);
  35. //Client.instance.SendGetUsers();
  36. }
  37. public static void LocationsRequest()
  38. {
  39. Client.SendFourByteParamPacket(54, Client.instance.company_id);
  40. }
  41. public static void ReceiveFromServer(byte[] bytedata)
  42. {
  43. var player = PlayerController.instance;
  44. player.locations = new Dictionary<uint, Location>();
  45. player.locations_index = new List<uint>();
  46. int read = 5;
  47. while (read < bytedata.Length)
  48. {
  49. var id = BitConverter.ToUInt32(bytedata, read);
  50. var x = BitConverter.ToSingle(bytedata, read + 4);
  51. var y = BitConverter.ToSingle(bytedata, read + 8);
  52. var scalex = BitConverter.ToSingle(bytedata, read + 12);
  53. var scalez = BitConverter.ToSingle(bytedata, read + 16);
  54. var posx = BitConverter.ToSingle(bytedata, read + 20);
  55. var posz = BitConverter.ToSingle(bytedata, read + 24);
  56. var lenimg = BitConverter.ToUInt16(bytedata, read + 28);
  57. var img = Encoding.UTF8.GetString(bytedata, read + 30, lenimg);
  58. var lenname = BitConverter.ToUInt16(bytedata, read + 30 + lenimg);
  59. var name = Encoding.UTF8.GetString(bytedata, read + 32 + lenimg, lenname);
  60. read += (32 + lenimg + lenname);
  61. Debug.Log($"location received read {read} id {id} x {x} y {y} scalex {scalex} scalez {scalez} posx {posx} posz {posz} lenimg {lenimg} img {img} lenname {lenname} name {name}");
  62. GameObject plane = UnityEngine.Object.Instantiate(Resources.Load("GameObjects/Plane", typeof(GameObject))) as GameObject;
  63. plane.transform.position = new Vector3(posx, 0.01f, posz);
  64. plane.transform.localScale = new Vector3(scalex, WallCreate.WallHeight, scalez);
  65. var Location = new GameObject();
  66. Location.name = name;
  67. plane.transform.SetParent(Location.transform);
  68. player.locations[id] =new Location { id = id, name = name, texture_url = img, location = Location, plane = plane };
  69. player.locations_index.Add(id);
  70. Debug.Log("locations count "+ player.locations.Count);
  71. }
  72. player.load_location = true;
  73. }
  74. }