public int SaveMapObjects(string name) { print("save map objects"); MapInfo mapInfo = new MapInfo(); mapInfo.name = name; mapInfo.author = player.name; mapInfo.dateTime = DateTime.Now.ToString(); if (isOfficial) { mapInfoJson.officialMaps.Add(mapInfo); } else { mapInfoJson.customMaps.Add(mapInfo); } string json = JsonUtility.ToJson(mapInfoJson, true); File.WriteAllText(Application.persistentDataPath + "/General/MapsInfo.json", json); MapObjInfo mapObjInfo = new MapObjInfo(); Transform t; t = ball.transform; mapObjInfo.ballInfo = new TransformProperty(t.position, t.localEulerAngles, t.localScale); t = destination.transform; mapObjInfo.destInfo = new TransformProperty(t.position, t.localEulerAngles, t.localScale); mapObjInfo.mapInfo = mapInfo; mapObjInfo.wallInfo = new List <TransformProperty>(); for (int i = 0; i < walls.transform.childCount; i++) { t = walls.transform.GetChild(i); mapObjInfo.wallInfo.Add(new TransformProperty(t.position, t.localEulerAngles, t.localScale)); } mapObjInfo.fieldNumList = new List <int>(); mapObjInfo.fieldTypeList = new List <string>(); foreach (KeyValuePair <string, int> kv in _fieldMaxDic) { mapObjInfo.fieldTypeList.Add(kv.Key); mapObjInfo.fieldNumList.Add(myUI.FieldNumLimitGet(kv.Key)); } BinaryFormatter bf = new BinaryFormatter(); string dir = GetMapDir() + "/Levels/" + name + "_" + player.name; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } FileStream file = File.Open(dir + "/general", FileMode.OpenOrCreate); bf.Serialize(file, mapObjInfo); file.Close(); //Transform[] fieldsTrans = mapFields.transform.GetComponentsInChildren<Transform>(); dir = dir + "/fields"; MyUtils.EmptyOrCreateDir(dir); foreach (var kv in mapFieldDic) { for (int i = 0; i < kv.Value.Count; i++) { file = File.Open(dir + '/' + kv.Key + i, FileMode.OpenOrCreate); FieldInfo info = kv.Value[i].GetComponent <Field>().Save(); bf.Serialize(file, info); file.Close(); } } return(-1); }