You can create your own Custom Actions via script (C#).
(Do not forget to read here: Performing Actions while typing )
How to create custom actions
1. Registering custom action IDs
In order to tell TextAnimator which tags are custom actions, you need to add them in the “Custom Actions” array (located in the TextAnimator’s GlobalData Scriptable Object
asset).
P.S. In case you don’t have a GlobalData Scriptable Object, please read here how to create it.
In this example, I’m setting “playAudio” as a custom action.
2. Processing actions in a custom typewriter
Your Custom Actions can be performed by a custom typewriter:
- Create a new typewriter class (Read more here).
- Override the
DoCustomAction
method (do not invoke the base method). - Perform specific actions based on the given “
actionID
” and use anyparameter
as you wish. - Add your new custom typewriter near a TextAnimator component, instead of the default “TextAnimatorPlayer”.
Example script
using System.Collections;
//custom typewriter class
public class CustomTAnimPlayer : Febucci.UI.TextAnimatorPlayer
{
protected override IEnumerator DoCustomAction(Febucci.UI.TypewriterAction action)
{
switch (action.actionID)
{
case "playAudio": //example: an action that plays given sounds
for(int i = 0; i < action.parameters.Count; i++)
{
AudioManager.PlaySoundFromID(action.parameters[i]);
}
yield return new WaitForSeconds(2); //holds the typewriter for 2 seconds
break;
}
}
}
Done! With this simple procedure, you can add any Custom Action you want.