private static LoadInformation Load(GameData game, WorldData world, PlayerData player, string filename) { var info = new LoadInformation(); Instance.StartCoroutine(Instance.Load(info, game, world, player, filename)); return(info); }
private static IEnumerator Read(LoadInformation info, string filename, SaveData data) { var thread = new Thread(DoRead); var transfer = new ThreadData { Failed = false, Contents = data, Path = filename, Filename = filename }; thread.Start(transfer); while (thread.IsAlive) { yield return(null); } if (transfer.Failed) { info.SetError(transfer.Error); } }
private IEnumerator Load(LoadInformation info, GameData game, WorldData world, PlayerData player, string filename) { if (world == null) { info.UpdateProgress(LoadState.ReadingData, 0.0f); var data = new SaveData(); if (!string.IsNullOrEmpty(filename)) { yield return(StartCoroutine(Read(info, filename, data))); } if (info.State == LoadState.Error) { yield break; } game = game ?? data.Game; world = data.World ?? new WorldData(); player = data.Player ?? new PlayerData(); } info.UpdateProgress(LoadState.LoadingWorld, 0.1f); var mainLoader = SceneManager.LoadSceneAsync(game.MainScene); if (mainLoader == null) { info.SetError(string.Format("the scene {0} could not be loaded", game.MainScene)); yield break; } while (!mainLoader.isDone) { yield return(null); } if (WorldManager.Instance == null) { SceneManager.UnloadSceneAsync(game.MainScene); info.SetError(string.Format("the scene {0} does not contain a WorldManager", game.MainScene)); yield break; } if (WorldManager.Instance.World == null) { SceneManager.UnloadSceneAsync(game.MainScene); info.SetError(string.Format("the WorldManager in scene {0} does not have a World set", game.MainScene)); yield break; } if (Player.Instance == null) { SceneManager.UnloadSceneAsync(game.MainScene); info.SetError(string.Format("the scene {0} does not contain a Player", game.MainScene)); yield break; } var zone = WorldManager.Instance.World.GetZone(game.StartingZone); if (zone == null) { SceneManager.UnloadSceneAsync(game.MainScene); info.SetError(string.Format("the zone {0} does not exist on the world in scene {1}", game.StartingZone, game.MainScene)); yield break; } WorldManager.Instance.SaveFilename = filename; WorldManager.Instance.LoadWorld(world); Player.Instance.Initialize(player); var zoneData = WorldManager.Instance.Zones[zone.Scene.Index]; info.UpdateProgress(LoadState.LoadingZones, 0.2f); var zoneLoader = WorldManager.Instance.ChangeZone(zoneData, true); while (!zoneLoader.IsDone) { yield return(null); } var spawn = game.PlayerSpawn.Layer == CollisionLayer.None ? zoneData.GetSpawnPoint(game.PlayerSpawn.Name ?? "") : game.PlayerSpawn; Player.Instance.Mover.WarpToPosition(spawn.Position, spawn.Direction, spawn.Layer); info.UpdateProgress(LoadState.LoadingUi, 0.9f); yield return(StartCoroutine(LoadUis(WorldManager.Instance.World.UIScenes))); info.SetComplete(); }