PhishingAwarenessSimulation/Assets/Scripts/SceneOutcomeManager.cs

146 lines
3.9 KiB
C#
Raw Normal View History

2025-05-28 10:27:04 +05:00
using UnityEngine;
2025-05-29 00:19:15 +05:00
using System.Collections;
2025-06-05 00:11:38 +05:00
using UnityEngine.SceneManagement;
using TMPro;
2025-06-23 14:13:43 +05:00
using UnityEngine.UI;
using System.Collections.Generic;
2025-05-28 10:27:04 +05:00
public class SceneOutcomeManager : MonoBehaviour
{
public static SceneOutcomeManager Instance;
2025-05-29 00:19:15 +05:00
[Header("UI Images")]
public GameObject notSuspiciousImage;
public GameObject alwaysReportImage;
public GameObject understandPhishingImage;
[Header("Camera Movement")]
public Transform cameraTarget;
public float cameraMoveSpeed = 1.5f;
public Camera mainCamera;
2025-05-29 20:41:47 +05:00
public Transform teacherTarget;
public GameObject DebriefObj;
public GameObject LaptopCanvas;
2025-06-23 14:13:43 +05:00
public GameObject nextButton;
[Header("Score UI")]
public List<TextMeshProUGUI> scoreTexts = new List<TextMeshProUGUI>();
public Image progressBar;
public int totalEmails = 5;
public TextMeshProUGUI mailCount;
private int openCount = 0;
private int decisionCount = 0;
private int score = 0;
private bool nextButtonShown = false;
2025-07-24 14:26:09 +05:00
public CanvasGroup progressbarCanvasGroup;
public GameObject slides_Arabic;
public GameObject slides_English;
2025-05-28 10:27:04 +05:00
private void Awake()
{
Instance = this;
}
2025-06-23 14:13:43 +05:00
private void Start()
{
2025-06-23 14:13:43 +05:00
score = 0;
PlayerPrefs.SetInt("Score", score);
UpdateUI();
}
2025-06-23 14:13:43 +05:00
public void OnEmailOpened()
2025-05-28 10:27:04 +05:00
{
2025-06-23 14:13:43 +05:00
openCount++;
UpdateUI();
}
public void OnEmailDecision(bool wasCorrect, int rewardPoints = 9)
{
decisionCount++;
if (wasCorrect)
2025-05-29 00:19:15 +05:00
{
2025-06-23 14:13:43 +05:00
score += rewardPoints;
PlayerPrefs.SetInt("Score", score);
2025-05-29 00:19:15 +05:00
}
2025-06-23 14:13:43 +05:00
if (!nextButtonShown && decisionCount >= totalEmails && nextButton != null)
2025-05-29 00:19:15 +05:00
{
2025-06-23 14:13:43 +05:00
nextButton.SetActive(true);
nextButtonShown = true;
2025-05-29 00:19:15 +05:00
}
2025-06-23 14:13:43 +05:00
UpdateUI();
2025-05-28 10:27:04 +05:00
}
2025-06-23 14:13:43 +05:00
public void ProceedToDebrief()
2025-05-28 10:27:04 +05:00
{
2025-07-24 14:26:09 +05:00
(LanguageManager.Instance.IsArabic ? slides_Arabic : slides_English).SetActive(true);
2025-06-25 23:14:09 +05:00
NarrationPlayer.Instance.PlayNarration(NarrationID.Feedback);
2025-06-23 14:13:43 +05:00
StartCoroutine(MoveCameraToDebrief());
}
private void UpdateUI()
{
float fill = Mathf.Clamp01((openCount + decisionCount) / (totalEmails * 2f));
if (progressBar != null)
progressBar.fillAmount = fill;
foreach (var text in scoreTexts)
2025-05-28 10:27:04 +05:00
{
2025-06-23 14:13:43 +05:00
if (text != null)
text.text = $"Score: {score}/{(totalEmails * 10)}";
2025-05-28 10:27:04 +05:00
}
2025-06-23 14:13:43 +05:00
if (mailCount != null)
mailCount.text = $"Email: {decisionCount} / {totalEmails}";
}
public void Reported(EmailData data)
{
if (data.isPhishing)
2025-05-28 10:27:04 +05:00
{
2025-06-23 14:13:43 +05:00
WorldTimelineManager.Instance.SnapshotCurrentSequence();
2025-05-28 10:27:04 +05:00
}
}
2025-06-23 14:13:43 +05:00
public void Clicked(EmailData data)
2025-05-28 10:27:04 +05:00
{
2025-05-29 00:19:15 +05:00
if (data.isPhishing)
{
2025-06-23 14:13:43 +05:00
Debug.Log("❌ SIMULATION FAILED CREDENTIALS STOLEN");
understandPhishingImage.SetActive(true);
2025-05-29 00:19:15 +05:00
StartCoroutine(MoveCameraToDebrief());
WorldTimelineManager.Instance.SnapshotCurrentSequence();
}
}
2025-06-23 14:13:43 +05:00
2025-06-05 00:11:38 +05:00
public void Restarter()
{
SceneManager.LoadScene(0);
}
2025-06-23 14:13:43 +05:00
IEnumerator MoveCameraToDebrief()
2025-05-28 10:27:04 +05:00
{
2025-06-23 14:13:43 +05:00
LaptopCanvas.SetActive(false);
2025-05-29 20:41:47 +05:00
DebriefObj.SetActive(true);
2025-05-29 00:19:15 +05:00
2025-06-23 14:13:43 +05:00
float elapsedTime = 0f;
Vector3 startingPos = mainCamera.transform.position;
Quaternion startingRot = mainCamera.transform.rotation;
2025-05-29 20:41:47 +05:00
2025-06-23 14:13:43 +05:00
while (elapsedTime < cameraMoveSpeed)
2025-05-29 00:19:15 +05:00
{
2025-06-23 14:13:43 +05:00
float t = elapsedTime / cameraMoveSpeed;
mainCamera.transform.position = Vector3.Lerp(startingPos, cameraTarget.position, t);
mainCamera.transform.rotation = Quaternion.Slerp(startingRot, cameraTarget.rotation, t);
elapsedTime += Time.deltaTime;
2025-05-29 00:19:15 +05:00
yield return null;
}
2025-05-29 20:41:47 +05:00
mainCamera.transform.position = cameraTarget.position;
2025-06-23 14:13:43 +05:00
mainCamera.transform.rotation = cameraTarget.rotation;
2025-05-28 10:27:04 +05:00
}
}