122 lines
3.6 KiB
C#
122 lines
3.6 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine.SceneManagement; // WAJIB ADA untuk pindah scene
|
|
|
|
public class MateriManager : MonoBehaviour
|
|
{
|
|
[Header("UI Panels")]
|
|
public GameObject panelKategori;
|
|
public GameObject panelDetail;
|
|
|
|
[Header("Detail References")]
|
|
public Image detailImage;
|
|
public Image detailTitle;
|
|
public TextMeshProUGUI detailDesc;
|
|
public CanvasGroup detailContentGroup;
|
|
|
|
private List<MateriItem> materiAktif;
|
|
private int currentIndex = 0;
|
|
|
|
void Start()
|
|
{
|
|
StartCoroutine(AnimasiMasukKategori());
|
|
}
|
|
|
|
// --- FUNGSI PINDAH SCENE ---
|
|
// Panggil fungsi ini untuk tombol Back di pojok kiri atas
|
|
public void KeMenuBelajar()
|
|
{
|
|
SceneManager.LoadScene("Menu Belajar"); // Pastikan namanya sama persis dengan di Build Settings
|
|
}
|
|
|
|
// --- LOGIKA MATERI ---
|
|
public void BukaKategori(DataKategori data)
|
|
{
|
|
if (data == null || data.daftarMateri.Count == 0) return;
|
|
materiAktif = data.daftarMateri;
|
|
currentIndex = 0;
|
|
if (detailTitle != null) detailTitle.sprite = data.gambarJudulKategori;
|
|
UpdateTampilanMateri();
|
|
panelKategori.SetActive(false);
|
|
panelDetail.SetActive(true);
|
|
StartCoroutine(AnimasiPopUpPanel(panelDetail.transform));
|
|
}
|
|
|
|
public void UpdateTampilanMateri()
|
|
{
|
|
if (materiAktif == null || materiAktif.Count == 0) return;
|
|
MateriItem item = materiAktif[currentIndex];
|
|
detailImage.sprite = item.gambarIlustrasi;
|
|
detailDesc.text = item.penjelasan;
|
|
StopCoroutine("FadeInContent");
|
|
StartCoroutine(FadeInContent());
|
|
}
|
|
|
|
public void SlideNext()
|
|
{
|
|
if (currentIndex >= materiAktif.Count - 1) Kembali();
|
|
else { currentIndex++; UpdateTampilanMateri(); }
|
|
}
|
|
|
|
public void SlidePrevious()
|
|
{
|
|
if (currentIndex <= 0) Kembali();
|
|
else { currentIndex--; UpdateTampilanMateri(); }
|
|
}
|
|
|
|
public void Kembali()
|
|
{
|
|
panelDetail.SetActive(false);
|
|
panelKategori.SetActive(true);
|
|
StartCoroutine(AnimasiMasukKategori());
|
|
}
|
|
|
|
// --- ANIMASI ---
|
|
IEnumerator AnimasiMasukKategori()
|
|
{
|
|
foreach (Transform child in panelKategori.transform) child.localScale = Vector3.zero;
|
|
foreach (Transform child in panelKategori.transform)
|
|
{
|
|
float t = 0;
|
|
while (t < 1)
|
|
{
|
|
t += Time.deltaTime * 5f;
|
|
child.localScale = Vector3.one * Mathf.Lerp(0, 1.1f, t);
|
|
yield return null;
|
|
}
|
|
child.localScale = Vector3.one;
|
|
yield return new WaitForSeconds(0.05f);
|
|
}
|
|
}
|
|
|
|
IEnumerator AnimasiPopUpPanel(Transform panel)
|
|
{
|
|
panel.localScale = Vector3.one * 0.7f;
|
|
float t = 0;
|
|
while (t < 1)
|
|
{
|
|
t += Time.deltaTime * 6f;
|
|
panel.localScale = Vector3.one * Mathf.SmoothStep(0.7f, 1f, t);
|
|
yield return null;
|
|
}
|
|
panel.localScale = Vector3.one;
|
|
}
|
|
|
|
IEnumerator FadeInContent()
|
|
{
|
|
if (detailContentGroup == null) yield break;
|
|
detailContentGroup.alpha = 0;
|
|
float durasi = 0.4f;
|
|
float waktu = 0;
|
|
while (waktu < durasi)
|
|
{
|
|
waktu += Time.deltaTime;
|
|
detailContentGroup.alpha = waktu / durasi;
|
|
yield return null;
|
|
}
|
|
detailContentGroup.alpha = 1;
|
|
}
|
|
} |