Table of Contents

Class OnChangeAttribute

Namespace
Nautilus.Options.Attributes
Assembly
Nautilus.dll
Attribute used to signify a method to call whenever the decorated member's value changes.
[AttributeUsage(AttributeTargets.Property|AttributeTargets.Field, AllowMultiple = true)]
public sealed class OnChangeAttribute : ModOptionEventAttribute, _Attribute
Inheritance
OnChangeAttribute
Implements
Inherited Members
Extension Methods

Examples

using Nautilus.Json;
using Nautilus.Options;
using QModManager.Utility;
using UnityEngine;

[Menu("Nautilus Example Mod")]
public class Config : ConfigFile
{
    [Toggle("My checkbox"), OnChange(nameof(MyCheckboxToggleEvent)), OnChange(nameof(MyGenericValueChangedEvent))]
    public bool ToggleValue;

    public void MyCheckboxToggleEvent(ToggleChangedEventArgs e)
    {
        Logger.Log(Logger.Level.Info, "Checkbox value was changed!");
        Logger.Log(Logger.Level.Info, $"{e.Value}");
    }

    private void MyGenericValueChangedEvent(ModOptionEventArgs e)
    {
        Logger.Log(Logger.Level.Info, "Generic value changed!");
        Logger.Log(Logger.Level.Info, $"{e.Id}: {e.GetType()}");

        switch (e)
        {
            case KeybindChangedEventArgs keybindChangedEventArgs:
                Logger.Log(Logger.Level.Info, keybindChangedEventArgs.KeyName);
                break;
            case ChoiceChangedEventArgs choiceChangedEventArgs:
                Logger.Log(Logger.Level.Info, choiceChangedEventArgs.Value);
                break;
            case SliderChangedEventArgs sliderChangedEventArgs:
                Logger.Log(Logger.Level.Info, sliderChangedEventArgs.Value.ToString());
                break;
            case ToggleChangedEventArgs toggleChangedEventArgs:
                Logger.Log(Logger.Level.Info, toggleChangedEventArgs.Value.ToString());
                break;
        }
     }

Remarks

The method must be a member of the same class. Can be specified mutliple times to call multiple methods.

The specified method can take the following parameters in any order:
- object sender: The sender of the event
- EventArgs eventArgs: The generalized event arguments of the event
- ChoiceChangedEventArgs<T> choiceChangedEventArgs: Only when the member corresponds to a ModChoiceOption<T>
- KeybindChangedEventArgs keybindChangedEventArgs: Only when the member correspends to a ModKeybindOption
- SliderChangedEventArgs sliderChangedEventArgs: Only when the member corresponds to a ModSliderOption
- ToggleChangedEventArgs toggleChangedEventArgs: Only when the member corresponds to a ModToggleOption

Constructors

OnChangeAttribute(string)

Signifies a method to call whenever the decorated member's value changes.
public OnChangeAttribute(string methodName)

Parameters

methodName string
The name of the method within the same class to invoke.

Remarks

The method must be a member of the same class.

See Also