Writing Custom Effects (C#)

Other than using built-in effects or creating custom ones from the Inspector, you can easily program custom Effects via C#.

P.S. Make sure you have read the Advanced Concepts page!

Effects have three key parts (which can be written in the same file).

Parameters class/struct

Contains information about the data/values you will use in your effect (state)

State struct

Main effect class. Given the parameters and a Character, modifies it through time. Also handles Modifiers

Scriptable Wrapper

Unifies the previous elements together and lets you save things on disk. A few of line of code to let us do the rest!

Writing your Custom Script

For this example, we're making an effect that makes a character go up by a variable amount.

First, make sure to import the necessary namespaces (your IDE will tell you anyways <3)

using UnityEngine;

// import Text Animator's namespaces
using Febucci.TextAnimatorCore;
using Febucci.TextAnimatorCore.Text;
using Febucci.Parsing;
using Febucci.TextAnimatorForUnity.Effects;

Parameters

Create the data you will need to modify the characters (it's the same one you will see and edit in the Inspector).

State

The "core" part of an effect. Modifies the letter given the parameters and pre-calculated Text Animator data.

  • The struct must inherit from IEffectState.

Scriptable Object Wrapper

Creates the logic necessary to hook your custom effect into Text Animator, also saving it in the Assets folder.

There is another version of "ManagedEffectScriptable" which accepts more types, as well as the "Referenced" effect implementation, but we will cover than from future versions!


Have fun applying your effects!


A guide for creating "Referenced" effects is coming soon, as we're still tinkering the UX/API part.