146 lines
3.9 KiB
C#
146 lines
3.9 KiB
C#
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;
|
||
public CanvasGroup progressbarCanvasGroup;
|
||
public GameObject slides_Arabic;
|
||
public GameObject slides_English;
|
||
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()
|
||
{
|
||
(LanguageManager.Instance.IsArabic ? slides_Arabic : slides_English).SetActive(true);
|
||
NarrationPlayer.Instance.PlayNarration(NarrationID.Feedback);
|
||
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;
|
||
}
|
||
}
|