Exemple #1
0
 public ObjToSave(string profilename, int Day, List <int> stats, List <ItemObj> items, Dictionary <string, int> ammos, List <string> PlayerShipsList, PlayerShipObj playership, DateTime savetime, bool isNew, bool isTutorialPart1, bool isTutorialPart2, bool isTutorialPart3, bool isCheat)
 {
     this.ProfileName     = profilename;
     this.isNewProfile    = isNew;
     this.isTutorialPart1 = isTutorialPart1;
     this.isTutorialPart2 = isTutorialPart2;
     this.isTutorialPart3 = isTutorialPart3;
     this.isCheat         = isCheat;
     this.ProfileStats    = stats;
     this.Items           = items;
     this.Ammos           = ammos;
     this.PlayerShipsList = PlayerShipsList;
     this.PlayerShip      = playership;
     this.SaveDate        = savetime;
     this.Day             = Day;
 }
Exemple #2
0
    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");
    }