PhishingAwarenessSimulation/Assets/Scripts/SceneOutcomeManager.cs
2025-06-23 14:13:43 +05:00

142 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;
using TMPro;
using UnityEngine.UI;
using System.Collections.Generic;
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;
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;
private void Awake()
{
Instance = this;
}
private void Start()
{
score = 0;
PlayerPrefs.SetInt("Score", score);
UpdateUI();
}
public void OnEmailOpened()
{
openCount++;
UpdateUI();
}
public void OnEmailDecision(bool wasCorrect, int rewardPoints = 9)
{
decisionCount++;
if (wasCorrect)
{
score += rewardPoints;
PlayerPrefs.SetInt("Score", score);
}
if (!nextButtonShown && decisionCount >= totalEmails && nextButton != null)
{
nextButton.SetActive(true);
nextButtonShown = true;
}
UpdateUI();
}
public void ProceedToDebrief()
{
StartCoroutine(MoveCameraToDebrief());
}
private void UpdateUI()
{
float fill = Mathf.Clamp01((openCount + decisionCount) / (totalEmails * 2f));
if (progressBar != null)
progressBar.fillAmount = fill;
foreach (var text in scoreTexts)
{
if (text != null)
text.text = $"Score: {score}/{(totalEmails * 10)}";
}
if (mailCount != null)
mailCount.text = $"Email: {decisionCount} / {totalEmails}";
}
public void Reported(EmailData data)
{
if (data.isPhishing)
{
WorldTimelineManager.Instance.SnapshotCurrentSequence();
}
}
public void Clicked(EmailData data)
{
if (data.isPhishing)
{
Debug.Log("❌ SIMULATION FAILED CREDENTIALS STOLEN");
understandPhishingImage.SetActive(true);
StartCoroutine(MoveCameraToDebrief());
WorldTimelineManager.Instance.SnapshotCurrentSequence();
}
}
public void Restarter()
{
SceneManager.LoadScene(0);
}
IEnumerator MoveCameraToDebrief()
{
LaptopCanvas.SetActive(false);
DebriefObj.SetActive(true);
float elapsedTime = 0f;
Vector3 startingPos = mainCamera.transform.position;
Quaternion startingRot = mainCamera.transform.rotation;
while (elapsedTime < cameraMoveSpeed)
{
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;
yield return null;
}
mainCamera.transform.position = cameraTarget.position;
mainCamera.transform.rotation = cameraTarget.rotation;
}
}