Виктор Шейко 4 роки тому
батько
коміт
2402def2bd

+ 1 - 0
Assets/Scenes/Player.unity

@@ -24614,6 +24614,7 @@ MonoBehaviour:
   UserInfo: {fileID: 1986755448}
   Editor: {fileID: 1379126276}
   broadcast: 0
+  active_mode: 2
   users_load: 0
   beacons_load: 0
 --- !u!1 &996525504

+ 13 - 10
Assets/Scripts/Controllers/CompanyController.cs

@@ -141,21 +141,24 @@ public class CompanyController : MonoBehaviour
         }
 
         active_company = DropdownCompany.value;
+        DropdownLocation.value = 0;
+        DropdownLocation.RefreshShownValue();
+        //active_location = 0;
             
-        if (player.users != null)
-            foreach (var m in player.users)
-            {
-                Destroy(m.Value.marker.gameObject);
-                Destroy(m.Value.marker_line.gameObject);
-                Destroy(m.Value.toggle_user);
-                //m.Value.UserCompany();
-            }
+        //if (player.users != null)
+        //    foreach (var m in player.users)
+        //    {
+        //        Destroy(m.Value.marker.gameObject);
+        //        Destroy(m.Value.marker_line.gameObject);
+        //        Destroy(m.Value.toggle_user);
+        //        //m.Value.UserCompany();
+        //    }
         Client.instance.company_id = (uint)(active_company + 1);
         User.SendGetUsers();
         //player.users = new Dictionary<uint, User>();
         //player.users = users[];
-        if(player.users != null)
-        foreach (var u in player.users.Values) u.UserCompany();            
+        if (player.users != null)
+            foreach (var u in player.users.Values) u.UserCompany();
         Location.LocationsRequest(0);
     }
 

+ 37 - 29
Assets/Scripts/Controllers/PlayerController.cs

@@ -42,8 +42,8 @@ public class PlayerController : MonoBehaviour
     public bool broadcast = false;
     public Dictionary<uint, User> users;
     public enum Mode { RealTime = 0, History = 1, Stop = 2 };
-    public static Mode active_mode = Mode.Stop;
-    int mode = 0;
+    public Mode active_mode = Mode.Stop;
+    //int mode = 0;
 
     Client client;
     CompanyController company;
@@ -89,8 +89,13 @@ public class PlayerController : MonoBehaviour
     // Update is called once per frame
     void Update()
     {
-        if (DropdownMode.value != mode)
+        //if (DropdownMode.value != mode)
+        //    СhangeMode();
+
+        DropdownMode.onValueChanged.AddListener(delegate
+        {
             СhangeMode();
+        });
 
         if (active_mode != Mode.Stop)
         {
@@ -106,10 +111,13 @@ public class PlayerController : MonoBehaviour
         {
             if (users_load == false)
             {
-                foreach (var u in users)
+                foreach (var u in users.Values)
                 {
-                    u.Value.marker_line.gameObject.SetActive(ToggleLine.isOn);
-                    if (ToggleLine.isOn == false) u.Value.marker_line.positionCount = 0;
+                    if (u.marker_line != null)
+                    {
+                        u.marker_line.gameObject.SetActive(ToggleLine.isOn);
+                        if (ToggleLine.isOn == false) u.marker_line.positionCount = 0;
+                    }
                 }
             }  
 
@@ -120,8 +128,8 @@ public class PlayerController : MonoBehaviour
                 {
                     u.Value.SetParam(BroadcastStart);
 
-                    if (DropdownMode.value == 0) u.Value.toggle_user.SetActive(u.Value.online);
-                    else u.Value.toggle_user.SetActive(true);
+                    //if (DropdownMode.value == 0) u.Value.toggle_user.SetActive(u.Value.online);
+                    //else u.Value.toggle_user.SetActive(true);
                 }
             }
         }
@@ -207,7 +215,6 @@ public class PlayerController : MonoBehaviour
                     {
                         if (u.Value.toggle.isOn)
                         {
-
                             client.CoordinatesRequest(time_start.Ticks, time_end.Ticks, 1, company.locations_index[company.active_location], u.Value.id);
                             end_send[u.Value.id] = false;
                         }
@@ -342,25 +349,26 @@ public class PlayerController : MonoBehaviour
         StopProgress();
 
         active_mode = Mode.Stop;
-        mode = DropdownMode.value;
-        switch (DropdownMode.value)
-        {            
-            case 0:
-                DateTimePanel.SetActive(false);
-                if (users != null)
-                    foreach (var u in users)
-                    {
-                        if(!u.Value.online) u.Value.toggle.isOn = false;
-                        u.Value.toggle_user.SetActive(u.Value.online);
-                    }
-                break;
-            case 1:
-                DateTimePanel.SetActive(true);
-                if (users != null)
-                    foreach (var u in users)
-                    u.Value.toggle_user.SetActive(true);
-                break;
-        }
+        foreach (var u in users) u.Value.UserCompany();
+        //mode = DropdownMode.value;
+        //switch (DropdownMode.value)
+        //{            
+        //    case 0:
+        //        DateTimePanel.SetActive(false);
+        //        if (users != null)
+        //            foreach (var u in users)
+        //            {
+        //                if(!u.Value.online) u.Value.toggle.isOn = false;
+        //                u.Value.toggle_user.SetActive(u.Value.online);
+        //            }
+        //        break;
+        //    case 1:
+        //        DateTimePanel.SetActive(true);
+        //        if (users != null)
+        //            foreach (var u in users)
+        //            u.Value.toggle_user.SetActive(true);
+        //        break;
+        //}
     }
 
     /// <summary>
@@ -373,7 +381,7 @@ public class PlayerController : MonoBehaviour
         {
             if (u.Value != null)
             {
-                if (u.Value.marker.activeSelf != u.Value.toggle.isOn) u.Value.marker.SetActive(u.Value.toggle.isOn);
+                //if (u.Value.marker.activeSelf != u.Value.toggle.isOn) u.Value.marker.SetActive(u.Value.toggle.isOn);
 
                 if (active_mode == Mode.RealTime && u.Value.toggle.isOn && !Workers.ContainsKey(u.Value.id))
                 {

+ 5 - 2
Assets/Scripts/Models/Location.cs

@@ -153,8 +153,11 @@ public class Location
                 {
                     z.buttons.SetActive(active);
 
-                    var lz = lzs.ZoneInfos[z.id];
-                    lz.gameObject.SetActive(active);
+                    if (lzs.ZoneInfos.ContainsKey(z.id))
+                    {
+                        var lz = lzs.ZoneInfos[z.id];
+                        lz.gameObject.SetActive(active);
+                    }
                 }
         if (active)
         {

+ 64 - 7
Assets/Scripts/Models/User.cs

@@ -26,7 +26,7 @@ public class User
     public static void UsersReceive(byte[] bytedata)
     {
         var player = PlayerController.instance;
-        player.users = new Dictionary<uint, User>();
+        if(player.users==null) player.users = new Dictionary<uint, User>();
         var companyId = BitConverter.ToUInt32(bytedata, 5);
         int read = 9;
         while (read < bytedata.Length)
@@ -38,8 +38,11 @@ public class User
             read += 6 + lenname;
             Debug.Log($"user received id {id} lenname {lenname} name {name} online {online} companyId {companyId}");
             //if (companyId == Client.instance.company_id) {
+            if(!player.users.ContainsKey(id)){
                 player.users.Add(id, new User { id = id, name_user = name, online = online != 0, company_id = companyId });
                 WorkerMarker(player.users[id], Color.green);
+                player.users[id].UserCompany();
+            }
             //}
         }
         player.users_load = true;
@@ -86,8 +89,10 @@ public class User
         if (u != null)
         {
             var b = cmd != 0;
-            u.toggle_user.SetActive(b);
-            u.marker.SetActive(b);
+            u.online = b;
+            //u.toggle_user.SetActive(b);
+            //u.marker.SetActive(b);
+            u.UserCompany();
         }
         else
         {
@@ -141,7 +146,7 @@ public class User
     public static void WorkerMarker(User user, Color color/*, GameObject WorkersList, Action<uint> BroadcastStart*/)
     {
         var toggle_user = UnityEngine.Object.Instantiate(Resources.Load("GameObjects/ToggleUser", typeof(GameObject))) as GameObject;
-        toggle_user.name = $"{user.id}";
+        toggle_user.name = $"user_{user.id}";
         var toggle = toggle_user.transform.GetChild(0).GetComponent<Toggle>();
         toggle.transform.GetChild(1).gameObject.GetComponent<Text>().text = $"{user.id} {user.name_user}";
         //toggle_user.transform.SetParent(WorkersList.transform);
@@ -158,6 +163,10 @@ public class User
 
         marker.GetComponent<Renderer>().material.color = color; // UnityEngine.Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f);
         marker.GetComponent<LabelObjectScript>().UserId = user.id;
+        toggle.onValueChanged.AddListener(delegate
+        {
+            marker.SetActive(toggle.isOn);
+        });
 
         var color_line = UnityEngine.Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f);
         var marker_line = UnityEngine.Object.Instantiate(Resources.Load("GameObjects/Line", typeof(LineRenderer))) as LineRenderer;
@@ -176,6 +185,10 @@ public class User
         toggle_user.transform.SetParent(player.WorkersList.transform);
     }
 
+    /// <summary>
+    /// Запуск потока с камеры
+    /// </summary>
+    /// <param name="BroadcastStart"></param>
     public void SetParam(Action<uint> BroadcastStart)
     {        
         var camera_button = toggle_user.transform.GetChild(1).GetComponent<Button>();
@@ -187,8 +200,52 @@ public class User
     /// </summary>
     public void UserCompany()
     {
-        var active = CompanyController.instance.active_location + 1 == company_id;
-        toggle_user.SetActive(active);
-        marker.SetActive(active);
+        var on = PlayerController.instance.DropdownMode.value == 0;
+        var active = Client.instance.company_id == company_id;
+
+        if (on)
+        {
+            toggle_user.SetActive(active && online);
+            marker.SetActive(active && online && toggle.isOn);
+        }
+        else
+        {
+            toggle_user.SetActive(active);
+            marker.SetActive(active && toggle.isOn);
+        }
+    }
+
+    public void BroadcastStart()
+    {
+        var player = PlayerController.instance;
+        var client = Client.instance;
+        var user_broadcast = player.user_broadcast;
+        if (user_broadcast.HasValue)
+        {
+            client.ImageStreamStopSend(user_broadcast.Value);
+            var camera_button = toggle_user.transform.GetChild(1).GetComponent<Button>();
+            camera_button.GetComponent<Image>().color = Color.white;
+            broadcast = false;
+        }
+        if (user_broadcast != id)
+        {
+            client.ImageStreamStartSend(id);
+            player.user_broadcast = id;
+            var name = player.UserInfo.transform.GetChild(1).GetChild(0).GetComponent<Text>();
+            name.text = $"{id} {name_user}";
+            name.GetComponent<RectTransform>().sizeDelta = new Vector2(name.preferredWidth, 30);
+
+            var camera_button = toggle_user.transform.GetChild(1).GetComponent<Button>();
+            camera_button.GetComponent<Image>().color = Color.green;
+
+            player.UserInfo.SetActive(false);
+            broadcast = true;
+        }
+        else
+        {
+            broadcast = false;
+            player.user_broadcast = null;
+            player.UserInfo.SetActive(false);
+        }
     }
 }