86 lines
2.5 KiB
C#
86 lines
2.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class CombinatorPanel : MonoBehaviour
|
|
{
|
|
[Header("Настройки генерации", order = 0)]
|
|
[SerializeField] float leftOffset = 10;
|
|
[SerializeField] float upOffset = -10;
|
|
[SerializeField] float verticalGap = 50;
|
|
[SerializeField] GameObject timerPrefab;
|
|
[SerializeField] GameObject labelPrefab;
|
|
[SerializeField] GameObject buttonsBlockPrefab;
|
|
|
|
List<GameObject> generatedObjects;
|
|
|
|
bool ready = false;
|
|
|
|
|
|
[Header("Комбинации", order = 0)]
|
|
[SerializeField] List<Combination> Combinations;
|
|
|
|
void Update() => ProcessCombinations();
|
|
//private void OnEnable() => Generate();
|
|
//private void OnDisable() => Clear();
|
|
public void Clear()
|
|
{
|
|
if (generatedObjects == null) return;
|
|
|
|
foreach (GameObject go in generatedObjects)
|
|
{
|
|
Destroy(go);
|
|
}
|
|
ready = false;
|
|
}
|
|
|
|
void ProcessCombinations()
|
|
{
|
|
if (!ready) return;
|
|
|
|
foreach(Combination comb in Combinations)
|
|
{
|
|
if (comb.Process()) break;
|
|
}
|
|
}
|
|
|
|
public void Generate()
|
|
{
|
|
generatedObjects = new();
|
|
|
|
int i = 0;
|
|
foreach(Combination combo in Combinations)
|
|
{
|
|
float commonY = upOffset - i * verticalGap;
|
|
//таймер
|
|
GameObject timer = Instantiate(timerPrefab, transform);
|
|
RectTransform rect = timer.GetComponent<RectTransform>();
|
|
rect.anchoredPosition = new Vector2(leftOffset, commonY);
|
|
timer.GetComponent<Image>().fillAmount = 0;
|
|
combo.SetImageLink(timer.GetComponent<Image>());
|
|
|
|
|
|
|
|
GameObject label = Instantiate(labelPrefab, transform);
|
|
rect = label.GetComponent<RectTransform>();
|
|
rect.anchoredPosition = new Vector2(leftOffset+30, commonY);
|
|
label.GetComponent<TextMeshProUGUI>().text = combo.description;
|
|
|
|
GameObject buttonsBlock = Instantiate(buttonsBlockPrefab, transform);
|
|
rect = buttonsBlock.GetComponent<RectTransform>();
|
|
rect.anchoredPosition = new Vector2(leftOffset + 30 + 400, commonY);
|
|
buttonsBlock.GetComponent<ButtonsBlock>().SetupBlock(combo.buttons);
|
|
|
|
generatedObjects.Add(timer);
|
|
generatedObjects.Add(label);
|
|
generatedObjects.Add(buttonsBlock);
|
|
|
|
i++;
|
|
}
|
|
ready = true;
|
|
}
|
|
|
|
}
|