✏️Modifiers

Modifiers allow you to change the values before they are set or retrieved by requesters. Modifiers provide flexibility in manipulating the bound values. Like converters, modifiers are relatively simple to implement and extend.

To add a new modifier, it is sufficient to implement the IModifier<T> interface:

public class MyModifier : IModifier<bool>
{
    public string Id => "Invert";
    public string ShortDataDescription => "[Invert X]";
    public BindMode ModifyMode => BindMode.ReadWrite;
    public object Modify(object value) => !((bool)value); // This is required for internal purposes
    public bool ModifyRead(in bool value) => !value; // Used when reading a value from source
    public bool ModifyWrite(in bool value) => !value; // Used when writing a value to source
}

The system will automatically pick up the new modifier and make it available in Bind Menu. To avoid auto registration of the new modifier, add [HideMember] attribute over the class.

Sometimes the system will need another recompilation round to successfully register the new modifier.

The modifier must have a parameterless constructor.

For new numeric modifiers, we suggest extending NumericModifier for simplicity. It only requires to implement a simple Modify(double) method and optionally another Modify(long) method to cover all numeric modification cases.

Most of the modifiers have their code exposed, this is to allow users to change them at their heart's content.

Last updated