Custom Event Handlers
Using events in custom MonoBehaviours
public class CustomEventHandler : MonoBehaviour
{
// 1. Reference your UI Document
[SerializeField]
private UIDocument uiDocument;
private IAnimatedTextElement _dialogueBox;
private void OnEnable()
{
// 2. Find your animated text element
_dialogueBox = TextAnimationUtility.GetAnimatedTextElement(uiDocument, "dialogue-box");
// 3. Register the events you're interested in
_dialogueBox.animationEvent += OnAnimationEvent;
_dialogueBox.letterAppeared += OnLetterAppeared;
_dialogueBox.textAppearanceFinished += OnTextAppearanceFinished;
}
private void OnDisable()
{
// 4. Unregister your events in OnDisable,
// or your component will continue to work when disabled.
_dialogueBox.animationEvent -= OnAnimationEvent;
_dialogueBox.letterAppeared -= OnLetterAppeared;
_dialogueBox.textAppearanceFinished -= OnTextAppearanceFinished;
}
private void OnAnimationEvent(TextAnimationEvent ev)
{
Debug.Log("Received animation event");
}
private void OnLetterAppeared(LetterAppearanceEvent ev)
{
Debug.Log("Received letter appearance event for letter: " + ev.letter);
}
private void OnTextAppearanceFinished(TextAppearanceFinishedEvent ev)
{
Debug.Log("Received text appearance finished event");
}
}Last updated