Exemplo n.º 1
0
        public static void StartALevel()
        {
            Debug.Log("StartALevel called for " + CurrentLevel.gameObject.name);

            //check that Lobby Level is currently running, if so transition to a new Level
            if (CurrentLevel == Level.LobbyLevel)
            {
                Level newToLoad = (_levels.ContainsKey(PlayerUser.LastLevelCompleted + 1))
                    ? _levels[PlayerUser.LastLevelCompleted + 1]
                    : Level.LobbyLevel; //fallback is lobby level

                UnitMgr.ClearUnitsData();
                Level.LobbyLevel.gameObject.SetActive(false);
                CurrentLevel = newToLoad;
                newToLoad.gameObject.SetActive(true);
                //TODO: at some point make a fancier scheme for difficulty selection so that holes greater or less than town count!
                newToLoad.Reset(PlayerUser.LastLevelCompleted + 1, PlayerUser.LastLevelCompleted + 1);
                PlayerUser.ResetPlayerPosition();
                PlayerUser.ResetLevelStartingResources();
                UnitMgr.ResetWaveLogic();

                string text = $"Current Level Obtained: {PlayerUser.LastLevelCompleted + 1}";
                DisplayInfoDesktop.SetDisplayInfo(text);
            }
            else
            {
                Debug.LogWarning("LevelMgr.StartALevel() called from outside the Lobby!");
            }

            MenuInGameObject?.GetComponent <MenuInGame>()?.UpdateNow();
            StatusInGameComponent?.Show(true);
            if (CurrentLevel == Level.LobbyLevel) //if new level not found and the lobby reloaded
            {
                StatusInGameComponent?.SetAlert("Level " + (PlayerUser.LastLevelCompleted + 1) + " not found, back to Lobby",
                                                Color.red);
            }
            else
            {
                StatusInGameComponent?.SetAlert("Level " + (PlayerUser.LastLevelCompleted + 1) + " Loaded",
                                                Color.white);
            }
        }