140 lines
3.2 KiB
C#
140 lines
3.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Threading.Tasks;
|
|
|
|
public class SelectLevel : Menu<SelectLevel>
|
|
{
|
|
[SerializeField] private GameObject[] containerLevelButton;
|
|
[SerializeField] private int indexContainer;
|
|
|
|
[SerializeField] private Button[] buttons;
|
|
[SerializeField] private int indexUnlock;
|
|
|
|
[SerializeField] private Sprite completeSprite;
|
|
[SerializeField] private Sprite lockedSprite;
|
|
[SerializeField] private Sprite currentSprite;
|
|
|
|
[SerializeField] private GameObject infolockPostTest;
|
|
|
|
private SaveData saveData;
|
|
|
|
private async void OnEnable()
|
|
{
|
|
await LoadAndRefresh();
|
|
}
|
|
|
|
private async Task LoadAndRefresh()
|
|
{
|
|
saveData = await Cloudsave.LoadData<SaveData>( "DataPlayer");
|
|
|
|
RefreshButtonsUnlockProgress();
|
|
}
|
|
|
|
public void OpenPretest()
|
|
{
|
|
PreTestMenu.Open();
|
|
}
|
|
|
|
public void OpenPostTest()
|
|
{
|
|
if (indexUnlock == 10)
|
|
{
|
|
PostTestMenu.Open();
|
|
}
|
|
else
|
|
{
|
|
infolockPostTest.SetActive(true);
|
|
Debug.Log("Selesaikan Dulu");
|
|
}
|
|
}
|
|
|
|
void RefreshButtonsUnlockProgress()
|
|
{
|
|
indexUnlock = saveData.unlockLevel;
|
|
if (indexUnlock == null)
|
|
{
|
|
indexUnlock = 1;
|
|
}
|
|
|
|
for (int i = 0; i < buttons.Length; i++)
|
|
{
|
|
Image imgSprite = buttons[i].GetComponent<Image>();
|
|
|
|
if (i < indexUnlock - 1)
|
|
{
|
|
imgSprite.sprite = completeSprite;
|
|
buttons[i].interactable = true;
|
|
}
|
|
else if (i == indexUnlock - 1)
|
|
{
|
|
imgSprite.sprite = currentSprite;
|
|
buttons[i].interactable = true;
|
|
}
|
|
else
|
|
{
|
|
imgSprite.sprite = lockedSprite;
|
|
buttons[i].interactable = false;
|
|
}
|
|
}
|
|
|
|
CheckPreTest();
|
|
}
|
|
|
|
private void CheckPreTest()
|
|
{
|
|
if (!saveData.isPreTestComplete)
|
|
{
|
|
Image imgSprite = buttons[0].GetComponent<Image>();
|
|
imgSprite.sprite = lockedSprite;
|
|
buttons[0].interactable = false;
|
|
|
|
}
|
|
else
|
|
{
|
|
Image imgSprite = buttons[0].GetComponent<Image>();
|
|
imgSprite.sprite = currentSprite;
|
|
buttons[0].interactable = true;
|
|
}
|
|
}
|
|
|
|
void RefreshContainer()
|
|
{
|
|
for (int i = 0; i < containerLevelButton.Length; i++)
|
|
{
|
|
containerLevelButton[i].SetActive(false);
|
|
}
|
|
containerLevelButton[indexContainer].SetActive(true);
|
|
}
|
|
|
|
public void NextLevelButton()
|
|
{
|
|
indexContainer++;
|
|
if (indexContainer >= containerLevelButton.Length)
|
|
{
|
|
indexContainer = 0;
|
|
}
|
|
|
|
RefreshContainer();
|
|
}
|
|
|
|
public void PreviousLevelButton()
|
|
{
|
|
indexContainer--;
|
|
if (indexContainer < 0)
|
|
{
|
|
indexContainer = containerLevelButton.Length - 1;
|
|
}
|
|
|
|
RefreshContainer();
|
|
}
|
|
|
|
public void SelectLevelButton(string nameScene)
|
|
{
|
|
SceneController.Instance.LoadScene(nameScene);
|
|
GameMenu.Open();
|
|
}
|
|
}
|