Beispiel #1
0
        public static LoadInformation Load(GameSaveData game, string filename)
        {
            var info = new LoadInformation();

            Instance.StartCoroutine(Instance.Load(info, game, filename));

            return(info);
        }
Beispiel #2
0
        public static LoadInformation New(string startingZone, string playerSpawn)
        {
            var filename = Guid.NewGuid().ToString();
            var game     = new GameSaveData
            {
                StartingZone = startingZone,
                PlayerSpawn  = new SpawnPoint {
                    Name = playerSpawn
                }
            };

            return(Load(game, filename));
        }
Beispiel #3
0
        private IEnumerator Load(LoadInformation info, GameSaveData game, string filename)
        {
            info.UpdateProgress(LoadState.ReadingData, 0.0f);

            var data = new SaveData();

            if (!string.IsNullOrEmpty(filename))
            {
                Read(info, filename, data);
            }

            if (info.State == LoadState.Error)
            {
                yield break;
            }

            game = game ?? data.Game;
            var worldData  = data.World ?? new WorldSaveData();
            var playerData = data.Player ?? new PlayerSaveData();

            info.UpdateProgress(LoadState.LoadingWorld, 0.1f);

            var mainLoader = string.IsNullOrEmpty(game.MainScene) ? null : SceneManager.LoadSceneAsync(game.MainScene);

            if (mainLoader == null)
            {
                info.SetError(string.Format(_missingMainSceneError, game.MainScene));
                yield break;
            }

            while (!mainLoader.isDone)
            {
                yield return(null);
            }

            if (WorldManager.Instance == null)
            {
                info.SetError(string.Format(_missingWorldManagerError, game.MainScene));
                yield break;
            }

            if (WorldManager.Instance.World == null)
            {
                info.SetError(string.Format(_missingWorldAssetError, game.MainScene));
                yield break;
            }

            if (InstructionManager.Instance == null)
            {
                info.SetError(string.Format(_missingCompositionManagerError, game.MainScene));
                yield break;
            }

            if (Player.Instance == null)
            {
                info.SetError(string.Format(_missingPlayerError, game.MainScene));
                yield break;
            }

            var camera = ComponentHelper.GetComponentInScene <Camera>(WorldManager.Instance.gameObject.scene.buildIndex, false);

            if (camera == null)
            {
                info.SetError(string.Format(_missingCameraError, game.MainScene));
                yield break;
            }

            var zone = WorldManager.Instance.World.GetZoneByName(game.StartingZone);

            if (zone == null)
            {
                info.SetError(string.Format(_invalidZoneError, game.StartingZone, game.MainScene));
                yield break;
            }

            info.UpdateProgress(LoadState.LoadingUi, 0.2f);

            yield return(WorldManager.Instance.LoadUi());

            info.UpdateProgress(LoadState.LoadingZones, 0.4f);

            WorldManager.Instance.Load(filename, worldData);
            Player.Instance.Load(playerData);

            WorldManager.Instance.TransitionZone(zone, game.PlayerSpawn, null);

            while (WorldManager.Instance.IsTransitioning)
            {
                yield return(null);
            }

            info.SetComplete();
        }