PhishingAwarenessSimulation/Assets/Scripts/SceneOutcomeManager.cs
2025-06-05 00:11:38 +05:00

120 lines
3.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class SceneOutcomeManager : MonoBehaviour
{
public static SceneOutcomeManager Instance;
[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;
public Transform teacherTarget;
public GameObject DebriefObj;
public GameObject LaptopCanvas;
private void Awake()
{
Instance = this;
}
public void Reported(EmailData data)
{
if (data.isPhishing)
{
understandPhishingImage.SetActive(true);
StartCoroutine(MoveCameraToDebrief());
WorldTimelineManager.Instance.SnapshotCurrentSequence();
}
else
{
notSuspiciousImage.SetActive(true);
// ✅ No camera or timeline
}
}
public void Clicked(EmailData data)
{
if (data.isPhishing)
{
Debug.Log("❌ SIMULATION FAILED CREDENTIALS STOLEN");
understandPhishingImage.SetActive(true);
StartCoroutine(MoveCameraToDebrief());
WorldTimelineManager.Instance.SnapshotCurrentSequence();
}
else
{
Debug.Log("Clicked safe link.");
// Optional: You can add a "well done" feedback here if desired
}
}
public void Ignored(EmailData data)
{
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.");
}
}
public void Restarter()
{
SceneManager.LoadScene(0);
}
private IEnumerator MoveCameraToDebrief()
{
DebriefObj.SetActive(true);
yield return new WaitForSeconds(2);
if (mainCamera == null || cameraTarget == null || teacherTarget == null)
yield break;
Vector3 startPos = mainCamera.transform.position;
Quaternion startRot = mainCamera.transform.rotation;
Quaternion finalRot = cameraTarget.rotation;
float duration = 2f;
float t = 0;
while (t < 1)
{
t += Time.deltaTime / duration;
// Smooth position interpolation
mainCamera.transform.position = Vector3.Lerp(startPos, cameraTarget.position, t);
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);
}
yield return null;
}
// Snap to ensure exact final values
mainCamera.transform.position = cameraTarget.position;
mainCamera.transform.rotation = finalRot;
}
}