Browse Source

фиксы сохранения

Rimmon 4 years ago
parent
commit
c603510519

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

@@ -163,7 +163,7 @@ public class WallCreate : MonoBehaviour
                 var w = wall.transform.GetChild(i);
                 if(w.gameObject.activeSelf == true)
                 {
-                    currentWall = new Wall { id = Convert.ToUInt32(4000000000 + Walls.Count),location_id = location_id, start_width = w.position.x, start_height = w.position.z, end_width = w.localScale.x, end_height = w.localScale.z, go = wall };
+                    currentWall = new Wall { id = Convert.ToUInt32(4000000000 + Walls[location_id].Count),location_id = location_id, start_width = w.position.x, start_height = w.position.z, end_width = w.localScale.x, end_height = w.localScale.z, go = wall };
                     Walls[location_id].Add(currentWall);
                 }
             }
@@ -172,7 +172,7 @@ public class WallCreate : MonoBehaviour
         //if (mode == Mode.Room) Rooms.Add(currentWall);
         if (mode == Mode.Wall)
         {
-            currentWall = new Wall { id =Convert.ToUInt32(4000000000 + Walls.Count), start_width = wall.transform.position.x, start_height = wall.transform.position.z, end_width = wall.transform.localScale.x, end_height = wall.transform.localScale.z, go = wall };
+            currentWall = new Wall { id =Convert.ToUInt32(4000000000 + Walls[location_id].Count), start_width = wall.transform.position.x, start_height = wall.transform.position.z, end_width = wall.transform.localScale.x, end_height = wall.transform.localScale.z, go = wall, location_id=location_id };
             Debug.Log($"new wall save id {currentWall.id}  x {currentWall.start_width} z {currentWall.start_height} x2 {currentWall.end_width} z2 {currentWall.end_height} location_id {currentWall.location_id}");
             Walls[location_id].Add(currentWall);
         }
@@ -243,7 +243,7 @@ public class WallCreate : MonoBehaviour
         zone.GetComponent<ZoneController>().TextMesh.text = $"Зона {Zones[location_id].Count+1}";
         var active_zone = Zones[location_id].Count;
         
-        if(z == null) z = new Zone { id= Convert.ToUInt32(4000000000 + Zones.Count), go=zone, buttons = panel_button, location_id=(uint) location_id };   
+        if(z == null) z = new Zone { id= Convert.ToUInt32(4000000000 + Zones[location_id].Count), go=zone, buttons = panel_button, location_id=(uint) location_id };   
         else
         {
             zone.transform.position = new Vector3(z.start_width, 0.05f, z.start_height);

+ 2 - 2
Assets/Scripts/Controllers/EditorController.cs

@@ -233,7 +233,7 @@ public class EditorController : MonoBehaviour
             //    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();
         }
@@ -298,7 +298,7 @@ public class EditorController : MonoBehaviour
         {
             b = new Beacon();
             b.location_id = location.id; 
-            b.id = Convert.ToUInt32(4000000000 + Beacons.Count);
+            b.id = Convert.ToUInt32(4000000000 + Beacons[location.id].Count);
             b.enabled = true;
 
             BeaconEdit(b, name_beacon);

+ 4 - 4
Assets/Scripts/Models/Location.cs

@@ -42,7 +42,6 @@ public class Location
 
     public void SaveContents()
     {
-        Debug.Log("zcount " + zones.Count);
         foreach (Wall wall in walls)
         {
             wall.Save();
@@ -90,8 +89,9 @@ public class Location
             var img = Encoding.UTF8.GetString(bytedata, read + 30, lenimg);
             var lenname = BitConverter.ToUInt16(bytedata, read + 30 + lenimg);
             var name = Encoding.UTF8.GetString(bytedata, read + 32 + lenimg, lenname);
-            read += (32 + lenimg + lenname);
-            Debug.Log($"location received read {read} id {id} x {x} y {y} scalex {scalex} scalez {scalez} posx {posx} posz {posz} lenimg {lenimg} img {img} lenname {lenname} name {name}");
+            var company_id = BitConverter.ToUInt32(bytedata, read + 32 + lenimg + lenname);
+            read += (36 + lenimg + lenname);
+            Debug.Log($"location received company_id {company_id} read {read} id {id} x {x} y {y} scalex {scalex} scalez {scalez} posx {posx} posz {posz} lenimg {lenimg} img {img} lenname {lenname} name {name}");
 
             var plane = UnityEngine.Object.Instantiate(Resources.Load("GameObjects/Plane", typeof(GameObject))) as GameObject;
            
@@ -112,7 +112,7 @@ public class Location
                 go.transform.SetParent(Location.transform);
             }          
 
-            player.locations[id] =new Location { id = id, name = name, texture_url = img, location = Location, plane = plane };
+            player.locations[id] =new Location { id = id, name = name, texture_url = img, location = Location, plane = plane, company_id = company_id };
             player.locations_index.Add(id);
             Debug.Log("locations count "+ player.locations.Count);
         }

+ 11 - 3
Assets/Scripts/Models/Zone.cs

@@ -8,7 +8,7 @@ public class Zone
 {
     public uint id { get; set; }
     public uint location_id { get; set; }
-    public string name { get; set; }
+    public string name = ""; 
     public float start_width { get; set; }
     public float start_height { get; set; }
     public float end_width { get; set; }
@@ -25,7 +25,11 @@ public class Zone
         list.AddRange(BitConverter.GetBytes(end_width));
         list.AddRange(BitConverter.GetBytes(end_height));
         list.AddRange(BitConverter.GetBytes(location_id));
-        Debug.Log($"zone save id {id}  x {start_width} z {start_height} x2 {end_width} z2 {end_height} location_id {location_id}");
+        var bname = System.Text.Encoding.UTF8.GetBytes(name);
+        var namelen = (ushort) bname.Length;
+        list.AddRange(BitConverter.GetBytes(namelen));
+        list.AddRange(bname);
+        Debug.Log($"zone save id {id}  x {start_width} z {start_height} x2 {end_width} z2 {end_height} location_id {location_id} namelen {namelen} name {name}");
 
         var tosend = Client.ConstructVariablePacket(53, list.ToArray());
         Client.SendEnqueue(tosend);
@@ -33,7 +37,6 @@ public class Zone
 
     public static void SaveAll(uint lid)
     {
-        Debug.Log("Zone count " + WallCreate.Zones.Count);
         if (WallCreate.Zones.Count > 0)
         {
             List<byte> list = new List<byte>();
@@ -45,6 +48,11 @@ public class Zone
                 list.AddRange(BitConverter.GetBytes(z.start_height));
                 list.AddRange(BitConverter.GetBytes(z.end_width));
                 list.AddRange(BitConverter.GetBytes(z.end_height));
+                list.AddRange(BitConverter.GetBytes(z.location_id));
+                var bname = System.Text.Encoding.UTF8.GetBytes(z.name);
+                var namelen = (ushort)bname.Length;
+                list.AddRange(BitConverter.GetBytes(namelen));
+                list.AddRange(bname);
                 Debug.Log($"zone save id {z.id}  x {z.start_width} z {z.start_height} x2 {z.end_width} z2 {z.end_height}");
             }