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

142 lines
3.6 KiB
C#

1 month ago
using UnityEngine;
using System.Collections;
3 weeks ago
using UnityEngine.SceneManagement;
using TMPro;
using UnityEngine.UI;
using System.Collections.Generic;
1 month ago
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;
1 month ago
private void Awake()
{
Instance = this;
}
private void Start()
{
score = 0;
PlayerPrefs.SetInt("Score", score);
UpdateUI();
}
public void OnEmailOpened()
1 month ago
{
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();
1 month ago
}
public void ProceedToDebrief()
1 month ago
{
StartCoroutine(MoveCameraToDebrief());
}
private void UpdateUI()
{
float fill = Mathf.Clamp01((openCount + decisionCount) / (totalEmails * 2f));
if (progressBar != null)
progressBar.fillAmount = fill;
foreach (var text in scoreTexts)
1 month ago
{
if (text != null)
text.text = $"Score: {score}/{(totalEmails * 10)}";
1 month ago
}
if (mailCount != null)
mailCount.text = $"Email: {decisionCount} / {totalEmails}";
}
public void Reported(EmailData data)
{
if (data.isPhishing)
1 month ago
{
WorldTimelineManager.Instance.SnapshotCurrentSequence();
1 month ago
}
}
public void Clicked(EmailData data)
1 month ago
{
if (data.isPhishing)
{
Debug.Log("❌ SIMULATION FAILED CREDENTIALS STOLEN");
understandPhishingImage.SetActive(true);
StartCoroutine(MoveCameraToDebrief());
WorldTimelineManager.Instance.SnapshotCurrentSequence();
}
}
3 weeks ago
public void Restarter()
{
SceneManager.LoadScene(0);
}
IEnumerator MoveCameraToDebrief()
1 month ago
{
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;
1 month ago
}
}