using System;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
namespace TMPro {
public class TMP_TextEventHandler : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler {
[SerializeField] private CharacterSelectionEvent m_OnCharacterSelection = new();
[SerializeField] private SpriteSelectionEvent m_OnSpriteSelection = new();
[SerializeField] private WordSelectionEvent m_OnWordSelection = new();
[SerializeField] private LineSelectionEvent m_OnLineSelection = new();
[SerializeField] private LinkSelectionEvent m_OnLinkSelection = new();
private Camera m_Camera;
private Canvas m_Canvas;
private int m_lastCharIndex = -1;
private int m_lastLineIndex = -1;
private int m_lastWordIndex = -1;
private int m_selectedLink = -1;
private TMP_Text m_TextComponent;
///
/// Event delegate triggered when pointer is over a character.
///
public CharacterSelectionEvent onCharacterSelection {
get => m_OnCharacterSelection;
set => m_OnCharacterSelection = value;
}
///
/// Event delegate triggered when pointer is over a sprite.
///
public SpriteSelectionEvent onSpriteSelection {
get => m_OnSpriteSelection;
set => m_OnSpriteSelection = value;
}
///
/// Event delegate triggered when pointer is over a word.
///
public WordSelectionEvent onWordSelection {
get => m_OnWordSelection;
set => m_OnWordSelection = value;
}
///
/// Event delegate triggered when pointer is over a line.
///
public LineSelectionEvent onLineSelection {
get => m_OnLineSelection;
set => m_OnLineSelection = value;
}
///
/// Event delegate triggered when pointer is over a link.
///
public LinkSelectionEvent onLinkSelection {
get => m_OnLinkSelection;
set => m_OnLinkSelection = value;
}
private void Awake() {
// Get a reference to the text component.
m_TextComponent = gameObject.GetComponent();
// Get a reference to the camera rendering the text taking into consideration the text component type.
if (m_TextComponent.GetType() == typeof(TextMeshProUGUI)) {
m_Canvas = gameObject.GetComponentInParent