Merge branch 'LosersCreditsSFX' into TrickSounds
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df3455d232d364f4b809e3308d7b42b2
|
||||
@@ -5,8 +5,8 @@ using UnityEngine.UIElements;
|
||||
|
||||
public class MainMenuController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private List<string> buttonNames = new List<string> { "Start", "Experiment", "Level2" };
|
||||
[SerializeField] private List<string> sceneNames = new List<string> { "Level1", "Experiment", "Level2" };
|
||||
[SerializeField] private List<string> buttonNames = new List<string> { "Start", "Experiment", "Level2", "Credits" };
|
||||
[SerializeField] private List<string> sceneNames = new List<string> { "Level1", "Experiment", "Level2", "Credits" };
|
||||
private UIDocument uiDocument;
|
||||
private List<Button> buttons;
|
||||
|
||||
@@ -24,7 +24,7 @@ public class MainMenuController : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
|
||||
buttons = new List<Button> { new Button(), new Button(), new Button() };
|
||||
buttons = new List<Button> { new Button(), new Button(), new Button(), new Button() };
|
||||
for (int i = 0; i < buttons.Count; i++)
|
||||
{
|
||||
int buttonIndex = i;
|
||||
|
||||
Reference in New Issue
Block a user