Credits Menu Added
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
public class CreditsInputHandler : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private List<string> buttonNames = new List<string> { "Back" };
|
||||
[SerializeField] private List<string> sceneNames = new List<string> { "MainMenu" };
|
||||
private UIDocument uiDocument;
|
||||
private List<Button> buttons;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
uiDocument ??= GetComponent<UIDocument>();
|
||||
if (uiDocument == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var root = uiDocument.rootVisualElement;
|
||||
if (root == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
buttons = new List<Button> { new Button() };
|
||||
for (int i = 0; i < buttons.Count; i++)
|
||||
{
|
||||
int buttonIndex = i;
|
||||
|
||||
buttons[i] = root.Q<Button>(buttonNames[i]);
|
||||
|
||||
if (buttons[i] == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
buttons[i].clicked += () => HandleStartClicked(sceneNames[buttonIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
for (int i = 0; i < buttons.Count; i++)
|
||||
{
|
||||
if (buttons[i] == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
buttons[i].clicked -= () => HandleStartClicked(buttonNames[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleStartClicked(string sceneName)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(sceneName))
|
||||
{
|
||||
SceneManager.LoadScene(sceneName);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user