ToggleSettingOption - jimdroberts/FishMMO GitHub Wiki
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.
-
public string ToggleKey
The configuration key used to store the toggle value.
-
public Toggle Toggle
The UI Toggle component associated with this setting.
-
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.
- Attach
ToggleSettingOption
to a toggle option UI GameObject in the Unity Editor. - Assign the
Toggle
field in the Inspector. - Set the
ToggleKey
to a unique configuration key for this setting. - Ensure the configuration system is available and properly set up.
// 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.
- Always assign the
Toggle
in the Inspector and set a uniqueToggleKey
to avoid errors. - Use the configuration system to persist user preferences.
- Validate required fields and log errors for missing references or keys.