Пример #1
0
        private IEnumerator LoadMainMenuRoutine()
        {
            CharacterPool.Clear();
            saveableObjects.Clear();
            AsyncOperation async;

            // Unload scenes
            for (int i = 0; i < SceneManager.sceneCount; i++)
            {
                if (SceneManager.GetSceneAt(i).buildIndex == 0)
                {
                    continue;
                }
                SceneManager.UnloadSceneAsync(SceneManager.GetSceneAt(i));
            }

            //Load scenes
            async = SceneManager.LoadSceneAsync("MainMenu", LoadSceneMode.Additive);
            while (!async.isDone)
            {
                yield return(null);
            }

            SceneManager.SetActiveScene(SceneManager.GetSceneByName("MainMenu"));
        }
Пример #2
0
        private IEnumerator LoadSaveRoutine()
        {
            CharacterPool.Clear();
            newGame = false;

            // Remove all non-global objects from the list. They will be destroyed
            var toRemove = (
                from obj in saveableObjects
                where !obj.Value.global
                select obj.Key).ToList();

            foreach (var key in toRemove)
            {
                saveableObjects.Remove(key);
            }


            yield return(StartCoroutine(LoadGameRoutine()));

            lastLoadTime = Time.time;
            yield return(null);            // SaveableObjects will re-register themselves during this frame

            string allData = File.ReadAllText(Application.persistentDataPath + "/Save.json");

            allData = allData.Replace("\n", "");
            string[] data = allData.Split(';');

            for (int i = 0; i < data.Length; i++)
            {
                if (!string.IsNullOrEmpty(data[i]))
                {
                    try
                    {
                        saveableObjects[data[i]].Load(data[++i]);
                    }
                    catch (KeyNotFoundException e)
                    {
                        Debug.LogWarning("Savegame data did not find object: " + data[i]);
                    }
                }
            }

            yield return(null);
        }