Esempio n. 1
0
    public void LoadGame()
    {
        List <CageSaveData> cages = JsonConvert.DeserializeObject <List <CageSaveData> >(PlayerPrefs.GetString("save"));

        DataManager.Money = (PlayerPrefs.GetInt("money", 0));
        for (int i = 0; i < cages.Count; i++)
        {
            Cage tmp = CageFactory.GetNewCage(cages[i].biome, i, true);
            tmp.Name  = cages[i].Name;
            tmp.stage = cages[i].stage;
            GameManager.Ins.cages.Add(tmp);
            GameManager.Ins.ToCage(i);
            foreach (var item in cages[i].items)
            {
                if (item.type == NeedType.Food)
                {
                    Feeder f = Instantiate(feeders[(int)item.food], tmp.transform).GetComponent <Feeder>();
                    f.transform.localPosition = item.localPos;
                    f.capacity = item.capacity;
                    f.Place();
                }
                else
                {
                    SpecialItem s = Instantiate(specials[(int)item.special], tmp.transform).GetComponent <SpecialItem>();
                    s.transform.localPosition = item.localPos;
                    s.Place();
                }
            }
            foreach (var animal in cages[i].animals)
            {
                Animal a = AnimalFactory.NewAnimalOfKind(animal.kind, tmp.transform, true);
                a.data.name           = animal.data.name;
                a.data.adult          = animal.data.adult;
                a.data.age            = animal.data.age;
                a.data.male           = animal.data.male;
                a.data.pregnant       = animal.data.pregnant;
                a.data.pregnancy      = animal.data.pregnancy;
                a.data.sexualActivity = animal.data.sexualActivity;
                a.data.happiness      = animal.data.happiness;
                a.data.foods          = animal.data.foods;
                a.data.specials       = animal.data.specials;
                a.transform.position  = tmp.GetFreeTileInGrid();
                a.status.RecalculateHappiness();
            }

            if (tmp.animals.Count > 0)
            {
                GameManager.Ins.cageIcons.GetChild(i).GetComponent <Image>().sprite = Resources.Load <Sprite>($"Animals/{tmp.animals[0].stats.kind}/CageIcon");
            }
        }
        Technet99m.Clock.deltaActualized += SaveGame;
        GameManager.Ins.ToCage(0);
        StartCoroutine(CalculateTimeChanges());
    }