PhishingAwarenessSimulation/Assets/Scripts/SceneOutcomeManager.cs

120 lines
3.6 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;
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-05-28 10:27:04 +05:00
private void Awake()
{
Instance = this;
}
public void Reported(EmailData data)
{
2025-05-29 00:19:15 +05:00
if (data.isPhishing)
{
understandPhishingImage.SetActive(true);
StartCoroutine(MoveCameraToDebrief());
WorldTimelineManager.Instance.SnapshotCurrentSequence();
}
else
{
notSuspiciousImage.SetActive(true);
// ✅ No camera or timeline
}
2025-05-28 10:27:04 +05:00
}
public void Clicked(EmailData data)
{
if (data.isPhishing)
{
Debug.Log("❌ SIMULATION FAILED CREDENTIALS STOLEN");
2025-05-29 00:19:15 +05:00
understandPhishingImage.SetActive(true);
StartCoroutine(MoveCameraToDebrief());
WorldTimelineManager.Instance.SnapshotCurrentSequence();
2025-05-28 10:27:04 +05:00
}
else
{
Debug.Log("Clicked safe link.");
2025-05-29 00:19:15 +05:00
// Optional: You can add a "well done" feedback here if desired
2025-05-28 10:27:04 +05:00
}
}
2025-05-29 00:19:15 +05:00
public void Ignored(EmailData data)
2025-05-28 10:27:04 +05:00
{
2025-05-29 00:19:15 +05:00
if (data.isPhishing)
{
alwaysReportImage.SetActive(true);
StartCoroutine(MoveCameraToDebrief());
WorldTimelineManager.Instance.SnapshotCurrentSequence();
}
else
{
// ✅ Not phishing + Ignored → Do nothing
Debug.Log("Ignored a safe email. No feedback triggered.");
}
2025-05-28 10:27:04 +05:00
}
2025-06-05 00:11:38 +05:00
public void Restarter()
{
SceneManager.LoadScene(0);
}
2025-05-29 00:19:15 +05:00
private IEnumerator MoveCameraToDebrief()
2025-05-28 10:27:04 +05:00
{
2025-05-29 20:41:47 +05:00
DebriefObj.SetActive(true);
yield return new WaitForSeconds(2);
if (mainCamera == null || cameraTarget == null || teacherTarget == null)
2025-05-29 00:19:15 +05:00
yield break;
Vector3 startPos = mainCamera.transform.position;
Quaternion startRot = mainCamera.transform.rotation;
2025-05-29 20:41:47 +05:00
Quaternion finalRot = cameraTarget.rotation;
2025-05-29 00:19:15 +05:00
2025-05-29 20:41:47 +05:00
float duration = 2f;
2025-05-29 00:19:15 +05:00
float t = 0;
2025-05-29 20:41:47 +05:00
2025-05-29 00:19:15 +05:00
while (t < 1)
{
2025-05-29 20:41:47 +05:00
t += Time.deltaTime / duration;
// Smooth position interpolation
2025-05-29 00:19:15 +05:00
mainCamera.transform.position = Vector3.Lerp(startPos, cameraTarget.position, t);
2025-05-29 20:41:47 +05:00
if (t < 0.4f)
{
LaptopCanvas.SetActive(false);
// First half: look at teacher
Quaternion lookAtTeacher = Quaternion.LookRotation(teacherTarget.position - mainCamera.transform.position);
mainCamera.transform.rotation = Quaternion.Slerp(mainCamera.transform.rotation, lookAtTeacher, Time.deltaTime * 5f);
}
else
{
// Second half: rotate towards final camera rotation
float rotT = (t - 0.4f) * 2f; // Normalize from 01 for second half
mainCamera.transform.rotation = Quaternion.Slerp(mainCamera.transform.rotation, finalRot, rotT);
}
2025-05-29 00:19:15 +05:00
yield return null;
}
2025-05-29 20:41:47 +05:00
// Snap to ensure exact final values
mainCamera.transform.position = cameraTarget.position;
mainCamera.transform.rotation = finalRot;
2025-05-28 10:27:04 +05:00
}
2025-05-29 20:41:47 +05:00
2025-05-28 10:27:04 +05:00
}