Writing Custom Effects (C#)
You can easily program custom Effects via C#.
1. Effect Base Class
All you need to do is inherit from the base Febucci.UI.TextAnimationEffect
.
Scripting API will be available soon!
public partial class CustomEffect : TextAnimationEffect
{
//[...]
There are also some useful classes already available for you that you can view from the API, like the “BehaviorEffectBase” or “AppearanceEffectBase” which are intended for each effect category, “SineBehaviorEffectsBase” which already handles modifiers such as “a, f, w” and more.
2. Attributes
Since you’re creating a Resource, make sure to add the needed attributes as well in order to instance and serialize them:
[Tool, GlobalClass]
public partial class CustomEffect : TextAnimationEffect
{
//[...]
Both attributes are mandatory to see the new effects in the resource explorer of a TextAnimationsDatabase
.
3. Modifiers Methods
Since effects can be affected by “Modifiers”, you can override the following methods to handle them in your animations:
These methods will be applied, in order, before the animation.
3.1 Accessing TextAnimator
You can access the current TextAnimator from your effect by calling the property:
public TextAnimator TextAnimator { get; private set; }
3.1 ResetContext
override void OnResetContext()
You can use this method to reset your animation’s variables to their initial state.
For example, in the inspector you can publicly expose a variable called baseSpeed
, but in your effect only use currentSpeed
and have that variable be currentSpeed=baseSpeed
inside this method.
3.2 SetModifier
override void SetModifier(ModifierInfo modifierInfo, CharFXTransform charTransform)
You can use this method to apply a modifier to your variables.
For example this will multiply the currentSpeed
value by the s
modifier (if there is any).
public override void SetModifier(ModifierInfo modifierInfo, CharFXTransform charTransform)
{
switch (modifierInfo.name)
{
case "s": currentSpeed *= modifier.value; break;
}
}
👍🏻 If you want to create a Behavior effect that has three modifiers such as “CurrentAmplitude”, “CurrentFrequency” and “CurrentWaveSize”, you can create a class that inherits from BehaviorSineBase
which will handle them for you.
4. Animation Methods
Here are a few methods that you can override to create your custom animations.
4.1 CanApplyEffectTo
override bool CanApplyEffectTo(CharFXTransform charFx)
Used to check if the effect can be applied to the current letter. For example if you’re creating an appearance effect, which only applies if a character passed time is within the effect’s durattion (but in that case you can inherit from “AppearanceScriptableBase” and have it handle that for you).
You can go beyond that, for example check if the character is a number or a letter, or their word index and much more.
4.2 OnProcessCustomFx
override void OnProcessCustomFx(CharFXTransform charFX)
Main method to apply an animation to a letter, called if “OnProcessCustomFx” returned true.
charFX
is reset every frame so you’re expected to modify its values in order to animate a letter.
✅ Done!
You’ve completed all the steps necessary, yay! The more effects you add, the more this process will sound familiar and simpler.
Remember to create your effect ScriptableObject in the ProjectView, and add it to a database.
You can read more here: Databases
👍🏻 You can always take a look at the built-in effects classes and see how they’re implemented.
Have fun applying your effects!