Exemplo n.º 1
0
        public async Task LoadSavedGameAsync(string slotName)
        {
            if (this.loading)
            {
                return;
            }

            this.loading = true;

            this.BackgroundImage.Value.Hide();
            await this.BlackScreen.Value.ShowAsync();

            var gameState = await this.Storage.Value.LoadAsync(slotName);

            var level     = Level.AllById[gameState.LevelId];
            var levelName = Texts.GetLevelText(level.Name);

            this.LoadingText.Value.DisplayNewText(levelName);
            await this.LoadGameStateAsync(gameState);

            await Task.Delay(2000);

            this.LoadingText.Value.HideText();
            await this.BlackScreen.Value.HideAsync();

            this.loading = false;
        }
Exemplo n.º 2
0
        public async void SwitchLevelAsync(Level level, string locationName)
        {
            await this.BlackScreen.Value.ShowAsync();

            this.LoadingText.Value.DisplayNewText(Texts.GetLevelText(level.Name));

            var time           = DateTime.Now.ToTeamZDateTime();
            var beforeAutoSave = $"Switching to {level.Name} {time}";

            var gameState = this.GetState();

            await this.SaveAsync(gameState, beforeAutoSave);

            gameState.LevelId = level.Id;
            var mainCharacters = gameState.GameObjectsStates.
                                 Where(o => o.MonoBehaviousStates.OfType <CharacterState>().Any());

            foreach (var character in mainCharacters)
            {
                character.Entity.LevelId = level.Id;
            }

            Time.timeScale = 0;

            await this.LoadGameStateAsync(gameState);

            // TODO: Think about how set position before scene loading.
            var locationPosition = GameObject.FindObjectsOfType <Location>().
                                   First(o => o.name == locationName).transform.position;

            foreach (var character in this.EntitiesStorage.Value.Entities.Values.Where(o => o.GetComponent <ICharacter>() != null))
            {
                character.transform.localPosition = locationPosition;
            }

            gameState = this.GetState();
            var afterAutoSave = $"Switched to {level.Name} {time}";

            this.VisitedLevels.Add(level.Id);
            await this.SaveAsync(gameState, afterAutoSave);

            Time.timeScale = 1;

            await Task.Delay(2000);

            this.LoadingText.Value.HideText();
            this.Loaded.OnNext(Unit.Default);
            await this.BlackScreen.Value.HideAsync();
        }