Ejemplo n.º 1
0
    public void SetState(GameState state)
    {
        switch (state)
        {
        case GameState.MainMenu:
            SceneManager.LoadScene("MainMenu", LoadSceneMode.Single);
            CamPan.DisableCamPan();
            transform.position    = Vector3.zero;
            transform.eulerAngles = new Vector3(transform.eulerAngles.x, 0, 0);
            ObjectPlacement.DisableObjectPlacement();
            ObjectPlacement.ClearPlacedObjects();
            IngameUI.ActivateElements(false, false, false, false);
            IngameUI.ClearList();
            MusicSource.clip = PlayMusic;
            MusicSource.Play();
            Time.timeScale = 1;
            break;

        case GameState.PlacingObjects:
            if (_currentState == GameState.Playing)
            {
                foreach (var barb in GameObject.FindObjectsOfType <Barbie>())
                {
                    Destroy(barb.gameObject);
                }
                ObjectPlacement.RestorePlacedObjectState();
                var currentActiveLevelScene = SceneManager.GetSceneByName(Levels[_currentLevelIndex].SceneName);
                SceneManager.LoadScene(Levels[_currentLevelIndex].SceneName, LoadSceneMode.Additive);
                ExecutionDelayer.Instance.ExecuteNextFrame(() => {
                    SceneManager.UnloadScene(currentActiveLevelScene);
                    SceneManager.SetActiveScene(SceneManager.GetSceneByName("DynamicObjects"));
                });
            }
            ObjectPlacement.EnableObjectPlacement();
            CamPan.EnableCamPan();
            IngameUI.ActivateElements(true, true, false, false);
            MusicSource.clip = PlacementMusic;
            MusicSource.Play();
            Time.timeScale = 0;
            break;

        case GameState.Playing:
            if (_currentState == GameState.PlacingObjects)
            {
                ObjectPlacement.SavePlacedObjectState();
            }
            ObjectPlacement.DisableObjectPlacement();
            CamPan.EnableCamPan();
            IngameUI.ActivateElements(false, true, false, false);
            MusicSource.clip = PlayMusic;
            MusicSource.Play();
            Time.timeScale = 1;
            break;

        case GameState.SuccessfulEnd:
            Time.timeScale = 0;
            if (_currentLevelIndex < Levels.Length - 1)
            {
                IngameUI.ActivateElements(false, false, true, false);
            }
            else
            {
                IngameUI.ActivateElements(false, false, false, true);
            }
            break;
        }
        _currentState = state;
    }