177 lines
4.6 KiB
C#
177 lines
4.6 KiB
C#
|
|
using System.Collections;
|
|||
|
|
using TMPro;
|
|||
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.SceneManagement;
|
|||
|
|
using UnityEngine.UI;
|
|||
|
|
|
|||
|
|
public class Mod6Resume : MonoBehaviour
|
|||
|
|
{
|
|||
|
|
[Header("UI TEXTS")]
|
|||
|
|
public TMP_Text scoreText; // Toplam skor
|
|||
|
|
public TMP_Text maxScoreText; // En yüksek skor
|
|||
|
|
public TMP_Text correctText; // Doğru sayısı
|
|||
|
|
public TMP_Text wrongText; // Yanlış sayısı
|
|||
|
|
|
|||
|
|
[Header("BUTTONS")]
|
|||
|
|
public Button retryButton;
|
|||
|
|
public Button exitButton;
|
|||
|
|
|
|||
|
|
[Header("AUDIO")]
|
|||
|
|
public AudioSource sfx;
|
|||
|
|
public AudioClip clickSound;
|
|||
|
|
|
|||
|
|
[Header("━━━ ANIMATION SETTINGS ━━━━━━━━━━━━━━━━━")]
|
|||
|
|
public float countUpDuration = 0.8f;
|
|||
|
|
public float popInDelay = 0.08f;
|
|||
|
|
public float popInTime = 0.3f;
|
|||
|
|
|
|||
|
|
// Mod6 PlayerPrefs Key
|
|||
|
|
private string modKey = "Mod6";
|
|||
|
|
|
|||
|
|
private int score;
|
|||
|
|
private int maxScore;
|
|||
|
|
private int correct;
|
|||
|
|
private int wrong;
|
|||
|
|
|
|||
|
|
// ============================================================
|
|||
|
|
void Start()
|
|||
|
|
{
|
|||
|
|
LoadResults();
|
|||
|
|
PrepareTexts();
|
|||
|
|
|
|||
|
|
// Retry
|
|||
|
|
if (retryButton != null)
|
|||
|
|
retryButton.onClick.AddListener(() =>
|
|||
|
|
{
|
|||
|
|
PlaySFX();
|
|||
|
|
Retry();
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
// Exit
|
|||
|
|
if (exitButton != null)
|
|||
|
|
exitButton.onClick.AddListener(() =>
|
|||
|
|
{
|
|||
|
|
PlaySFX();
|
|||
|
|
ExitToMenu();
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
StartCoroutine(PlayRevealSequence());
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ============================================================
|
|||
|
|
void LoadResults()
|
|||
|
|
{
|
|||
|
|
score = PlayerPrefs.GetInt(modKey + "_LastScore", 0);
|
|||
|
|
maxScore = PlayerPrefs.GetInt(modKey + "_MaxScore", 0);
|
|||
|
|
correct = PlayerPrefs.GetInt(modKey + "_Correct", 0);
|
|||
|
|
wrong = PlayerPrefs.GetInt(modKey + "_Wrong", 0);
|
|||
|
|
|
|||
|
|
Debug.Log($"[MOD6 RESULT] Score={score} | Max={maxScore} | Correct={correct} | Wrong={wrong}");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ============================================================
|
|||
|
|
void PrepareTexts()
|
|||
|
|
{
|
|||
|
|
SetTextZero(scoreText);
|
|||
|
|
SetTextZero(maxScoreText);
|
|||
|
|
SetTextZero(correctText);
|
|||
|
|
SetTextZero(wrongText);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void SetTextZero(TMP_Text txt)
|
|||
|
|
{
|
|||
|
|
if (txt == null) return;
|
|||
|
|
|
|||
|
|
txt.text = "0";
|
|||
|
|
txt.transform.localScale = Vector3.zero;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ============================================================
|
|||
|
|
IEnumerator PlayRevealSequence()
|
|||
|
|
{
|
|||
|
|
yield return StartCoroutine(RevealStat(scoreText, score));
|
|||
|
|
yield return new WaitForSeconds(popInDelay);
|
|||
|
|
|
|||
|
|
yield return StartCoroutine(RevealStat(maxScoreText, maxScore));
|
|||
|
|
yield return new WaitForSeconds(popInDelay);
|
|||
|
|
|
|||
|
|
yield return StartCoroutine(RevealStat(correctText, correct));
|
|||
|
|
yield return new WaitForSeconds(popInDelay);
|
|||
|
|
|
|||
|
|
yield return StartCoroutine(RevealStat(wrongText, wrong));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
IEnumerator RevealStat(TMP_Text txt, int targetValue)
|
|||
|
|
{
|
|||
|
|
if (txt == null) yield break;
|
|||
|
|
|
|||
|
|
// pop-in scale
|
|||
|
|
Vector3 normal = Vector3.one;
|
|||
|
|
float t = 0f;
|
|||
|
|
|
|||
|
|
while (t < 1f)
|
|||
|
|
{
|
|||
|
|
t += Time.deltaTime / Mathf.Max(0.01f, popInTime);
|
|||
|
|
txt.transform.localScale = Vector3.Lerp(Vector3.zero, normal, EaseOutBack(t));
|
|||
|
|
|
|||
|
|
if (targetValue == 0)
|
|||
|
|
txt.text = "0";
|
|||
|
|
|
|||
|
|
yield return null;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
txt.transform.localScale = normal;
|
|||
|
|
|
|||
|
|
// count-up
|
|||
|
|
if (targetValue > 0)
|
|||
|
|
{
|
|||
|
|
float ct = 0f;
|
|||
|
|
|
|||
|
|
while (ct < 1f)
|
|||
|
|
{
|
|||
|
|
ct += Time.deltaTime / Mathf.Max(0.01f, countUpDuration);
|
|||
|
|
int shown = Mathf.RoundToInt(Mathf.Lerp(0, targetValue, EaseOutQuad(ct)));
|
|||
|
|
txt.text = shown.ToString();
|
|||
|
|
yield return null;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
txt.text = targetValue.ToString();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ============================================================
|
|||
|
|
void PlaySFX()
|
|||
|
|
{
|
|||
|
|
if (sfx && clickSound)
|
|||
|
|
sfx.PlayOneShot(clickSound);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ============================================================
|
|||
|
|
void Retry()
|
|||
|
|
{
|
|||
|
|
SceneManager.LoadScene("Mod6");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ============================================================
|
|||
|
|
void ExitToMenu()
|
|||
|
|
{
|
|||
|
|
SceneManager.LoadScene("Anamen");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ============================================================
|
|||
|
|
float EaseOutBack(float t)
|
|||
|
|
{
|
|||
|
|
t = Mathf.Clamp01(t);
|
|||
|
|
|
|||
|
|
float c1 = 1.70158f;
|
|||
|
|
float c3 = c1 + 1f;
|
|||
|
|
|
|||
|
|
return 1f + c3 * Mathf.Pow(t - 1f, 3f) + c1 * Mathf.Pow(t - 1f, 2f);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
float EaseOutQuad(float t)
|
|||
|
|
{
|
|||
|
|
t = Mathf.Clamp01(t);
|
|||
|
|
return 1f - (1f - t) * (1f - t);
|
|||
|
|
}
|
|||
|
|
}
|