Use the regular syntax
The regular syntax is a set of extension methods in the Concordance namespace, called on the member
you modify. It does everything the quick syntax does, and lets you choose the owner, a key and a local order:
x = (Modifier)(x * 0.5f) is x.Modify(x * 0.5f), and x = Modifier.Stop is
x.StopModifying().
Call Modify
To set a modifier with options, call Modify on the member, and StopModifying to remove
it:
using Concordance;
rb.gravityScale.Modify(rb.gravityScale * 0.5f); // halves gravityScale
AudioListener.volume.Modify(0f, owner: caller, key: "mute"); // owned by caller, told apart by a key
AudioListener.volume.StopModifying(owner: caller, key: "mute");
Call it on the member itself: a field, a property with a setter, or the getter of a getter and setter pair. Never call it on a local variable. Concordance rewrites the call so that it acts on the member, not on a copy of its value. Every method takes the same parameters:
| Parameter | Default | Description |
|---|---|---|
| The value | Required | What the modifier does: a value, read as in the quick syntax, or a modifier function. |
owner | The calling object | The object the modifier ends with. A line in a shared helper, such as a buff system, belongs to the helper: pass owner to give each buff its own lifetime. For more information, refer to When a modifier ends. |
key | None | Tells apart several modifiers of one owner on one member. |
localOrder | 0 | Orders the modifiers of one script on one member. |
Compute the value
The value passed to Modify follows the quick syntax's rules: the member you modify reads as its value
before this modifier, and everything else is read once, when the call runs:
speed.Modify(speed / 2f);
transform.localScale.Modify(transform.localScale * 2f);
lamp.color.Modify(Color.Lerp(lamp.color, alarmColor, 0.5f), key: "alarm");
A modifier keeps the values it was written with. To follow a value that changes over time, call
Modify again, such as from Update.
To pass what the modifier does as an object, such as a function picked in the Inspector window, pass a modifier function. For more information, refer to Modifier functions.
Hold several modifiers from one owner
An owner has one modifier per member. To hold several on the same member, give each one a key:
void OnTriggerEnter2D(Collider2D zone) => rb.gravityScale.Modify(0.5f, key: zone);
void OnTriggerExit2D(Collider2D zone) => rb.gravityScale.StopModifying(key: zone);
A key can be any object. The quick syntax always uses a null key, the same as Modify without a key.
Code in a base class and in a class deriving from it has the same owner, the object, so their modifier lines on
the same member replace each other: give each one a key to keep both.
Order the modifiers of one script
When one script sets several modifiers on the same member, localOrder orders them, lowest
first:
lamp.intensity.Modify(lamp.intensity + 0.5f, key: "boost", localOrder: 0);
lamp.intensity.Modify(lamp.intensity * dim, key: "dim", localOrder: 1); // applies after the boost
The order between different scripts comes from their phases. For more information, refer to Order modifiers.