Browse Source

fix worker move

Виктор 4 years ago
parent
commit
eda982987e

+ 60 - 28
Assets/Scripts/Controllers/PlayerController.cs

@@ -121,19 +121,20 @@ public class PlayerController : MonoBehaviour
             time_draw -= interpolationPeriod;
         }
 
-        if (active_mode == Mode.RealTime && !starting)
-        {
-            foreach (var m in markers)
-            {
-                if (m.toggle.isOn)
-                {
-                    var index = company.locations_index[company.active_location];
-                    client.CoordinatesRequest(0, 0, 1, company.locations[index].id, m.acc_id);
-                    end_send[m.acc_id] = false;
-                }
-            }
-            starting = true;
-        }
+        //if (active_mode == Mode.RealTime && !starting)
+        //{
+        //    foreach (var m in markers)
+        //    {
+        //        if (m.toggle.isOn)
+        //        {
+        //            Debug.LogWarning($"send {m.acc_id}");
+        //            var index = company.locations_index[company.active_location];
+        //            client.CoordinatesRequest(0, 0, 1, company.locations[index].id, m.acc_id);
+        //            //end_send[m.acc_id] = false;
+        //        }
+        //    }
+        //    starting = true;
+        //}\\\\\
 
         if (ToggleLine.isOn)
         {
@@ -223,6 +224,7 @@ public class PlayerController : MonoBehaviour
     /// <returns></returns>
     void Position(float step, Vector3 start_pos, Vector3 end_pos, Marker marker, Structure w, string progress)
     {
+        Debug.LogWarning($"move user {marker.acc_id} {end_pos} {w.ts} {w.zone_id}");
         if (marker.marker.activeSelf == true)
         {
             var x_position = Mathf.Lerp(start_pos.x, end_pos.x, step);
@@ -348,33 +350,52 @@ public class PlayerController : MonoBehaviour
         int i = 0;
         float step = 0.1f;
         if (moving.ContainsKey(m.acc_id))
-        {
+        {           
             if (moving[m.acc_id].index < Workers[m.acc_id].Count) i = moving[m.acc_id].index;
             if (moving[m.acc_id].step < 1.1f) step = moving[m.acc_id].step;
         }
         else moving[m.acc_id] = new MarkerMoving();
 
-        var worker = Workers[m.acc_id].OrderBy(wr => wr.ts).ToList();
+        var worker = Workers[m.acc_id];
+        Debug.LogWarning($"worker coord count {m.acc_id} {worker.Count}");
+        if (active_mode == Mode.RealTime) worker = worker.OrderBy(wr => wr.ts).ToList();
         if (worker.Any())
         {
-            var w = worker.ElementAt(i);
+            var w = worker[i];
             var start_pos = m.marker.transform.position;
             if (i != 0) start_pos = new Vector3(worker[i - 1].coord_x, 0.5f, worker[i - 1].coord_y);
-            if (active_mode == Mode.History && i == 0) start_pos = new Vector3(w.coord_x , 0.5f, w.coord_y);
+            if (active_mode == Mode.History && i == 0) start_pos = new Vector3(w.coord_x, 0.5f, w.coord_y);
 
             var end_pos = new Vector3(w.coord_x, 0.5f, w.coord_y);
 
             var progress = "";
             if (active_mode == Mode.History) progress = $"\n{i + 1} из {Workers[m.acc_id].Count}";
-            if (starting) Position(step, start_pos, end_pos, m, w, progress);
+            //if (starting) 
+                Position(step, start_pos, end_pos, m, w, progress);
             // StartingAccPositiong(m.value, time_step);
 
         }
 
-        if (step >= 1) i++;
+        if (step >= 1)
+        {
+            i++;
+        }
         step += interpolationPeriod; // 0.1f;
         moving[m.acc_id].index = i;
         moving[m.acc_id].step = step;
+
+        if (active_mode == Mode.RealTime)
+            if (moving[m.acc_id].step >= 1)
+            {
+                Workers.Remove(m.acc_id);
+                Debug.LogWarning($"clear coord user {m.acc_id}");
+            }
+        if (active_mode == Mode.History)
+            if (moving[m.acc_id].index == Workers[m.acc_id].Count)
+            {
+                //StopProgress();
+                Workers.Remove(m.acc_id);
+            }
     }
 
     /// <summary>
@@ -426,19 +447,30 @@ public class PlayerController : MonoBehaviour
     {
         foreach (var m in markers.Select((value, i) => (value, i)))
         {
-            m.value.marker.SetActive(m.value.toggle.isOn);
-            if (m.value.toggle.isOn && Workers.ContainsKey(m.value.acc_id) && starting && end_send[m.value.acc_id])
-            {    
+            if (m.value.marker.activeSelf != m.value.toggle.isOn) m.value.marker.SetActive(m.value.toggle.isOn);
+
+            if (active_mode == Mode.RealTime && m.value.toggle.isOn && !Workers.ContainsKey(m.value.acc_id))
+            {
+                Debug.LogWarning($"send coord user {m.value.acc_id}");
+                var index = company.locations_index[company.active_location];
+                client.CoordinatesRequest(0, 0, 1, company.locations[index].id, m.value.acc_id);
+            }
+
+            if (m.value.toggle.isOn && Workers.ContainsKey(m.value.acc_id) && active_mode != Mode.Stop/*&& starting*/ /*&& end_send[m.value.acc_id]*/)
+            {
                 StartingAccPositiong(m.value);
 
-                var temp = Workers.Values.Max(v => v.Count);
-                if (active_mode == Mode.History && m.i == temp - 1 && moving[moving.Keys.Last()].step >= 1f)
+                if (active_mode == Mode.History && !Workers.Any())
                 {
+                    //var temp = Workers.Values.Max(v => v.Count);
+                    //if (m.i == temp - 1 && moving[moving.Keys.Last()].step >= 1f)
+                    //{
                     StopProgress();
-                }
-                if (active_mode == Mode.RealTime && moving[moving.Keys.Last()].index == 1)
-                {
-                    starting = false;
+                    //}
+                    //if (active_mode == Mode.RealTime && moving[moving.Keys.Last()].index == 1)
+                    //{
+                    //    starting = false;
+                    //}
                 }
             }
         }

+ 20 - 0
Assets/Scripts/Controllers/WorkerController.cs

@@ -0,0 +1,20 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class WorkerController : MonoBehaviour
+{
+    public uint id;
+
+    // Start is called before the first frame update
+    void Start()
+    {
+        
+    }
+
+    // Update is called once per frame
+    void Update()
+    {
+        
+    }
+}

+ 1 - 0
Assets/Scripts/Models/Marker.cs

@@ -13,5 +13,6 @@ public class Marker
     public GameObject marker { get; set; }
     public LineRenderer marker_line { get; set; }
     public uint acc_id { get; set; }
+    public bool starting { get; set; }
 }
 

+ 3 - 0
Assets/Scripts/Models/Structure.cs

@@ -3,6 +3,9 @@ using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
+/// <summary>
+/// координаты с сервера
+/// </summary>
 public class Structure
 {
     public uint id { get; set; }

+ 2 - 1
Assets/Scripts/Models/Wall.cs

@@ -75,7 +75,8 @@ public class Wall
             location_id = lid;
         }
 
-        if (location_id != 0)company.load_location_elements[location_id].walls = true;
+        if (location_id != 0)
+            company.load_location_elements[location_id].walls = true;
     }
 
     public static void LoadByLocationId(uint locId)