UnityGameProjectsCode / Rise2Point0Game / Managers / GameManager.cs
GameManager.cs
Raw
using UnityEngine;

public class GameManager : MonoBehaviour
{
    private GameObject playerObject;
    private ApplyForceToPlayer applyForce;
    private ApplyForceTouch applyForceTouch;
    private ApplyForceController applyForceController;
    private LevelGenerator levelGen;
    private ScoreManager scoreMgr;
    private DeathWall dWall;
    private SessionTimer sessionT;
    private UnlockSystem uSys;
    private SoundManager soundMgr;
    private AchievementSystem achSys;
    private InputManager inputMgr;

    private void Awake()
    {
        ObjectManager.SetReferences();
        GUIManager.SetReferences();
        SaveManager.SetReferences();
        scoreMgr = GetComponent<ScoreManager>();
        levelGen = GetComponent<LevelGenerator>();
        sessionT = GetComponent<SessionTimer>();
        uSys = GetComponent<UnlockSystem>();
        soundMgr = GetComponent<SoundManager>();
        dWall = ObjectManager.GetObject(2).GetComponent<DeathWall>();
        achSys = GetComponent<AchievementSystem>();
        inputMgr = GetComponent<InputManager>();
    }

    private void Start()
    {
        playerObject = ObjectManager.GetObject(0);
        applyForce = ObjectManager.GetObject(3).GetComponent<ApplyForceToPlayer>();
        applyForceTouch = ObjectManager.GetObject(3).GetComponent<ApplyForceTouch>();
        applyForceController = ObjectManager.GetObject(3).GetComponent<ApplyForceController>();
        playerObject.SetActive(false);
        SaveManager.SetupScoreboard();
        SaveManager.SetupMusicBoard();
        SaveManager.SetupAchievementList();
        GUIManager.PlayCameraMenuAnim();
        ObjectManager.SetInteractionSurfaceState();
    }

    public void OpenEscapeMenu()
    {
        if (!GUIManager.GetDeathCanvasState())
        {
            GUIManager.OpenPauseCanvas();
            GUIManager.SetTimeScale(0);
            ObjectManager.SetInteractionSurfaceState();
        }
    }

    public void CloseEscapeMenu()
    {
        GUIManager.ClosePauseCanvas();
        GUIManager.SetTimeScale(1);
        ObjectManager.SetInteractionSurfaceState();
    }

    public void OnPlayerDeath(int killerID) //player makes contact with obstacle
    {
        GUIManager.OnPlayerDeath(killerID);
        playerObject.GetComponent<PlayerDeathEffects>().CreateDeathParticles();
        playerObject.GetComponent<PlayerDeathEffects>().CreateAnimatedPlayerObject();
        playerObject.SetActive(false);
        //SetPlayerColor();
        scoreMgr.SetDeathPanelInfo();
        ObjectManager.SetInteractionSurfaceState();
        sessionT.PauseTimer();
        soundMgr.PlayDeathSound();
    }

    public void OnGameStart() //called via start button
    {
        playerObject.SetActive(true);
        GUIManager.OnLeavingMainMenu();
        ObjectManager.SetInteractionSurfaceState();
        inputMgr.UpdateTutorialInputTexts();
        playerObject.GetComponent<PlayerTrailParticles>().RestartParticles();
    }

    public void OnGameRestart() //called from death menu with the restart button
    {
        GUIManager.OnGameRestart();
        playerObject.transform.position = new Vector2(0, -3.5f);
        playerObject.SetActive(true);
        playerObject.GetComponent<PlayerInvulnAbility>().DisableInvulnAbility();
        levelGen.ResetLevel();
        dWall.ResetPosition();
        scoreMgr.AddScoreToBoard();
        scoreMgr.ResetScore();
        achSys.OnRunReset();
        inputMgr.UpdateTutorialInputTexts();
        playerObject.GetComponent<PlayerTrailParticles>().RestartParticles();

        if (applyForce.enabled)
            applyForce.ResetForceMultiplier();

        if (applyForceTouch.enabled)
            applyForceTouch.ResetForceMultiplier();

        if (applyForceController.enabled)
            applyForceController.ResetForceMultiplier();


        sessionT.UnPauseTimer();
        uSys.ActivateUnlocksButton();
        ObjectManager.SetInteractionSurfaceState();
    }

    public void OnPauseRestart()
    {
        GUIManager.OnGameRestart();
        playerObject.transform.position = new Vector2(0, -3.5f);
        playerObject.SetActive(true);
        playerObject.GetComponent<PlayerInvulnAbility>().DisableInvulnAbility();
        levelGen.ResetLevel();
        dWall.ResetPosition();
        scoreMgr.ResetScore();
        achSys.OnRunReset();
        inputMgr.UpdateTutorialInputTexts();
        playerObject.GetComponent<PlayerTrailParticles>().RestartParticles();

        if (applyForce.enabled)
            applyForce.ResetForceMultiplier();

        if (applyForceTouch.enabled)
            applyForceTouch.ResetForceMultiplier();

        if (applyForceController.enabled)
            applyForceController.ResetForceMultiplier();

        uSys.ActivateUnlocksButton();
        ObjectManager.SetInteractionSurfaceState();
    }

    public void OnReturnToMainMenu()
    {
        GUIManager.OnMainMenuReturn();
        playerObject.transform.position = new Vector2(0, -3.5f);
        playerObject.SetActive(false);

        playerObject.GetComponent<PlayerInvulnAbility>().DisableInvulnAbility();
        levelGen.ResetLevel();
        levelGen.BuildLevel();
        dWall.ResetPosition();
        scoreMgr.ResetScore();
        uSys.ActivateUnlocksButton();
        achSys.OnRunReset();

        if (applyForce.enabled)
            applyForce.ResetForceMultiplier();

        if (applyForceTouch.enabled)
            applyForceTouch.ResetForceMultiplier();

        if (applyForceController.enabled)
            applyForceController.ResetForceMultiplier();

        ObjectManager.SetInteractionSurfaceState();
    }
}