UIOptions - jimdroberts/FishMMO GitHub Wiki

Description

A UI controller for managing all setting options in the FishMMO client. Handles initialization, loading, and saving of all child SettingOption components, and manages the global configuration lifecycle. Ensures that all settings are properly loaded and saved when the UI is started or destroyed.


API Access

Fields

  • private List settingOptions

    List of all setting options found in child objects.

Methods

  • public override void OnStarting()

    Called when the UI is starting. Loads configuration and initializes all setting options. If configuration fails to load, sets defaults and saves a new file.

  • public void LoadAll()

    Loads all setting options from configuration.

  • public void SaveAll()

    Saves all setting options to configuration and persists the global settings file.

  • public override void OnDestroying()

    Called when the UI is being destroyed. (No implementation)


Basic Usage

Setup

  1. Attach UIOptions to a parent UI GameObject containing child SettingOption components.
  2. Ensure the configuration system is available and properly set up.
  3. Call OnStarting() to initialize and load all settings.

Example

// Example usage in a MonoBehaviour
public UIOptions uiOptions;

void Start() {
    uiOptions.OnStarting();
}

// To reload all settings
uiOptions.LoadAll();

// To save all settings
uiOptions.SaveAll();

Best Practices

  • Ensure all child setting controls inherit from SettingOption for automatic management.
  • Always call OnStarting() to initialize and load settings when the UI is shown.
  • Use LoadAll() and SaveAll() to synchronize settings with configuration as needed.
  • Handle configuration file errors gracefully and provide defaults if loading fails.
⚠️ **GitHub.com Fallback** ⚠️