246 lines
7.7 KiB
C#
246 lines
7.7 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
using System.Collections;
|
|
|
|
public class MissionManager : MonoBehaviour
|
|
{
|
|
public static MissionManager instance;
|
|
|
|
[Header("UI Panel Dialog")]
|
|
public GameObject panelDialogUI;
|
|
public TextMeshProUGUI txtNamaUI;
|
|
public TextMeshProUGUI txtIsiDialogUI;
|
|
|
|
[Header("UI Tombol Pilihan")]
|
|
public Button[] tombolPilihanUI;
|
|
public TextMeshProUGUI[] txtTombolUI;
|
|
|
|
[Header("UI Skor & Tracker")]
|
|
public TextMeshProUGUI txtSkorUI;
|
|
public TextMeshProUGUI txtTrackerMisiUI;
|
|
|
|
[Header("Referensi Player")]
|
|
public PlayerMovement playerScript;
|
|
|
|
[Header("--- PENGATURAN LEVEL (GANTI DI INSPECTOR) ---")]
|
|
public int urutanLevelIni = 1;
|
|
[TextArea] public string teksIntroLevel = "Teks intro misi level ini...";
|
|
|
|
public string idMisi1 = "Barang1";
|
|
[TextArea] public string notifMisi1Selesai = "Notifikasi saat barang 1 diambil";
|
|
|
|
public string idMisi2 = "Barang2";
|
|
[TextArea] public string notifMisi2Selesai = "Notifikasi saat barang 2 diambil";
|
|
|
|
public string namaSceneSelanjutnya = "NamaSceneBerikutnya";
|
|
|
|
[Header("Pengaturan Game")]
|
|
public float kecepatanKetik = 0.02f;
|
|
public int poinGameMisi = 100;
|
|
|
|
// Status Checklist Misi
|
|
private Coroutine ketikCoroutine;
|
|
private bool sudahMisi1 = false;
|
|
private bool sudahMisi2 = false;
|
|
|
|
private int totalSkorKesopanan = 100;
|
|
private int jumlahTugasSelesai = 0;
|
|
|
|
void Awake()
|
|
{
|
|
instance = this;
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
panelDialogUI.SetActive(false);
|
|
UpdateSkorUI();
|
|
UpdateTrackerUI();
|
|
MulaiIntroCerita();
|
|
}
|
|
|
|
void MulaiIntroCerita()
|
|
{
|
|
playerScript.canMove = false;
|
|
panelDialogUI.SetActive(true);
|
|
txtNamaUI.text = "INFO MISI";
|
|
|
|
CetakTeksDialog(teksIntroLevel);
|
|
SetupTombolTunggal("Siap, Mulai!");
|
|
}
|
|
|
|
public void CetakTeksDialog(string kalimat)
|
|
{
|
|
if (ketikCoroutine != null) StopCoroutine(ketikCoroutine);
|
|
ketikCoroutine = StartCoroutine(KetikKalimatAsinkron(kalimat));
|
|
}
|
|
|
|
IEnumerator KetikKalimatAsinkron(string kalimat)
|
|
{
|
|
txtIsiDialogUI.text = "";
|
|
foreach (char huruf in kalimat.ToCharArray())
|
|
{
|
|
txtIsiDialogUI.text += huruf;
|
|
yield return new WaitForSeconds(kecepatanKetik);
|
|
}
|
|
}
|
|
|
|
void SetupTombolTunggal(string teksTombol)
|
|
{
|
|
foreach (var btn in tombolPilihanUI) btn.gameObject.SetActive(false);
|
|
|
|
tombolPilihanUI[0].gameObject.SetActive(true);
|
|
txtTombolUI[0].text = teksTombol;
|
|
tombolPilihanUI[0].onClick.RemoveAllListeners();
|
|
tombolPilihanUI[0].onClick.AddListener(TutupPanelDialog);
|
|
}
|
|
|
|
public void InteraksiDenganObjek(string idObjek)
|
|
{
|
|
playerScript.canMove = false;
|
|
panelDialogUI.SetActive(true);
|
|
txtNamaUI.text = "NOTIFIKASI MISI";
|
|
|
|
string teksMisi = "";
|
|
|
|
if (idObjek == idMisi1 && !sudahMisi1)
|
|
{
|
|
sudahMisi1 = true;
|
|
jumlahTugasSelesai++;
|
|
teksMisi = notifMisi1Selesai;
|
|
}
|
|
else if (idObjek == idMisi2 && !sudahMisi2)
|
|
{
|
|
sudahMisi2 = true;
|
|
jumlahTugasSelesai++;
|
|
teksMisi = notifMisi2Selesai;
|
|
}
|
|
|
|
UpdateTrackerUI();
|
|
|
|
if (playerScript.objekTerdekat != null)
|
|
{
|
|
Destroy(playerScript.objekTerdekat.gameObject);
|
|
if (playerScript.promptInteraksiUI != null) playerScript.promptInteraksiUI.SetActive(false);
|
|
}
|
|
|
|
CetakTeksDialog(teksMisi);
|
|
SetupTombolTunggal("Lanjutkan");
|
|
}
|
|
|
|
void UpdateTrackerUI()
|
|
{
|
|
if (txtTrackerMisiUI != null)
|
|
{
|
|
if (jumlahTugasSelesai < 2)
|
|
{
|
|
txtTrackerMisiUI.text = "Tugas: " + jumlahTugasSelesai + " / 2";
|
|
txtTrackerMisiUI.color = Color.yellow;
|
|
}
|
|
else
|
|
{
|
|
txtTrackerMisiUI.text = "Semua Tugas Selesai!";
|
|
txtTrackerMisiUI.color = Color.green;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void JalankanDialogNPC(DialogData data)
|
|
{
|
|
playerScript.canMove = false;
|
|
panelDialogUI.SetActive(true);
|
|
txtNamaUI.text = data.namaKarakter;
|
|
|
|
CetakTeksDialog(data.kalimatIntro);
|
|
|
|
foreach (var btn in tombolPilihanUI) btn.gameObject.SetActive(false);
|
|
|
|
for (int i = 0; i < data.pilihanJawaban.Length; i++)
|
|
{
|
|
if (i >= tombolPilihanUI.Length) break;
|
|
|
|
tombolPilihanUI[i].gameObject.SetActive(true);
|
|
txtTombolUI[i].text = data.pilihanJawaban[i].teksTombol;
|
|
|
|
int index = i;
|
|
tombolPilihanUI[i].onClick.RemoveAllListeners();
|
|
tombolPilihanUI[i].onClick.AddListener(() => MemilihJawabanDialog(data.pilihanJawaban[index]));
|
|
}
|
|
}
|
|
|
|
void MemilihJawabanDialog(OpsiPilihan opsi)
|
|
{
|
|
totalSkorKesopanan += opsi.poinKesopanan;
|
|
bool jawabanSopan = opsi.poinKesopanan > 0;
|
|
|
|
int tugasTerlewat = 0;
|
|
if (!sudahMisi1)
|
|
{
|
|
poinGameMisi -= 20;
|
|
tugasTerlewat++;
|
|
}
|
|
if (!sudahMisi2)
|
|
{
|
|
poinGameMisi -= 20;
|
|
tugasTerlewat++;
|
|
}
|
|
|
|
UpdateSkorUI();
|
|
|
|
txtNamaUI.text = "EVALUASI SIKAP & TUGAS";
|
|
string teksEvaluasi = opsi.feedbackEnding + "\n\n";
|
|
|
|
if (jawabanSopan)
|
|
teksEvaluasi += "<color=green><b>[SIKAP SOPAN]</b> Pintar! Kamu berinteraksi dan menjawab dengan santun.</color>\n\n";
|
|
else
|
|
teksEvaluasi += "<color=orange><b>[KURANG SOPAN]</b> Wah, caramu barusan kurang sopan. Poin kesopananmu berkurang.</color>\n\n";
|
|
|
|
if (tugasTerlewat == 0)
|
|
teksEvaluasi += "<color=green><b>[TUGAS SELESAI]</b> Hebat! Semua misi di area ini berhasil diselesaikan.</color>";
|
|
else if (tugasTerlewat == 1)
|
|
teksEvaluasi += "<color=yellow><b>[TUGAS TERLEWAT]</b> Kamu melupakan salah satu misi di area ini! Poin Game berkurang.</color>";
|
|
else
|
|
teksEvaluasi += "<color=red><b>[TUGAS TERLEWAT]</b> Kamu tidak menyelesaikan misimu sama sekali! Poin Game banyak berkurang.</color>";
|
|
|
|
CetakTeksDialog(teksEvaluasi);
|
|
|
|
foreach (var btn in tombolPilihanUI) btn.gameObject.SetActive(false);
|
|
tombolPilihanUI[0].gameObject.SetActive(true);
|
|
txtTombolUI[0].text = "Lanjut Level Berikutnya";
|
|
tombolPilihanUI[0].onClick.RemoveAllListeners();
|
|
tombolPilihanUI[0].onClick.AddListener(PindahKeSceneBerikutnya);
|
|
}
|
|
|
|
void PindahKeSceneBerikutnya()
|
|
{
|
|
panelDialogUI.SetActive(false);
|
|
|
|
// --- TAMBAHAN BARU: SIMPAN SKOR AKHIR UNTUK RAPORT ---
|
|
PlayerPrefs.SetInt("SkorFinalPoin", poinGameMisi);
|
|
PlayerPrefs.SetInt("SkorFinalSopan", totalSkorKesopanan);
|
|
// -----------------------------------------------------
|
|
|
|
// --- SISTEM UNLOCK LEVEL ---
|
|
int levelTerbukaSaatIni = PlayerPrefs.GetInt("ProgresRPG", 1);
|
|
if (urutanLevelIni >= levelTerbukaSaatIni)
|
|
{
|
|
PlayerPrefs.SetInt("ProgresRPG", urutanLevelIni + 1);
|
|
}
|
|
// ----------------------------
|
|
|
|
UnityEngine.SceneManagement.SceneManager.LoadScene(namaSceneSelanjutnya);
|
|
}
|
|
|
|
void UpdateSkorUI()
|
|
{
|
|
if (txtSkorUI != null)
|
|
txtSkorUI.text = "Poin Game: " + poinGameMisi + " | Sopan: " + totalSkorKesopanan;
|
|
}
|
|
|
|
public void TutupPanelDialog()
|
|
{
|
|
panelDialogUI.SetActive(false);
|
|
playerScript.canMove = true;
|
|
}
|
|
} |