Exemplo n.º 1
0
    IEnumerator SceneLoader(SaveData data)
    {
        AsyncOperation scene = SceneManager.LoadSceneAsync(data.currentScene, LoadSceneMode.Single);

        while (!scene.isDone)
        {
            yield return(null);
        }
        Time.timeScale = 1;

        if (GameObject.FindObjectOfType <HouseAudioController>() != null)
        {
            GameObject.FindObjectOfType <HouseAudioController>().startPlaying = true;
        }

        Scene check = SceneManager.GetSceneByName(data.currentScene);

        if (check.IsValid())
        {
            player.Status = data.playerStatus;
            if (player.Status.Count > 0)
            {
                for (int i = 0; i < player.Status.Count(); i++)
                {
                    player.RestartTimers(player.Status[i], data.timers[i]);
                }
            }

            InputManager im = GameObject.FindObjectOfType <InputManager>();
            im.paused   = false;
            im.keybinds = data.keybinds;
            im.LoadKeybinds();

            Wardrobe wardrobe = GameObject.FindObjectOfType <Wardrobe>();
            if (wardrobe != null)
            {
                wardrobe.LoadCostume(data.currentCostume);
                wardrobe.Unlocked = data.unlockedCostumes;
            }

            rl.brewingIngredients = data.cauldronContents;
            rl.ingredientCount    = data.ingredientCount;
            for (int i = 0; i < data.ingredNames.Count; i++)
            {
                rl.knownAttributes.Add(data.ingredNames[i], data.knownAtts[i]);
            }

            Cauldron cauldron = GameObject.FindObjectOfType <Cauldron>();
            if (cauldron != null)
            {
                cauldron.UpdateText();
            }

            bm.Pot         = data.brewingPotion;
            bm.BrewTime    = data.brewingTime;
            bm.CurrentTime = data.currentTime;
            if (bm.Brewing == 1)
            {
                bm.Begin(bm.BrewTime, bm.Pot);
            }

            garden.plots.Clear();
            for (int i = 0; i < data.gardenPlots.Count; i++)
            {
                garden.plots.Add(data.gardenPlots[i], data.gardenData[i]);
            }
            List <string> keys = garden.plots.Keys.ToList();
            foreach (string s in keys)
            {
                if (SceneManager.GetActiveScene().name.Equals(garden.plots[s].plotScene))
                {
                    SpriteRenderer[] renderers = GameObject.Find(s).GetComponentsInChildren <SpriteRenderer>();
                    for (int i = 1; i < 4; i++)
                    {
                        renderers[i].sprite = Resources.LoadAll <Sprite>("Plants/" + garden.plots[s].type)[garden.plots[s].index];
                    }
                }
            }

            mc.Hour             = data.hour;
            mc.Minutes          = data.minute;
            mc.Days             = data.day;
            mc.DayPart          = data.dayPart;
            mc.CurrentMoonPhase = mc.Days % 6;
            mc.moonPhase.sprite = mc.moonCycleSprites[mc.CurrentMoonPhase];
            if (mc.Hour >= 18 || mc.Hour < 6)
            {
                mc.timeImage.sprite = mc.timeOfDay[3];
            }
            else if (mc.Hour >= 6 && mc.Hour < 10)
            {
                mc.timeImage.sprite = mc.timeOfDay[0];
            }
            else if (mc.Hour >= 10 && mc.Hour < 14)
            {
                mc.timeImage.sprite = mc.timeOfDay[1];
            }
            else if (mc.Hour >= 14 && mc.Hour < 18)
            {
                mc.timeImage.sprite = mc.timeOfDay[2];
            }

            npcs.npcData.Clear();
            for (int i = 0; i < data.npcNames.Count; i++)
            {
                npcs.npcData.Add(data.npcNames[i], data.npcInfo[i]);
            }

            npcs.npcQueue.Clear();
            for (int i = 0; i < data.schedules.Count; i++)
            {
                npcs.npcQueue.Add(data.schedules[i], data.scheduleNames[i]);
            }

            npcs.NPCQuestFlags.Clear();
            for (int i = 0; i < data.npcNames2.Count; i++)
            {
                npcs.NPCQuestFlags.Add(data.npcNames2[i], data.questFlags[i]);
            }

            npcs.CurrentMap = data.currentMap;
            npcs.LoadNPCS();
            npcs.gaveHint = data.gaveHint;
            GameObject.FindObjectOfType <ShrineManager>().endNature = data.endNature;
            GameObject.FindObjectOfType <ShrineManager>().endOrder  = data.endOrder;
            GameObject.FindObjectOfType <ShrineManager>().endSocial = data.endSocial;

            GameObject.FindObjectOfType <BookManager>().potionDiscovery.Clear();
            for (int i = 0; i < data.discoveredKeys.Count; i++)
            {
                GameObject.FindObjectOfType <BookManager>().potionDiscovery.Add(data.discoveredKeys[i], data.discoveredValues[i]);
            }

            gc.droppedItems = data.droppedItems;
            GameObject.Find("GarbageCollector").GetComponent <GarbageCollecter>().SpawnDropped();
            SceneManager.SetActiveScene(check);
            gameObject.SetActive(false);
        }
    }