ToggleSettingOption - jimdroberts/FishMMO GitHub Wiki

Description

A generic UI option for toggling a boolean setting in the FishMMO client. Provides a toggle for users to enable or disable a feature, persists the setting, and updates the UI accordingly. Integrates with the configuration system.


API Access

Fields

  • public string ToggleKey

    The configuration key used to store the toggle value.

  • public Toggle Toggle

    The UI Toggle component associated with this setting.

Methods

  • public override void Initialize()

    Initializes the toggle setting, sets up listeners, and validates required fields. Logs an error if the key or toggle is missing.

  • public override void Load()

    Loads the toggle value from configuration and updates the UI. Defaults to the current UI value if not set.

  • public override void Save()

    Saves the current toggle value to configuration.


Basic Usage

Setup

  1. Attach ToggleSettingOption to a toggle option UI GameObject in the Unity Editor.
  2. Assign the Toggle field in the Inspector.
  3. Set the ToggleKey to a unique configuration key for this setting.
  4. Ensure the configuration system is available and properly set up.

Example

// Example usage in a MonoBehaviour
public ToggleSettingOption toggleOption;

toggleOption.ToggleKey = "ShowFPS";

void Start() {
    toggleOption.Initialize();
    toggleOption.Load();
}

// When the toggle value changes, Save() is called automatically.

Best Practices

  • Always assign the Toggle in the Inspector and set a unique ToggleKey to avoid errors.
  • Use the configuration system to persist user preferences.
  • Validate required fields and log errors for missing references or keys.
⚠️ **GitHub.com Fallback** ⚠️