ResolutionSettingOption - jimdroberts/FishMMO GitHub Wiki
A UI option for adjusting the screen resolution in the FishMMO client. Provides a dropdown for users to select the desired resolution, persists the setting, and applies it to the game window. Integrates with the configuration system and Unity's screen settings.
-
public int DefaultResolutionWidth
The default resolution width if no value is saved.
-
public int DefaultResolutionHeight
The default resolution height if no value is saved.
-
public TMP_Dropdown ResolutionDropdown
The dropdown UI component for selecting screen resolution.
-
public override void Initialize()
Initializes the resolution setting, sets up listeners, and populates available resolutions. Logs an error if the dropdown is missing.
-
private void PopulateResolutions()
Populates the dropdown with all available screen resolutions and sets the current selection.
-
public override void Load()
Loads the saved resolution from configuration and applies it. Defaults to the specified default width and height if not set.
-
public override void Save()
Saves the selected resolution to configuration and applies it.
-
private int GetResolutionIndex(int width, int height)
Finds the index of the resolution matching the given width and height.
-
private void ApplyResolution(int index)
Applies the resolution at the given index to the screen.
- Attach
ResolutionSettingOption
to a resolution option UI GameObject in the Unity Editor. - Assign the
ResolutionDropdown
field in the Inspector. - Set the default width and height as needed.
- Ensure the configuration system is available and properly set up.
// Example usage in a MonoBehaviour
public ResolutionSettingOption resolutionOption;
void Start() {
resolutionOption.Initialize();
resolutionOption.Load();
}
// When the dropdown value changes, Save() is called automatically.
- Always assign the
ResolutionDropdown
in the Inspector to avoid errors. - Use the configuration system to persist user preferences.
- Populate the dropdown with only supported resolutions for the platform.
- Validate required fields and log errors for missing references.