Menu's - Team-Swamp/IceBites GitHub Wiki

Overview

The UI scripts I made serve 2 purposes. The settings script's purpose is loading, saving and creating the settings. The MenuSwitcher's purpose is switching from one menu to another without too much hassle.

Usage

Flowchart

---
title: Settings Menu
---

graph TD;
    Start((Start)) --> LoadSettings(Load Settings);
    LoadSettings -->|If mobile| LoadMobileSettings(Load Mobile Settings);
    LoadSettings --> PopulateResolutions(Populate Resolutions);
    LoadSettings --> SetHighestQuality(Set Highest Quality);
    LoadSettings --> SetVolume(Set Volume);
    LoadSettings --> SetQuality(Set Quality);
    LoadSettings --> SetFullscreen(Set Fullscreen);
    LoadSettings -->|If mobile| SetRatio(Set Ratio);
    LoadSettings -->|If mobile| todo(Fix Error);
    LoadSettings --> SetResolution(Set Resolution);
    LoadMobileSettings --> SetHighestQuality;
    LoadMobileSettings --> DeleteAll(Delete All PlayerPrefs);
    LoadMobileSettings --> HideResolutionDropdown(Hide Resolution Dropdown);
    LoadMobileSettings --> HideFullScreen(Hide FullScreen);
    PopulateResolutions --> GetResolutions(Get Screen Resolutions);
    GetResolutions --> AddOptions(Add Options to Resolutions Dropdown);
    AddOptions --> SetDefaultValue(Set Default Value of Resolutions Dropdown);
    SetVolume --> SetAudioVolume(Set Audio Volume);
    SetQuality --> SetGraphicsQuality(Set Graphics Quality);
    SetFullscreen --> SetScreenMode(Set Screen Mode);
    SetResolution --> LoadSettings;

---
title: Switch Menus
---
graph TD;
    Start((Start)) --> TogglePauseGame(Toggle Pause Game);
    TogglePauseGame -->|If paused| ResumeGame(Resume Game);
    TogglePauseGame -->|If not paused| PauseGame(Pause Game);
    PauseGame --> PausingEvent(Pausing Event);
    PausingEvent --> HideMenu(Hide Menu);
    PausingEvent --> ActivateMenu(Activate Menu);

    QuitGame --> SetAndLoadAsyncScene(Set And Load Async Scene);
    SetAndLoadAsyncScene --> Quit(Quit);

Settings

Methods Return Description
+LoadSettings() void LoadSettings is a function that will check if there are any settings that have been changed from it's default value. If there weren't any changes it will load the default values. If there have been changes it will load those settings.
+ApplySettings() void Apply settings is linked to the apply button. It saves a boolean into a playerpref which says that settings have been changed from it's default value
+SetVolume(float) void This changes the volume and saves the value of the float into a playerpref. This is hooked up to a slider.
+SetQuality(int) void This changes the quality of the game to the int that is selected. This is hooked up to a dropdown. The int being the value of the dropdown.
+SetFullscreen(bool) void This sets the game to either fullscreen, or windowed. This is hooked up to a button
+SetResolution(int) void This changes the Resolution of the game to the int that is selected. The int is the index of the resolution dropdown
-SetHighestQuality() void This sets the game to the highest quality
-GetDefaultResolution() void This gets the highest possible resolution it can get and then sets that as its default
-PopulateResolutions() void This will fill the Resolution Dropdown with all the possible Resolutions it can find that are on the device.

Menu Switcher

Method Return Description
+HideMenu(Gameobject) void This will hide a specific Gameobject that is given through a unity event
+ActivateMenu(Gameobject) void This will reveal/activate a specific Gameobject that is given through a unity event.
+TogglePauseGame() void This will check if the game is paused, if it is not it will stop the timescale
+PausingEvent() void This will invoke the PausingGame event which allows us to easily add what should happen once the game is paused.

Source

If u wish to take a closer look at the scripts:

Settings Menu

Menu Switcher