public void DeSerialize(Dictionary<string, object> dic) { pointList.Clear(); wallList.Clear(); productDataList.Clear(); roomList.Clear(); productList = new List<Product>(); preScanDatas.Clear(); foreach (string key in dic.Keys) { switch (key) { case "pointList": { object obj = MyJsonTool.getValue(dic, key); List<object> list = obj as List<object>; for (int i = 0; i < list.Count; i++) { Point point = new Point(); point.DeSerialize(list[i] as Dictionary<string, object>); pointList.Add(point); } } break; case "wallList": { object obj = MyJsonTool.getValue(dic, key); List<object> list = obj as List<object>; for (int i = 0; i < list.Count; i++) { WallData wall = new WallData(); wall.DeSerialize(list[i] as Dictionary<string, object>); wallList.Add(wall); } } break; case "productDataList": { object obj = MyJsonTool.getValue(dic, key); List<object> list = obj as List<object>; for (int i = 0; i < list.Count; i++) { ProductData productdata = new ProductData(); productdata.DeSerialize(list[i] as Dictionary<string, object>); productDataList.Add(productdata); } } break; case "roomList": { object obj = MyJsonTool.getValue(dic, key); List<object> list = obj as List<object>; for (int i = 0; i < list.Count; i++) { RoomData room = new RoomData(); room.DeSerialize(list[i] as Dictionary<string, object>); roomList.Add(room); } } break; case "productList": { object obj = MyJsonTool.getValue(dic, key); if (obj == null) { productList = null; break; } List<object> list = obj as List<object>; for (int i = 0; i < list.Count; i++) { Product product = new Product(); if (isOld) { JsonProduct jsonData = new JsonProduct(); jsonData.DeSerialize(list[i] as Dictionary<string, object>); jsonData.WriteToData(product); } else { product.DeSerialize(list[i] as Dictionary<string, object>); } productList.Add(product); //if(product) } } break; case "defaultsettings": { object obj = MyJsonTool.getValue(dic, key); defaultsettings.DeSerialize(obj as Dictionary<string, object>); } break; case "maxAngleRooms": { object obj = MyJsonTool.getValue(dic, key); List<object> list = obj as List<object>; for (int i = 0; i < list.Count; i++) { RoomData room = new RoomData(); room.DeSerialize(list[i] as Dictionary<string, object>); maxAngleRooms.Add(room); } } break; case "preScanDatas": { object obj = MyJsonTool.getValue(dic, key); List<object> list = obj as List<object>; for (int i = 0; i < list.Count; i++) { PreScanData prescan = new PreScanData(); prescan.DeSerialize(list[i] as Dictionary<string, object>); preScanDatas.Add(prescan); } } break; default: break; } } //恢复关联 Dictionary<int, Point> pointDic = new Dictionary<int, Point>(); Dictionary<int, WallData> wallDic = new Dictionary<int, WallData>(); Dictionary<int, WallSideData> tempSideDic = new Dictionary<int, WallSideData>(); for (int i = 0; i < pointList.Count; i++) { pointDic.Add(pointList[i].guid, pointList[i]); } for (int i = 0; i < wallList.Count; i++) { wallDic.Add(wallList[i].guid, wallList[i]); WallData wall = wallList[i]; if (pointDic.ContainsKey(wall.point1Guid) == false) { Debug.LogError("wall.point1Guid = "+ wall.point1Guid + "对应的Point不存在"); } else { wall.point1 = pointDic[wall.point1Guid]; } if (pointDic.ContainsKey(wall.point2Guid) == false) { Debug.LogError("wall.point2Guid = " + wall.point2Guid + "对应的Point不存在"); } else { wall.point2 = pointDic[wall.point2Guid]; } wall.point1To2Data.targetWall = wall; wall.point2To1Data.targetWall = wall; tempSideDic.Add(wall.point1To2Data.guid, wall.point1To2Data); tempSideDic.Add(wall.point2To1Data.guid, wall.point2To1Data); } for (int i = 0; i < productDataList.Count; i++) { ProductData productData = productDataList[i]; if (productData.targetWallGuid != -1) { if (wallDic.ContainsKey(productData.targetWallGuid)) { productData.targetWall = wallDic[productData.targetWallGuid]; } else { Debug.LogError("productData.targetWallGuid = "+ productData.targetWallGuid + "对应的Wall不存在"); productData.targetWall = null; } } else { productData.targetWall = null; } } for (int i = 0; i < roomList.Count; i++) { RoomData room = roomList[i]; for (int k = 0; k < room.sideListGuids.Count; k++) { if (tempSideDic.ContainsKey(room.sideListGuids[k]) == false) { Debug.LogError("room.sideListGuids[k] = " + room.sideListGuids[k] + "对应的WallSideData不存在"); continue; } room.sideList.Add(tempSideDic[room.sideListGuids[k]]); } room.pointList = new List<Point>(); for (int k = 0; k < room.pointListGuids.Count; k++) { if (pointDic.ContainsKey(room.pointListGuids[k]) == false) { Debug.LogError("room.pointListGuids[k] = " + room.pointListGuids[k] + "对应的Point不存在"); continue; } room.pointList.Add(pointDic[room.pointListGuids[k]]); } } for (int i = 0; i < maxAngleRooms.Count; i++) { RoomData room = maxAngleRooms[i]; for (int k = 0; k < room.sideListGuids.Count; k++) { if (tempSideDic.ContainsKey(room.sideListGuids[k]) == false) { Debug.LogError("room.sideListGuids[k] = " + room.sideListGuids[k] + "对应的WallSideData不存在"); continue; } room.sideList.Add(tempSideDic[room.sideListGuids[k]]); } room.pointList = new List<Point>(); for (int k = 0; k < room.pointListGuids.Count; k++) { if (pointDic.ContainsKey(room.pointListGuids[k]) == false) { Debug.LogError("room.pointListGuids[k] = " + room.pointListGuids[k] + "对应的Point不存在"); continue; } room.pointList.Add(pointDic[room.pointListGuids[k]]); } } MainPageUIData.Instance.productDic.Clear(); MainPageUIData.Instance.GoodsDic.Clear(); if (productList != null) { for (int i = 0; i < productList.Count; i++) { MainPageUIData.Instance.AddProduct(productList[i]); } } }