Browse Source

Загрузка маяков

Виктор Шейко 4 years ago
parent
commit
c8e5072bae

+ 5 - 1
Assets/Scripts/Controllers/AuthorizationController.cs

@@ -17,6 +17,7 @@ public class AuthorizationController : MonoBehaviour
     public static bool error = false;
     static string textError = "Неправильный логин или пароль";
 
+    Client client = new Client();
 
     // Start is called before the first frame update
     void Start()
@@ -27,8 +28,11 @@ public class AuthorizationController : MonoBehaviour
     // Update is called once per frame
     void Update()
     {
-        if (success) //SceneManager.LoadScene("Location");
+        if (success)
+        {//SceneManager.LoadScene("Location");
             transform.gameObject.SetActive(false);
+            client.SendGetUsers((uint)WorkerController.active_company + 1);
+        }
         if(error) Error.SetActive(true);
     }
 

+ 2 - 1
Assets/Scripts/Controllers/Editor2DController.cs

@@ -52,10 +52,11 @@ public class Editor2DController : MonoBehaviour
         SceneManager.LoadScene("Location");
     }
 
-  public void AddBeacon()
+    public void AddBeacon()
     {
         var beacon = Instantiate(Resources.Load("GameObjects/Beacon", typeof(GameObject))) as GameObject;
         var button = Instantiate(Resources.Load("GameObjects/ButtonUI", typeof(Button))) as Button;
+
         button.name = $"BeaconButton_{Beacons.Count}";
         button.transform.SetParent(BeaconsContent.transform);
         Beacons.Add(new Beacon { id = (uint)Beacons.Count, beacon = beacon, button = button });

+ 23 - 32
Assets/Scripts/Controllers/WorkerController.cs

@@ -12,6 +12,7 @@ public class WorkerController : MonoBehaviour
 {
     public static Dictionary<uint, List<Structure>> Workers = new Dictionary<uint, List<Structure>>();
     public static List<Structure> TestStructures = new List<Structure>();
+    public static List<Beacon> Beacons = new List<Beacon>();
 
     public GameObject WorkersList; // scroll content
     public Dropdown DropdownCompany;
@@ -37,8 +38,6 @@ public class WorkerController : MonoBehaviour
     public Camera camera;
     public Toggle projection;
 
-    InputField inputField_date_text;
-
     enum Mode { RealTime = 0, History = 1, Stop = 2 };
     Mode active_mode = Mode.Stop;
     int mode = 0;
@@ -59,6 +58,7 @@ public class WorkerController : MonoBehaviour
     float time_draw = 0;
     public static List<User> users = new List<User>();
     public static bool users_load = false;
+    public static bool beacons_load = false;
     uint location_id = 1;
 
     //List<bool> StartStop = new List<bool>();
@@ -67,28 +67,8 @@ public class WorkerController : MonoBehaviour
     void Start()
     {
         DebugHelper.ActivateConsole();
-        //WorkerMarker(4, Color.red);
-        //WorkerMarker(356, Color.green);
-
-        inputField_date_text = inputField_date.transform.GetComponent<InputField>();
-        //Year = DatePicker.transform.GetChild(0).GetComponent<Dropdown>();
-        //Month = DatePicker.transform.GetChild(1).GetComponent<Dropdown>();
-        //Day = DatePicker.transform.GetChild(2).GetComponent<Dropdown>();
 
         Date = DatePicker.GetComponent<DateTimePicker>();
-
-        //foreach (var s in structures.Select(s => s.acc_id).Distinct())
-        //    WorkerMarker(s, UnityEngine.Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f));
-
-        //foreach (var s in structures.Select(s => s.ts.Date).Distinct())
-        //{
-        //    dates.Add(s);
-        //    DropdownData.options.Add(new Dropdown.OptionData(s.ToString("dd.MM.yyyy")));
-        //}
-
-        //foreach (var s in structures.Select(s => s.location_id).Distinct())
-        //{
-        //    locations.Add(s);
         DropdownLocation.options.Add(new Dropdown.OptionData("1 Братск"));
         DropdownLocation.options.Add(new Dropdown.OptionData("22 Офис Ижевск"));
         DropdownLocation.options.Add(new Dropdown.OptionData("25"));
@@ -100,7 +80,7 @@ public class WorkerController : MonoBehaviour
     }
 
     int active_location = 0;
-    int active_company = 0;
+    public static int active_company = 0;
     // Update is called once per frame
     void Update()
     {
@@ -113,15 +93,11 @@ public class WorkerController : MonoBehaviour
             switch (DropdownMode.value)
             {
                 case 0:
-                    //history_start = false;
-                    //////inputField_date.gameObject.SetActive(false);
                     DatePicker.SetActive(false);
                     TimeStart.SetActive(false);
                     TimeEnd.SetActive(false);
                     break;
                 case 1:
-                    //real_time = false;
-                    //////inputField_date.gameObject.SetActive(true);
                     DatePicker.SetActive(true);
                     TimeStart.SetActive(true);
                     TimeEnd.SetActive(true);
@@ -150,18 +126,18 @@ public class WorkerController : MonoBehaviour
             switch (DropdownLocation.value)
             {
                 case 0:
-                    //inputField_location.text = "1";
                     location_id = 1;
                     break;
                 case 1:
-                    //inputField_location.text = "22";
                     location_id = 22;
                     break;
                 case 2:
-                    //inputField_location.text = "25";
                     location_id = 25;
                     break;
             }
+            
+            Beacons = new List<Beacon>();
+            client.BeaconsRequest((uint) active_location);
         }
 
         foreach (var m in markers)
@@ -234,9 +210,16 @@ public class WorkerController : MonoBehaviour
 
         if (users_load)
         {
-            foreach(var u in users.OrderBy(u => u.id))
-            WorkerMarker(u, Color.green);
             users_load = false;
+            foreach (var u in users.OrderBy(u => u.id))
+                WorkerMarker(u, Color.green);
+        }
+
+        if (beacons_load)
+        {
+            beacons_load = false;
+            foreach (var b in Beacons)
+                AddBeacon(b);
         }
     }
 
@@ -452,6 +435,14 @@ public class WorkerController : MonoBehaviour
         moving[m.acc_id].step = step;
     }
 
+    public void AddBeacon(Beacon b)
+    {
+        var beacon = Instantiate(Resources.Load("GameObjects/Beacon", typeof(GameObject))) as GameObject;
+        beacon.transform.position = new Vector3(b.x, 0.5f, b.y);
+        beacon.name = $"BeaconButton_{b.id}";
+        b.beacon = beacon;
+    }
+
     public void OpenEditor()
     {
         SceneManager.LoadScene("Scenes/Editor2D");

+ 4 - 1
Assets/Scripts/Models/Beacon.cs

@@ -8,10 +8,13 @@ using UnityEngine.UI;
 
 public class Beacon
 {
-    public uint id { get; set; }
+    public uint? id { get; set; }
     public float x { get; set; }
     public float y { get; set; }
     public float z { get; set; } // этаж
+    public string uuid { get; set; }
+    public uint minor { get; set; }
+    public uint major { get; set; }
     public GameObject beacon { get; set; }
     public Button button { get; set; }
 }

+ 9 - 0
Assets/Scripts/Net/Client.cs

@@ -29,6 +29,12 @@ public class Client : MonoBehaviour
     static bool ShowPackets = false; //ставится только в редакторе
     double initial_timer;
     int internal_timer = 0;
+
+    internal void SendGetUsers(object p)
+    {
+        throw new NotImplementedException();
+    }
+
     public double timer
     {
         get
@@ -816,7 +822,10 @@ public class Client : MonoBehaviour
             var major = BitConverter.ToUInt16(bytedata, read + 55);
             print($"beacon received id {id} uuid {uuid} x {x} y {y} z {z} minor {minor} major {major}");
             read += 56;
+
+            WorkerController.Beacons.Add(new Beacon { id = id, uuid = uuid, x = x, y = y, z = z, minor = minor, major = major });            
         }
+        WorkerController.beacons_load = true;
     }
 
     public void BeaconsRequest(uint locationId)