2026-02-04 05:31:41 +00:00
|
|
|
using System.IO;
|
|
|
|
|
using UnityEngine;
|
2026-02-07 14:41:29 +00:00
|
|
|
using UnityEngine.InputSystem;
|
2026-02-04 05:31:41 +00:00
|
|
|
using UnityEngine.SceneManagement;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
public class GenerateLevelButtons : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
[SerializeField] private GameObject levelButtonPrefab;
|
|
|
|
|
[SerializeField] private Transform buttonsGrid;
|
|
|
|
|
|
2026-02-07 14:41:29 +00:00
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
|
{
|
|
|
|
|
if (Keyboard.current != null && Keyboard.current.escapeKey.wasPressedThisFrame)
|
|
|
|
|
{
|
|
|
|
|
SceneManager.LoadScene("Title");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-04 05:31:41 +00:00
|
|
|
private void Start()
|
|
|
|
|
{
|
|
|
|
|
int levelCount = 0;
|
|
|
|
|
int totalScenes = SceneManager.sceneCountInBuildSettings;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < totalScenes; i++)
|
|
|
|
|
{
|
|
|
|
|
string path = SceneUtility.GetScenePathByBuildIndex(i);
|
|
|
|
|
string sceneName = Path.GetFileNameWithoutExtension(path);
|
|
|
|
|
if (sceneName.StartsWith("Level_"))
|
|
|
|
|
{
|
|
|
|
|
levelCount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i <= levelCount; i++)
|
|
|
|
|
{
|
|
|
|
|
GameObject levelButton = Instantiate(levelButtonPrefab, buttonsGrid);
|
|
|
|
|
SelectLevelButton selcButton = levelButton.GetComponent<SelectLevelButton>();
|
|
|
|
|
|
|
|
|
|
selcButton.SetUp(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|