Explorar el Código

fix beacons and zones, fix new location

Виктор hace 4 años
padre
commit
6b1677ac30

+ 2 - 2
Assets/Scenes/Player.unity

@@ -38,7 +38,7 @@ RenderSettings:
   m_ReflectionIntensity: 1
   m_CustomReflection: {fileID: 0}
   m_Sun: {fileID: 0}
-  m_IndirectSpecularColor: {r: 0.4465782, g: 0.49641252, b: 0.5748167, a: 1}
+  m_IndirectSpecularColor: {r: 0.44657844, g: 0.49641222, b: 0.57481694, a: 1}
   m_UseRadianceAmbientProbe: 0
 --- !u!157 &3
 LightmapSettings:
@@ -28657,7 +28657,7 @@ MonoBehaviour:
   m_GameObject: {fileID: 1248872932}
   m_Enabled: 1
   m_EditorHideFlags: 0
-  m_Script: {fileID: 11500000, guid: 6ff4c5b9b9033f24cbcb4cd46ba2cac4, type: 3}
+  m_Script: {fileID: 11500000, guid: 928944b70edda4247ad7eecd7423af3e, type: 3}
   m_Name: 
   m_EditorClassIdentifier: 
   ButtonStatus: {fileID: 2098093788}

+ 13 - 12
Assets/Scripts/Components/WallCreate.cs

@@ -228,15 +228,15 @@ public class WallCreate : MonoBehaviour
     public static GameObject AddZone(GameObject Dialog, CompanyController company, GameObject ZonesScroll, Zone z = null)
     {        
         var location = company.locations[company.locations_index[company.active_location]].location;
-        var location_id = company.locations_index[company.active_location];
-        
+        var location_id = company.locations_index[company.active_location];        
 
-        if (!Zones.ContainsKey(location_id)) Zones[location_id] = new List<Zone>();
-        var zname = $"Зона {Zones[location_id].Count + 1}";
-        if (z != null)
-            zname = z.name;
+        if (!Zones.ContainsKey(location_id)) Zones[location_id] = new List<Zone>();        
+        
         var zone = Instantiate(Resources.Load("GameObjects/Zone", typeof(GameObject))) as GameObject;
-        zone.name= $"Zone_{Zones[location_id].Count + 1}";
+        zone.name = $"Zone_{Zones[location_id].Count + 1}";
+        var zname = $"Зона {Zones[location_id].Count + 1}";
+        if (z != null) zname = z.name;                       
+        
         //zone.transform.position = pos;
 
         zone.transform.SetParent(location.transform.GetChild(2).transform);
@@ -249,13 +249,16 @@ public class WallCreate : MonoBehaviour
         zone.GetComponent<ZoneController>().TextMesh.text = zname;
         var active_zone = Zones[location_id].Count;
         
-        if(z == null) z = new Zone { id= Convert.ToUInt32(4000000000 + Zones[location_id].Count), go=zone, buttons = panel_button, location_id= location_id };   
+        if(z == null) z = new Zone { id= Convert.ToUInt32(4000000000 + Zones[location_id].Count), location_id= location_id };   
         else
         {
             zone.transform.position = new Vector3(Mathf.Abs(z.start_width), 0.05f, Mathf.Abs(z.start_height));
             zone.transform.localScale = new Vector3(Mathf.Abs(z.end_width), 1, Mathf.Abs(z.end_height));
+            zone.name = $"Zone_{z.id}";            
         }
-        
+        z.buttons = panel_button;
+        z.go = zone;
+
         var button_ok = Dialog.transform.GetChild(2).GetComponent<Button>();
         
         button.onClick.AddListener(() =>
@@ -273,9 +276,7 @@ public class WallCreate : MonoBehaviour
                 button.transform.GetChild(0).GetComponent<Text>().text = name;
                 zone.GetComponent<ZoneController>().TextMesh.text = name;
                 Dialog.SetActive(false);
-
                 z.name = name;
-
                 //Zones[location_id].Insert(last_zone, z);
             });           
         });
@@ -310,6 +311,6 @@ public class WallCreate : MonoBehaviour
     static uint ZoneGetInnerID(uint location_id, int num)
     {
         var zone = Zones[location_id][num];
-        return (uint)zone.id;
+        return zone.id;
     }
 }

+ 51 - 23
Assets/Scripts/Controllers/CompanyController.cs

@@ -57,7 +57,7 @@ public class CompanyController : MonoBehaviour
         if (active_location != DropdownLocation.value && AuthorizationController.success && locations.Any())
             ChangeLocation();
 
-        if (active_location >= 0 && locations_index.Count > active_location)
+        if (active_location >= 0 && locations_index.Any())
             if (AuthorizationController.success && load_location_elements.ContainsKey(locations_index[active_location]))
             {
                 if (load_location_elements[locations_index[active_location]].location)
@@ -70,6 +70,8 @@ public class CompanyController : MonoBehaviour
                 ZonesOnOff();
             }
 
+        
+
         if (load_location)
         {
             load_location = false;
@@ -86,6 +88,17 @@ public class CompanyController : MonoBehaviour
                 load_location_elements[l.Key].location = true;
                 l.Value.Load();
             }
+
+            if (ModeController.editor && editor.newLocation != null)
+            {
+                var l = editor.newLocation;
+                //l.location.transform.SetParent(Locations.transform);
+                l.location.transform.SetSiblingIndex(Locations.transform.childCount - 1);
+                l.location.SetActive(false);
+                DropdownLocation.options.Add(new Dropdown.OptionData($"Новая локация"));
+                locations_index.Add(l.id);
+                locations[l.id] = l;
+            }
             DropdownLocation.value = 0;
             DropdownLocation.RefreshShownValue();
             active_location = DropdownLocation.value;
@@ -107,34 +120,47 @@ public class CompanyController : MonoBehaviour
     /// </summary>
     public void ChangeCompany()
     {
-        active_company = DropdownCompany.value;
-        //DropdownLocation.value = 0;        
+        foreach (var l in locations)
+        {
+            if (l.Value.id < (uint)int.MaxValue)
+            {
+                Destroy(l.Value.location);
+                foreach (var b in l.Value.beacons)
+                    Destroy(b.panel_button);
+                foreach (var z in l.Value.zones)
+                    Destroy(z.buttons); 
+                load_location_elements.Remove(l.Value.id);
+            }
+        }
 
-        for (var i = Locations.transform.childCount - 1; i >= 0; i--)
-            Destroy(Locations.transform.GetChild(i).gameObject);
-        load_location_elements.Clear();
+       
 
-        Client.instance.company_id = (uint)(active_company + 1);
+active_company = DropdownCompany.value;
+        Client.instance.company_id = (uint)(active_company + 1);       
+        if (player.markers != null)
+            foreach (var m in player.markers)
+            {
+                Destroy(m.marker.gameObject);
+                Destroy(m.marker_line.gameObject);
+                Destroy(m.toggle_user);
+            } 
         Client.instance.SendGetUsers();
-        if(player.markers != null)
-        foreach (var m in player.markers)
-        {
-            Destroy(m.marker.gameObject);
-            Destroy(m.marker_line.gameObject);
-            Destroy(m.toggle_user);
-        }
         player.markers = new List<Marker>();
         Location.LocationsRequest(0);
     }
 
- float sizex = 0;
+    float sizex = 0;
     float sizey = 0;
     public void ChangeLocation()
     {
         Debug.Log("PlayerController locations count " + locations.Count + " active " + active_location);
-        if (active_location >= 0) locations[locations_index[active_location]].location.SetActive(false);
+        if (active_location >= 0)
+            locations[locations_index[active_location]].LocationActive(false);   
+
         active_location = DropdownLocation.value;
         var l = locations[locations_index[active_location]];
+        l.LocationActive(true);
+
         if (!l.texture_url.Equals("")) StartCoroutine(SendingFormController.LoadImage(l.texture_url, l.plane, l.plane.transform.position, l.plane.transform.localScale));
 
         editor.Name.text = l.name;
@@ -151,9 +177,7 @@ public class CompanyController : MonoBehaviour
             editor.SizeY.text = $"{l.plane.transform.localScale.z}";
             sizey = l.plane.transform.localScale.z;
         }              
-
-        l.location.SetActive(true);
-    }
+    }  
 
     public void LocationContents(Location location)
     {
@@ -169,7 +193,9 @@ public class CompanyController : MonoBehaviour
                 var walls = location.location.transform.GetChild(1);
                 foreach (var w in location.walls)
                 {
-                    var wall = WallCreate.AddWall(this, new Vector3(w.start_width, WallCreate.WallHeight / 2, w.start_height), new Vector3(w.end_width, WallCreate.WallHeight, w.end_height));
+                    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)));
                     wall.transform.SetParent(walls.transform);
                 }
             }
@@ -179,8 +205,9 @@ public class CompanyController : MonoBehaviour
                 //var beacons = location.Beacons ?? new GameObject();
                 //beacons.name = "Beacons";
                 //beacons.transform.SetParent(location.location.transform);
-               
-                foreach (var b in location.beacons) {
+
+                foreach (var b in location.beacons)
+                {
                     editor.AddBeacon(this, b);
                     if (ModeController.editor == true) b.beacon.GetComponent<BeaconController>().mode = BeaconController.Mode.Editor;
                 }
@@ -191,8 +218,9 @@ public class CompanyController : MonoBehaviour
                 load_location_elements[location.id].zones = false;
                 //var zones = location.Zones ?? new GameObject();               
                 //zones.name = "Zones";
-                //zones.transform.SetParent(location.location.transform);
+                //zones.transform.SetParent(location.location.transform);                
 
+               
                 foreach (var z in location.zones)
                     z.go = WallCreate.AddZone(Dialog, this, ZonesScroll, z);
             }

+ 10 - 71
Assets/Scripts/Controllers/EditorController.cs

@@ -33,6 +33,8 @@ public class EditorController : MonoBehaviour
     public GameObject NewLocation;
     public GameObject plane;
 
+    public Location newLocation;
+
     public Dictionary<uint, List<Beacon>> Beacons = new Dictionary<uint, List<Beacon>>();
 
     CompanyController company;
@@ -77,17 +79,18 @@ public class EditorController : MonoBehaviour
                 go.name = g;
                 go.transform.SetParent(NewLocation.transform);
             }
-            var location = new Location
+            newLocation = new Location
             {
                 id = uintNumber,
                 location = NewLocation,
                 walls = new List<Wall>(),
                 zones = new List<Zone>(),
                 beacons = new List<Beacon>(),
-                plane = plane
+                plane = plane,
+                texture_url = ""
             };
-            company.locations[location.id] = location;
-            company.locations_index.Add(location.id);
+            company.locations[newLocation.id] = newLocation;
+            company.locations_index.Add(newLocation.id);
 
             DropdownLocation.options.Add(new Dropdown.OptionData("Новая локация"));
 
@@ -98,35 +101,7 @@ public class EditorController : MonoBehaviour
    
     // Update is called once per frame
     void Update()
-    {
-        //if (company.active_location != DropdownLocation.value && AuthorizationController.success && company.locations.Any())
-        //{
-        //    //company.ChangeLocation();
-        //    var location = company.locations[company.locations_index[company.active_location]];
-        //    Name.text = location.name;
-        //    Image.text = location.texture_url;
-
-        //    company.active_location = DropdownLocation.value;
-        //    EditLocation = location;
-
-        //    foreach (var b in EditLocation.beacons)
-        //        b.beacon.GetComponent<BeaconController>().mode = BeaconController.Mode.Editor;
-        //}
-
-        //if (EditLocation == null)
-        //{
-        //    EditLocation = company.locations[company.locations_index[company.active_location]];
-        //    Name.text = EditLocation.name;
-        //    Image.text = EditLocation.texture_url;
-
-        //    foreach (var b in EditLocation.beacons)
-        //        b.beacon.GetComponent<BeaconController>().mode = BeaconController.Mode.Editor;
-        //}
-
-       
-
-        //if (ToggleScalePanel.isOn != plane.GetComponent<TouchScript>().activeScript) plane.GetComponent<TouchScript>().activeScript = ToggleScalePanel.isOn;
-
+    {        
         if (projection.isOn)
         {
             Camera.main.orthographic = true;
@@ -135,9 +110,6 @@ public class EditorController : MonoBehaviour
         {
             Camera.main.orthographic = false;
         }
-
-
-        //PlayerController.LoadMaps(DropdownLocation, Locations.gameObject);
     }
 
     string texture_url = "";
@@ -197,40 +169,7 @@ public class EditorController : MonoBehaviour
             company.DropdownLocation.options.Last().text = location.name;
 
             location.location.name = location.name;
-
-
-            //foreach (var g in Location.gos)
-            //{
-            //    var temp = location.location.transform.Find(g);
-
-            //    for (var i = 0; i < temp.childCount; i++)
-            //    {
-            //        var go = temp.GetChild(i);
-            //        if (g.Equals(Location.gos[0]))
-            //        {
-            //            var currentWall = new Wall { start_width = go.position.x, start_height =go.position.z, end_width = go.localScale.x, end_height = go.localScale.z, go = go.gameObject };
-            //            location.walls.Add(currentWall);
-            //        }
-            //        if (g.Equals(Location.gos[1]))
-            //        {
-            //            var currentZone = new Zone { start_width = go.position.x, start_height = go.position.z, end_width = go.localScale.x, end_height = go.localScale.z, go = go.gameObject };
-            //            location.zones.Add(currentZone);
-            //        } 
-            //        //if (g.Equals(Location.gos[2]))
-            //        //{
-            //        //    var currentBeacon = new Beacon { beacon = temp.gameObject, enabled =  };
-            //        //    location.zones.Add(currentZone);
-            //        //}
-            //    }
-
-            //}
-            //location.location.transform.SetParent(Locations);
-            //foreach(var b in location.beacons)
-            //    b.beacon.transform.SetParent(location.location.transform);
-            //foreach (var w in location.walls)
-            //    w.go.transform.SetParent(location.location.transform);
-            //foreach (var z in location.zones)
-            //    z.go.transform.SetParent(location.location.transform);
+           
             location.Save();
             location.SaveContents();
             mode.Switch();
@@ -301,7 +240,7 @@ public class EditorController : MonoBehaviour
 
             BeaconEdit(b, name_beacon);
         }
-        
+
         var button_ok = PanelBeaconEdit.transform.GetChild(7).transform.GetChild(0).GetComponent<Button>();
         button_ok.onClick.AddListener(() =>
         {           

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

@@ -85,14 +85,12 @@ public class ModeController : MonoBehaviour
         Destroy(GameObject.Find("SizeX"));
         Destroy(GameObject.Find("SizeY"));
 
-
         if (item == null)
         {
             item = maps.GetComponent<Dropdown>().options.Last();
             maps.GetComponent<Dropdown>().options.Remove(item);
             maps.GetComponent<Dropdown>().RefreshShownValue();
-        }
-        
+        }        
 
         //for (int i = 0; i < Beacons.transform.childCount; i++)
         //{

+ 2 - 42
Assets/Scripts/Controllers/PlayerController.cs

@@ -13,7 +13,7 @@ public class PlayerController : MonoBehaviour
     public static PlayerController instance;
     public Dictionary<uint, List<Structure>> Workers = new Dictionary<uint, List<Structure>>();
     public List<Structure> TestStructures = new List<Structure>();
-    public List<Beacon> Beacons = new List<Beacon>();
+    //public List<Beacon> Beacons = new List<Beacon>();
 
     public GameObject WorkersList; // scroll content
    
@@ -399,41 +399,6 @@ public class PlayerController : MonoBehaviour
         DebugHelper.DrawConsole();
     }
 
-    //public static void LoadMaps(Dropdown DropdownLocation, GameObject Locations)
-    //{
-    //    if (active_location != DropdownLocation.value && AuthorizationController.success && locations.Any())
-    //    {
-    //        if (active_location >= 0) Locations.transform.GetChild(active_location).gameObject.SetActive(false);
-    //        Locations.transform.GetChild(DropdownLocation.value).gameObject.SetActive(true);
-    //        active_location = DropdownLocation.value;           
-
-    //        //if (locations[active_location].walls == null) locations[active_location].Load();
-
-    //        foreach (var b in Beacons)
-    //        {
-    //            Destroy(b.beacon);
-    //            Destroy(b.panel_button);
-    //        }
-    //        Beacons = new List<Beacon>();
-
-    //        if (ModeController.editor == true && DropdownLocation.value != DropdownLocation.options.Count - 1)
-    //            Client.BeaconsRequest(locations_index[active_location]);
-    //        if (ModeController.editor == false)
-    //            Client.BeaconsRequest(locations_index[active_location]);
-    //    }
-
-    //    //if (beacons_load)
-    //    //{
-    //    //    beacons_load = false;
-    //    //    foreach (var b in Beacons)
-    //    //    {
-    //    //        //if (ModeController.editor == false) AddBeacon(b);
-    //    //        //if (ModeController.editor == true) 
-    //    //        editor.AddBeacon(b);
-    //    //    }
-    //    //}
-    //}
-
     /// <summary>
     /// Остановка отрисовки при смене режима история/онлайн
     /// </summary>
@@ -463,12 +428,7 @@ public class PlayerController : MonoBehaviour
         {
             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])
-            {
-                //end_send[m.value.acc_id] = false;
-                // moving.Add(true);
-
-                //if (markers.Count - 1 == m.i)                   
-
+            {    
                 StartingAccPositiong(m.value);
 
                 var temp = Workers.Values.Max(v => v.Count);

+ 13 - 0
Assets/Scripts/Models/Location.cs

@@ -139,5 +139,18 @@ public class Location
         }
         company.load_location = true;
     }
+
+    public void LocationActive(bool active)
+    {
+        location.SetActive(active);
+        if (beacons != null)
+            foreach (var b in beacons)
+                if (b.panel_button != null)
+                    b.panel_button.SetActive(active);
+        if (zones != null)
+            foreach (var z in zones)
+                if (z.buttons != null)
+                    z.buttons.SetActive(active);
+    }
 }