Ejemplo n.º 1
0
        public void Load()
        {
            IsPaused = true;

            var snapshot = SaveUtils.Load();

            if (snapshot != null)
            {
                _isLoading = true;

                Gold  = snapshot.Gold;
                Lives = snapshot.Lives;
                UpdateGold(0);
                UpdateLives(0);

                if (IsWaveActive)
                {
                    var wave = _waves[_currWave % _waves.Length];
                    wave.OnCreateEnemy -= HandleCreateEnemy;
                    wave.OnWaveCleared -= HandleWaveCleared;
                    wave.IsActive       = false;
                    WavePreview.UpdateWave(null, -1);

                    foreach (Transform enemy in EnemiesParent)
                    {
                        Destroy(enemy.gameObject);
                    }
                }
                _currWave = snapshot.Wave;
                ResetWaveStatus();

                foreach (var tower in _activeTowers.Keys)
                {
                    Destroy(tower);
                }
                foreach (var tower in snapshot.Towers)
                {
                    RegisterTower(TowerBase.FromSnapshot(tower));
                }

                Items.Clear();
                Inventory.ResetItems();
                foreach (var item in snapshot.Items)
                {
                    AddItem(ItemBase.FromSnapshot(item));
                }

                TowerDetails.UpdateTarget(null, false);
                EnemyDetails.UpdateTarget(null, false);

                _snapshot  = snapshot;
                _isLoading = false;
            }

            IsPaused = false;
        }