Main Menu

An example implementation that you can use directly or as a starting point. You can refer to the demo game samples to see it in action.

Base class with buttons:

  • Continue

  • Load

  • New Game

  • Settings

  • Credits

  • Quit

The Continue and Load buttons are enabled or disabled automatically based on the presence of a save file, in coordination with the GameSaveManager.

Example Implementation

using CupkekGames.Core;
using UnityEngine;

public class MainMenuViewExample : MainMenuView<GameSaveDataExample>
{
    [Header("Prefab Keys")]
    [SerializeField] string _settingsMenuKey = "Settings";
    [SerializeField] string _loadMenuKey = "SaveLoad";
    [SerializeField] string _gameScene = "Base";
    
    protected override GameSaveManager<GameSaveDataExample> GetSaveManager()
    {
        return (GameSaveManagerExample)GameSaveManagerExample.Instance;
    }
    protected override void OnButtonContinueClicked()
    {
        GameSaveManager.CurrentSave.Data = LastSave;

        SceneLoader.Instance.LoadScene(_gameScene, SceneTransitionManager.Instance.Transitions.Dictionary["Fade"]);
    }
    protected override void OnButtonLoadClicked()
    {
        UIPrefabLoaderString.Instance.Instantiate(_loadMenuKey);
    }

    protected override void OnButtonNewGameClicked()
    {
        _buttonNewGame.SetEnabled(false);

        GameSaveManager.CurrentSave.Data = new GameSaveDataExample();

        SceneLoader.Instance.LoadScene(_gameScene, SceneTransitionManager.Instance.Transitions.Dictionary["Fade"]);
    }

    protected override void OnButtonCreditsClicked()
    {
        Debug.Log("Credits");
    }

    protected override void OnButtonSettingsClicked()
    {
        UIPrefabLoaderString.Instance.Instantiate(_settingsMenuKey);
    }
}

Last updated