You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PhishingAwarenessSimulation/Assets/Scripts/BodyLinkHandler.cs

76 lines
2.4 KiB
C#

using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
public class BodyLinkHandler : MonoBehaviour, IPointerClickHandler, IPointerExitHandler
{
private TextMeshProUGUI tmp;
void Awake()
{
tmp = GetComponent<TextMeshProUGUI>();
}
void Update()
{
Camera eventCam = null;
// Try to get the event camera from the canvas (better than Camera.main)
if (tmp.canvas.renderMode == RenderMode.WorldSpace)
{
eventCam = tmp.canvas.worldCamera;
}
int linkIndex = TMP_TextUtilities.FindIntersectingLink(tmp, Input.mousePosition, eventCam);
if (linkIndex != -1)
{
CursorManager.Instance?.SetLinkCursor();
}
else
{
CursorManager.Instance?.SetDefaultCursor();
}
}
public void OnPointerClick(PointerEventData eventData)
{
int linkIndex = TMP_TextUtilities.FindIntersectingLink(tmp, Input.mousePosition, eventData.pressEventCamera);
if (linkIndex != -1)
{
string linkID = tmp.textInfo.linkInfo[linkIndex].GetLinkID();
Debug.Log("🔗 Clicked link: " + linkID);
EmailPopupManager.Instance?.ShowPopup(linkID);
var emailPanelGO = WorldTimelineManager.Instance?.OpenedEmailPanel;
if (emailPanelGO != null && emailPanelGO.TryGetComponent<EmailOpenPanel>(out var emailPanel))
{
EmailData email = emailPanel.Email;
if (email != null)
{
SceneOutcomeManager.Instance?.Clicked(email);
//UserActionLogger.Instance?.Log($"Clicked link '{linkID}' in email from '{email.senderName}'");
string englishLog = $"Clicked link '{linkID}' in email from '{email.senderName}'";
string arabicLog = $"تم الضغط على الرابط '{linkID}' في البريد من '{email.senderName}'";
UserActionLogger.Instance?.Log(englishLog, arabicLog);
}
else
{
Debug.LogWarning("📭 EmailData is null in EmailOpenPanel.");
}
}
else
{
Debug.LogWarning("📭 OpenedEmailPanel or EmailOpenPanel script not found.");
}
}
}
public void OnPointerExit(PointerEventData eventData)
{
CursorManager.Instance?.SetDefaultCursor();
}
}