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/UserActionLogger.cs

54 lines
1.1 KiB
C#

using System.Collections.Generic;
using UnityEngine;
using System.Text;
using TMPro;
public class UserActionLogger : MonoBehaviour
{
public static UserActionLogger Instance;
private List<string> logs = new List<string>();
public TextMeshProUGUI summaryText;
private void Awake()
{
if (Instance == null)
Instance = this;
else
Destroy(gameObject);
}
public void Log(string action)
{
logs.Add(action);
Debug.Log($"📜 Action Logged: {logs.Count}. {action}");
}
public void LogQuizAnswer(string answerText)
{
Log($"Answered quiz: {answerText}");
}
public string GetFullLog()
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < logs.Count; i++)
{
sb.AppendLine($"{i + 1}. {logs[i]}");
}
return sb.ToString();
}
[ContextMenu("ShowSummary")]
public void ShowSummary()
{
if (summaryText != null)
summaryText.text = GetFullLog();
}
public void ClearLog()
{
logs.Clear();
}
}