Writing Custom Actions (C#)

Other than using built-in actions, you can write your own via script (C#).


Actions Base Class

When creating a new class, inherit from Febucci.UI.Actions.ActionScriptableBase (Scripting API).

public class CustomAction : ActionScriptableBase
{
    //[...]

Attributes

Since you’re creating a ScriptableObject, just like Events, make sure to add the needed attributes as well in order to instance and serialize them:

[CreateAssetMenu(fileName = "YourCustomAction", menuName = "Text Animator/Custom/YourCustomAction")]
[System.Serializable]
public class CustomAction : ActionScriptableBase
{
    //[...]

This way you’ll be able to create them from your Project Window.

DoAction Method

Then, all you need to do is overriding the “DoAction” method and write your code inside it.

Remember that actions pause the typewriter until they’re completed (for example, waiting for player input or until time has passed).

public override IEnumerator DoAction(ActionMarker action, TypewriterCore typewriter, TypingInfo typingInfo)
{
    //[...]
}
  • The action paramater has useful info about your tag, for example the ID or if there are any parameters that come with it (e.g. <playSound=02>).
  • The typewriter references the component that is currently performing the action
  • The typingInfo contains information such as the current typing speed (which you can modify) and time passed inside the typewriter.

Please refer to the Scripting API to have a complete view of the classes and more.


✅ Done!

Done! With this simple procedure, you can add any Custom Action you want.

P.S. Don’t forget to create your action ScriptableObject in the ProjectView, and add it to an actions Database.

End of the page. Go back to the Documentation Index.