Browse Source

users online + user zone

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

+ 2 - 2
Assets/Resources/GameObjects/ToggleUser.prefab

@@ -226,7 +226,7 @@ MonoBehaviour:
   m_OnCullStateChanged:
     m_PersistentCalls:
       m_Calls: []
-  m_Sprite: {fileID: 0}
+  m_Sprite: {fileID: 10911, guid: 0000000000000000f000000000000000, type: 0}
   m_Type: 1
   m_PreserveAspect: 0
   m_FillCenter: 1
@@ -374,7 +374,7 @@ MonoBehaviour:
   m_OnCullStateChanged:
     m_PersistentCalls:
       m_Calls: []
-  m_Sprite: {fileID: 0}
+  m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0}
   m_Type: 1
   m_PreserveAspect: 0
   m_FillCenter: 1

+ 2 - 2
Assets/Resources/GameObjects/ZoneInfo.prefab

@@ -63,12 +63,12 @@ MonoBehaviour:
   m_Name: 
   m_EditorClassIdentifier: 
   m_Material: {fileID: 0}
-  m_Color: {r: 1, g: 1, b: 1, a: 0.78431374}
+  m_Color: {r: 1, g: 1, b: 1, a: 0.39215687}
   m_RaycastTarget: 1
   m_OnCullStateChanged:
     m_PersistentCalls:
       m_Calls: []
-  m_Sprite: {fileID: 0}
+  m_Sprite: {fileID: 10907, guid: 0000000000000000f000000000000000, type: 0}
   m_Type: 1
   m_PreserveAspect: 0
   m_FillCenter: 1

+ 18 - 3
Assets/Scenes/Playerold.unity

@@ -1161,10 +1161,14 @@ MonoBehaviour:
   m_Script: {fileID: 11500000, guid: 503a24c7752c50343834ceb2cdf964e3, type: 3}
   m_Name: 
   m_EditorClassIdentifier: 
+  id: 0
   rooms:
   - {fileID: 2137186683}
   - {fileID: 1765107640}
-  Location: {fileID: 60701535}
+  Ground: {fileID: 0}
+  Walls: {fileID: 0}
+  Zones: {fileID: 0}
+  Beacons: {fileID: 0}
 --- !u!4 &60701537
 Transform:
   m_ObjectHideFlags: 0
@@ -15786,11 +15790,15 @@ MonoBehaviour:
   m_Script: {fileID: 11500000, guid: 503a24c7752c50343834ceb2cdf964e3, type: 3}
   m_Name: 
   m_EditorClassIdentifier: 
+  id: 0
   rooms:
   - {fileID: 0}
   - {fileID: 0}
   - {fileID: 0}
-  Location: {fileID: 670244520}
+  Ground: {fileID: 0}
+  Walls: {fileID: 0}
+  Zones: {fileID: 0}
+  Beacons: {fileID: 0}
 --- !u!1 &680301590
 GameObject:
   m_ObjectHideFlags: 0
@@ -24736,6 +24744,7 @@ MonoBehaviour:
   m_Script: {fileID: 11500000, guid: 503a24c7752c50343834ceb2cdf964e3, type: 3}
   m_Name: 
   m_EditorClassIdentifier: 
+  id: 0
   rooms:
   - {fileID: 0}
   - {fileID: 925572859}
@@ -24743,7 +24752,10 @@ MonoBehaviour:
   - {fileID: 1911898849}
   - {fileID: 434253705}
   - {fileID: 302417704}
-  Location: {fileID: 1054412954}
+  Ground: {fileID: 0}
+  Walls: {fileID: 0}
+  Zones: {fileID: 0}
+  Beacons: {fileID: 0}
 --- !u!4 &1054412956
 Transform:
   m_ObjectHideFlags: 0
@@ -42689,6 +42701,8 @@ MonoBehaviour:
   Dialog: {fileID: 0}
   ZonesScroll: {fileID: 1296382291}
   Player: {fileID: 995816062}
+  redo: {fileID: 0}
+  undo: {fileID: 0}
 --- !u!1 &1765107640
 GameObject:
   m_ObjectHideFlags: 0
@@ -48026,6 +48040,7 @@ MonoBehaviour:
   Building: {fileID: 2022292460}
   BuildingMode: {fileID: 935354065}
   GroundSettings: {fileID: 583944819}
+  DateTime: {fileID: 1259139722}
 --- !u!1 &1953112961
 GameObject:
   m_ObjectHideFlags: 0

+ 14 - 1
Assets/Scripts/Components/LocationZones.cs

@@ -30,7 +30,8 @@ public class LocationZones : MonoBehaviour
         var zone_info = Instantiate(Resources.Load("GameObjects/ZoneInfo", typeof(ZoneInfo))) as ZoneInfo;
         ZoneInfos.Add(zone.id, zone_info);
         zone_info.text.text = zone.name;
-        zone_info.transform.parent = gameObject.GetComponent<ScrollRect>().content.transform;
+        zone_info.zone = zone;        
+        zone_info.transform.SetParent(gameObject.GetComponent<ScrollRect>().content.transform);
     }
 
     /// <summary>
@@ -60,4 +61,16 @@ public class LocationZones : MonoBehaviour
         foreach (var z in ZoneInfos)
             Destroy(z.Value);
     }
+
+    /// <summary>
+    /// Зона пользователя
+    /// </summary>
+    /// <param name="user_id"></param>
+    public void UserPosition(User user, Structure user_pos)
+    {
+        foreach (var z in ZoneInfos)
+        {
+            z.Value.UserDetectPosition(user, user_pos);
+        }
+    }
 }

+ 2 - 2
Assets/Scripts/Components/WallCreate.cs

@@ -257,7 +257,7 @@ public class WallCreate : MonoBehaviour
 
         var panel_button = Instantiate(Resources.Load("GameObjects/Panel_Beacon", typeof(GameObject))) as GameObject;
         panel_button.transform.SetParent(ZonesScroll.transform);
-        panel_button.name = $"Zone_{Zones.Count}";
+       
         var button = panel_button.transform.GetChild(0).GetComponent<Button>();
         button.transform.GetChild(0).GetComponent<Text>().text = zname;
         var tm = zone.GetComponent<ZoneController>().TextMesh;
@@ -267,7 +267,7 @@ public class WallCreate : MonoBehaviour
         //tm.transform.parent=zone.transform;
 
         var active_zone = Zones[location_id].Count;
-        
+         panel_button.name = $"Zone_{active_zone}";
         if(z == null) z = new Zone { id= Convert.ToUInt32(4000000000 + Zones[location_id].Count), location_id= location_id };   
         else
         {

+ 30 - 3
Assets/Scripts/Components/ZoneInfo.cs

@@ -6,8 +6,10 @@ using UnityEngine.UI;
 public class ZoneInfo : MonoBehaviour
 {
     public int id;
+    public Zone zone;
     public ScrollRect scrollRect;
     public Text text;
+    public Dictionary<uint, GameObject> users = new Dictionary<uint, GameObject>();
 
     // Start is called before the first frame update
     void Start()
@@ -23,8 +25,33 @@ public class ZoneInfo : MonoBehaviour
 
     public void AddWorker(User user)
     {
-        var user_name = Instantiate(text);
-        user_name.transform.parent=scrollRect.content.transform;
-        user_name.text = user.name;
+        if (!users.ContainsKey(user.id))
+        {
+            var user_name = Instantiate(text);
+            user_name.fontSize = 12;
+            user_name.transform.parent = scrollRect.content.transform;
+            user_name.text = user.name;
+            users[user.id] = user_name.gameObject;
+        }
+    }
+
+    public void DeleteWorker(uint user_id)
+    {
+        if (users.ContainsKey(user_id))
+        {
+            var go = users[user_id];
+            Destroy(go);
+            users.Remove(user_id);
+        }
+    }
+
+    public void UserDetectPosition(User user, Structure user_pos)
+    {
+        var coord = zone.Coordinates();
+        if (coord[0] < user_pos.coord_x && coord[2] > user_pos.coord_x && coord[1] < user_pos.coord_y && coord[3] > user_pos.coord_y)
+        {
+            AddWorker(user);
+        }
+        else DeleteWorker(user.id);
     }
 }

+ 19 - 3
Assets/Scripts/Controllers/PlayerController.cs

@@ -26,6 +26,7 @@ public class PlayerController : MonoBehaviour
     public GameObject EndMin;
     public GameObject EndSec;
     public GameObject StartStopButton;
+    public LocationZones locationZones;
     //public GameObject ErrorDialog;
     public Dropdown DropdownMode;
     public Toggle ToggleLine;
@@ -163,7 +164,11 @@ public class PlayerController : MonoBehaviour
         {
             users_load = false;
             foreach (var u in users.OrderBy(u => u.id))
+            {
                 WorkerMarker(u, Color.green);
+                if(DropdownMode.value == 0) markers[u.id].toggle_user.SetActive(u.online);
+                else markers[u.id].toggle_user.SetActive(true);
+            }
         }
 
         //LoadMaps(DropdownLocation, Locations);
@@ -354,11 +359,16 @@ public class PlayerController : MonoBehaviour
         else moving[m.acc_id] = new MarkerMoving();
 
         var worker = Workers[m.acc_id];
-        Debug.LogWarning($"worker coord count {m.acc_id} {worker.Count}");
+        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[i];
+
+            var user = users.Single(u => u.id == m.acc_id);
+            locationZones.UserPosition(user, w);           
+
             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);
@@ -432,9 +442,13 @@ public class PlayerController : MonoBehaviour
         {
             case 0:
                 DateTimePanel.SetActive(false);
+                foreach(var u in users)
+                    markers[u.id].toggle_user.SetActive(u.online);
                 break;
             case 1:
                 DateTimePanel.SetActive(true);
+                foreach (var u in users)
+                    markers[u.id].toggle_user.SetActive(true);
                 break;
         }
     }
@@ -450,13 +464,15 @@ public class PlayerController : MonoBehaviour
 
             if (active_mode == Mode.RealTime && m.Value.toggle.isOn && !Workers.ContainsKey(m.Value.acc_id))
             {
-                Debug.LogWarning($"send coord user {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);
+
+                m.Value.toggle_user.SetActive(users.Single(u => u.id ==m.Value.acc_id).online);
             }
 
             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);
 
                 if (active_mode == Mode.History && !Workers.Any())

+ 1 - 3
Assets/Scripts/Controllers/ZonesEditorController.cs

@@ -71,7 +71,5 @@ public class ZonesEditorController : MonoBehaviour
         Destroy(Zones[id].go);
         Destroy(Zones[id].buttons);
         Zones.Remove(id);
-    }
-
-    
+    }    
 }

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

@@ -9,6 +9,7 @@ public class User
 {
     public uint id { get; set; }
     public string name { get; set; }
+    public bool online { get; set; }
 
     public static void UsersReceive(byte[] bytedata)
     {
@@ -24,7 +25,7 @@ public class User
             var name = Encoding.UTF8.GetString(bytedata, read + 6, lenname);
             read += 6 + lenname;
             Debug.Log($"user received id {id} lenname {lenname} name {name} online {online}");
-            player.users.Add(new User { id = id, name = name });
+            player.users.Add(new User { id = id, name = name, online = online!=0 });
         }
         player.users_load = true;
     }

+ 23 - 0
Assets/Scripts/Models/Zone.cs

@@ -101,5 +101,28 @@ public class Zone
         CompanyController.instance.locations[locId].zones = new List<Zone>();
         Client.SendFourByteParamPacket(52, locId);
     }
+
+    /// <summary>
+    /// Перевод позиции и масштаба в координаты левой нижней (x1;z1) и правой верхней (x2;z2) точек
+    /// </summary>
+    /// <returns></returns>
+    public List<float> Coordinates()
+    {
+        var coord = new List<float>();
+
+        //var wall = WallCreate.AddWall(this,
+        //               new Vector3(w.start_width, WallCreate.WallHeight / 2, w.start_height),
+        //               new Vector3(Mathf.Abs(w.end_width), WallCreate.WallHeight, Mathf.Abs(w.end_height)));
+        var x1 = start_width - (end_width * 10 / 2);
+        coord.Add(x1); //x1
+        var x2 = start_height - (end_height * 10 / 2);
+        coord.Add(x2); //z1
+        var z1 = start_width + (end_width * 10 / 2);
+        coord.Add( z1); //x2
+        var z2 = start_height + (end_height * 10 / 2);
+        coord.Add(z2); //z2
+
+        return coord;
+    }
 }
 

+ 4 - 1
ProjectSettings/EditorBuildSettings.asset

@@ -5,7 +5,10 @@ EditorBuildSettings:
   m_ObjectHideFlags: 0
   serializedVersion: 2
   m_Scenes:
-  - enabled: 1
+  - enabled: 0
     path: Assets/Scenes/Player.unity
     guid: c0b38db15ebfc8b4fbd5046c1b62bfd8
+  - enabled: 1
+    path: Assets/Scenes/Playerold.unity
+    guid: 586f6184d109c0f40ae0375dc29aa491
   m_configObjects: {}