Jeremy Smitherman 1523485fe2 feat/state (#2)
Reviewed-on: #2
Co-authored-by: Jeremy Smitherman <Jeremysmitherman@gmail.com>
Co-committed-by: Jeremy Smitherman <Jeremysmitherman@gmail.com>
2026-04-24 18:57:06 +00:00

34 lines
954 B
C#

using System;
using UnityEngine;
using UnityEngine.UIElements;
namespace UI
{
[RequireComponent(typeof(UIDocument))]
public class MainMenu : MonoBehaviour
{
public event Action OnStartGame;
public event Action OnExitGame;
private Button _startGameButton;
private Button _exitGameButton;
private void Awake()
{
_startGameButton = GetComponent<UIDocument>().rootVisualElement.Q<Button>("StartGameButton");
_exitGameButton = GetComponent<UIDocument>().rootVisualElement.Q<Button>("QuitGameButton");
_startGameButton.clicked += HandleStartGame;
_exitGameButton.clicked += () => OnExitGame?.Invoke();
}
private void OnDestroy()
{
_startGameButton.clicked -= HandleStartGame;
}
private void HandleStartGame()
{
OnStartGame?.Invoke();
}
}
}