107 lines
2.7 KiB
C#
107 lines
2.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using TMPro;
|
|
|
|
public class LayerOrderController : MonoBehaviour
|
|
{
|
|
public static LayerOrderController Instance;
|
|
public TextMeshProUGUI taskDescriptionText;
|
|
|
|
[Header("Êàðòêè")]
|
|
public DraggableCard[] dragCards;
|
|
|
|
[Header("Ñëîòè")]
|
|
public DropZone[] dropZones;
|
|
|
|
[Header("Êíîïêà ïåðåâ³ðêè")]
|
|
public UnityEngine.UI.Button checkButton;
|
|
|
|
private string[] correctOrder = new string[]
|
|
{
|
|
"Òðîïîñôåðà",
|
|
"Ñòðàòîñôåðà",
|
|
"Ìåçîñôåðà",
|
|
"Òåðìîñôåðà",
|
|
"Åêçîñôåðà"
|
|
};
|
|
|
|
void Awake()
|
|
{
|
|
Instance = this;
|
|
}
|
|
|
|
public void SetupForPlanet(PlanetDatabase.PlanetInfo planetInfo)
|
|
{
|
|
if (taskDescriptionText != null)
|
|
taskDescriptionText.text = "Ðîçòàøóé øàðè àòìîñôåðè ó ïðàâèëüíîìó ïîðÿäêó â³ä ïîâåðõí³ ïëàíåòè äî êîñìîñó. Øàð 1 º íàéáëèæ÷èì äî ïîâåðõí³.";
|
|
|
|
if (planetInfo.layers == null) return;
|
|
|
|
string[] names = new string[planetInfo.layers.Length];
|
|
for (int i = 0; i < planetInfo.layers.Length; i++)
|
|
names[i] = planetInfo.layers[i].name;
|
|
|
|
ShuffleArray(names);
|
|
|
|
for (int i = 0; i < dragCards.Length && i < names.Length; i++)
|
|
{
|
|
dragCards[i].layerName = names[i];
|
|
var text = dragCards[i].GetComponentInChildren<TextMeshProUGUI>();
|
|
if (text != null) text.text = names[i];
|
|
dragCards[i].gameObject.SetActive(true);
|
|
}
|
|
|
|
foreach (var zone in dropZones)
|
|
{
|
|
zone.currentCard = null;
|
|
zone.ResetColor();
|
|
}
|
|
|
|
correctOrder = new string[planetInfo.layers.Length];
|
|
for (int i = 0; i < planetInfo.layers.Length; i++)
|
|
correctOrder[i] = planetInfo.layers[i].name;
|
|
}
|
|
|
|
void ShuffleArray(string[] arr)
|
|
{
|
|
for (int i = arr.Length - 1; i > 0; i--)
|
|
{
|
|
int j = Random.Range(0, i + 1);
|
|
string tmp = arr[i];
|
|
arr[i] = arr[j];
|
|
arr[j] = tmp;
|
|
}
|
|
}
|
|
|
|
public void CheckOrder()
|
|
{
|
|
bool allCorrect = true;
|
|
|
|
for (int i = 0; i < dropZones.Length; i++)
|
|
{
|
|
if (dropZones[i].currentCard == null)
|
|
{
|
|
allCorrect = false;
|
|
dropZones[i].SetWrong();
|
|
continue;
|
|
}
|
|
|
|
string expected = correctOrder[i];
|
|
string actual = dropZones[i].currentCard.layerName;
|
|
|
|
if (actual == expected)
|
|
dropZones[i].SetCorrect();
|
|
else
|
|
{
|
|
dropZones[i].SetWrong();
|
|
allCorrect = false;
|
|
}
|
|
}
|
|
|
|
if (allCorrect)
|
|
GameManager.Instance.OnLayerOrderComplete();
|
|
}
|
|
|
|
}
|