public static void CreateEmptyProfile(string name) { List <int> stats = new List <int>(); stats.Add(1000); //credits stats.Add(0); // fame List <ItemObj> items = new List <ItemObj>(); Dictionary <string, int> ammos = new Dictionary <string, int>(); List <string> PlayerShipsList = new List <string>(); ObjToSave obj = new ObjToSave(name, 0, stats, items, ammos, PlayerShipsList, DefaultShip(), DateTime.Now, true, true, true, true, false); JsonData jsonData = JsonMapper.ToJson(obj); File.WriteAllText(Application.persistentDataPath + "/" + name + ".json", jsonData.ToString()); Debug.Log("Profile Save - " + "Name: " + obj.ProfileName + " path: " + Application.persistentDataPath + "/" + name + ".json"); }
public static void SaveProfile(string name, Ship ship) { bool needcreatedefaulship = false; JsonData jsonData; PlayerShipObj shiptosave; // заполнение профиля данными bool isTutorialPart1 = ContextManagerGamePro.Instance().Profile.isTutorialPart1; bool isTutorialPart2 = ContextManagerGamePro.Instance().Profile.isTutorialPart2; bool isTutorialPart3 = ContextManagerGamePro.Instance().Profile.isTutorialPart3; bool isCheat = ContextManagerGamePro.Instance().Profile.isCheat; List <int> stats = new List <int>(); stats.Add(ContextManagerGamePro.Instance().Profile.credits); stats.Add(ContextManagerGamePro.Instance().Profile.fame); List <ItemObj> items = new List <ItemObj>(); GameObject inventory = GameObject.Find("StationUI").GetComponent <StationUI>().stationinventory.transform.GetChild(0).transform.GetChild(0).gameObject; if (inventory.transform.childCount > 0) { for (int i = 0; i < inventory.transform.childCount; i++) { items.Add(new ItemObj(inventory.transform.GetChild(i).GetComponent <Item>().ItemId, inventory.transform.GetChild(i).GetComponent <Item>().stackvalue)); } } Dictionary <string, int> ammos = new Dictionary <string, int>(); List <string> PlayerShipsList = new List <string>(); if (ContextManagerGamePro.Instance().Profile.playershipsIdlist.Count > 0) { PlayerShipsList.AddRange(ContextManagerGamePro.Instance().Profile.playershipsIdlist); } int _day = ContextManagerGamePro.Instance().Profile.Day; //заполнение данных корабля List <ItemInSlot> itemsinship = new List <ItemInSlot>(); if (ContextManagerGamePro.Instance().playership != null) { foreach (ComponentSlot slot in ship.ComponentController.Slots) { if (!slot.containitem) { continue; } if (slot.SlotType == ComponentSlot.slotType.Weapon) { if (slot.weapon) { itemsinship.Add(new ItemInSlot(slot.weapon.Id, slot.slotnumber)); } } else { if (slot.component) { itemsinship.Add(new ItemInSlot(slot.component.component_name, slot.slotnumber)); } } } shiptosave = new PlayerShipObj(ship.itemID, itemsinship); } else { needcreatedefaulship = true; shiptosave = DefaultShip(); } ObjToSave obj = new ObjToSave(name, _day, stats, items, ammos, PlayerShipsList, shiptosave, DateTime.Now, false, isTutorialPart1, isTutorialPart2, isTutorialPart3, isCheat); jsonData = JsonMapper.ToJson(obj); File.WriteAllText(Application.persistentDataPath + "/" + name + ".json", jsonData.ToString()); if (needcreatedefaulship) { Profile profile = ContextManagerGamePro.Instance().Profile; JsonData data = DataLoad(profile); CreateShipFromFile(); } Debug.Log("Profile Save - " + "Name: " + obj.ProfileName + " path: " + Application.persistentDataPath + "/" + name + ".json"); }